Last active
April 11, 2016 18:59
-
-
Save Ostico/eadfbbaabe4fd8a50e662199ea5f0f1e to your computer and use it in GitHub Desktop.
ObjectComparator does not check for Object Hash but internally knows that objects are different.
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 | |
/** | |
* @author Domenico Lupinetti [email protected] | |
* Date: 11/04/16 | |
* Time: 19.52 | |
* | |
* The try block is executed but the comparison are made on Exporter::toArray() | |
* and if the object has no properties $expected and $actual are equals but refers to two different instances | |
* ( tried with PDO as example ) | |
* | |
* @see https://github.com/sebastianbergmann/comparator/blob/master/src/ObjectComparator.php#L74 | |
* @see https://github.com/sebastianbergmann/exporter/blob/master/src/Exporter.php#L152 | |
* | |
*/ | |
class ObjectTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testObjectEquality(){ | |
$x = new PDO( | |
"mysql:host=mysql;dbname=mydb;charset=UTF8", | |
'user', | |
'user1', | |
array( | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION // Raise exceptions on errors | |
) ); | |
$y = new PDO( | |
"mysql:host=mysql;dbname=mydb;charset=UTF8", | |
'user', | |
'user1', | |
array( | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION // Raise exceptions on errors | |
) ); | |
echo("\n"); | |
var_dump( spl_object_hash( $x ) ); | |
var_dump( spl_object_hash( $y ) ); | |
//this is expected to fail | |
$this->assertEquals( $x, $y ); // <--- PASS but is WRONG | |
//this is expected to fail | |
$this->assertTrue( $x === $y ); // <--- NOT PASS ( RIGHT ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment