xp-framework / unittest

Unittests for the XP Framework
0 stars 0 forks source link

assertEquals() and non-XP objects #13

Closed thekid closed 8 years ago

thekid commented 8 years ago

Discussed this with @mikey179 today, assertEquals() should also handle non-XP objects, using PHP's default object comparison mechanism, which is to compare objects by comparing all their members:

$ xp test -e '$this->assertEquals(new \ReflectionClass(self::class), new \ReflectionClass(self::class))'
[F]

F unittest.TestAssertionFailed(test= xp.unittest.DynamicallyGeneratedTestCase0::run, time= 0.018 seconds) {
  unittest.AssertionFailedError{ expected [ReflectionClass {
    name => "xp\unittest\DynamicallyGeneratedTestCase0"
  }] but was [ReflectionClass {
    name => "xp\unittest\DynamicallyGeneratedTestCase0"
  }] using: 'equals' }
    at unittest.TestCase::assertEquals() [line 3 of xp.unittest.DynamicallyGeneratedTestCase0]
    at xp.unittest.DynamicallyGeneratedTestCase0::run() [line 0 of StackTraceElement.class.php]
    at ReflectionMethod::invokeArgs() [line 90 of Method.class.php]
    at lang.reflect.Method::invoke() [line 316 of TestSuite.class.php]
    at unittest.TestSuite::runInternal() [line 528 of TestSuite.class.php]
    at unittest.TestSuite::run() [line 381 of TestRunner.class.php]
    at xp.unittest.TestRunner::run() [line 391 of TestRunner.class.php]
    at xp.unittest.TestRunner::main() [line 0 of StackTraceElement.class.php]
    at ReflectionMethod::invokeArgs() [line 90 of Method.class.php]
    at lang.reflect.Method::invoke() [line 308 of class-main.php]

 }

×: 1/1 run (0 skipped), 0 succeeded, 1 failed
Memory used: 1354.80 kB (1416.52 kB peak)
Time taken: 0.018 seconds
thekid commented 8 years ago

Thought of implementing this with == first, but may yield unexpected results for native instances containing XP objects when they define equality differently than a member-wise comparison.

thekid commented 8 years ago

Decided to implement this in XP core, and to bump the dependency on it to ^6.9.2

thekid commented 8 years ago

After 6.9.2 is released:

$ xp test -e '$this->assertEquals(new \ReflectionClass(self::class), new \ReflectionClass(self::class))'
[.]

♥: 1/1 run (0 skipped), 1 succeeded, 0 failed
Memory used: 1279.71 kB (1416.52 kB peak)
Time taken: 0.000 seconds
thekid commented 8 years ago

Fixed in 6.8.1-RELEASE