I am writing unit test for a PSR7 implementation. I want to check if a method of MessageInterface
like withProtocolVersion
, do not mutate the original object.
How to check if the object is mutated after some operation in PHP?
Compare the objects strictly:
class Foo {
public $foo = 'bar';
}
$foo = new Foo();
var_dump($foo === $foo);
$foo2 = clone $foo;
$foo2->foo = 'not bar';
var_dump($foo2 === $foo);
var_dump($foo2 === $foo2);
I'm not sure if you're using phpunit, if yes try assertSame() and assertEquals().