Last active
December 25, 2015 11:49
-
-
Save edvakf/6971606 to your computer and use it in GitHub Desktop.
don't use phpunit's assertEquals to compare closures.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ClosureCompraisonTest extends PHPUnit_Framework_TestCase | |
{ | |
// passes. WTF??? | |
public function test_assertEquals() | |
{ | |
$f1 = function () { return 1; }; | |
$f2 = function () { return 2; }; | |
$this->assertEquals($f1, $f2); | |
} | |
// fails, don't kid me | |
public function test_assertNotEquals() | |
{ | |
$f1 = function () { return 1; }; | |
$f2 = function () { return 2; }; | |
$this->assertNotEquals($f1, $f2); | |
} | |
// fails, of course | |
public function test_assertSame() | |
{ | |
$f1 = function () { return 1; }; | |
$f2 = function () { return 2; }; | |
$this->assertSame($f1, $f2); | |
} | |
// passes | |
public function test_assertNotSame() | |
{ | |
$f1 = function () { return 1; }; | |
$f2 = function () { return 2; }; | |
$this->assertNotSame($f1, $f2); | |
} | |
// passes | |
public function test_doubleEqual() | |
{ | |
$f1 = function () { return 1; }; | |
$f2 = function () { return 2; }; | |
$this->assertFalse($f1 == $f2); | |
} | |
// passes | |
public function test_tripleEqual() | |
{ | |
$f1 = function () { return 1; }; | |
$f2 = function () { return 2; }; | |
$this->assertFalse($f1 === $f2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ./vendor/phpunit/phpunit/phpunit.php ClosureComparisonTest.php | |
PHPUnit 3.7.27 by Sebastian Bergmann. | |
Configuration read from /Users/atsushi/prog/phpmethodreplacer/phpunit.xml.dist | |
.FF... | |
Time: 63 ms, Memory: 2.75Mb | |
There were 2 failures: | |
1) ClosureCompraisonTest::test_assertNotEquals | |
Failed asserting that Closure Object ( | |
0 => Closure Object (*RECURSION*) | |
) is not equal to Closure Object ( | |
0 => Closure Object (*RECURSION*) | |
). | |
/Users/atsushi/prog/phpmethodreplacer/ClosureComparisonTest.php:18 | |
2) ClosureCompraisonTest::test_assertSame | |
Failed asserting that two variables reference the same object. | |
/Users/atsushi/prog/phpmethodreplacer/ClosureComparisonTest.php:26 | |
FAILURES! | |
Tests: 6, Assertions: 6, Failures: 2. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment