You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When verifying the parameters that are passed into a method, the state of an object that is passed into the method must match the state at that moment and not the final state of the object.
Example:
/********************************
********* ValueObject **********
********************************/
class MyObject
{
private $var1;
private $var2;
public function setVar1($var1)
{
$this->var1 = $var1;
}
public setVar2($var2)
{
$this->var2 = $var2;
}
}
/********************************
********** Sub Class **********
********************************/
interface SubClass
{
public function call1($obj);
public function call2($obj);
}
/********************************
************ Class *************
********************************/
class MyClass
{
/** @var MySubClass */
private $subClass;
public function __construct(SubClass $subClass)
{
$this->subClass = $subClass;
}
public function run(MyObject $obj)
{
$obj->setVar1('CHANGED');
$this->subClass->call1($obj);
$obj->setVar2('CHANGED');
$this->subClass->call2($obj);
}
}
/********************************
************ Test **************
********************************/
class MyTest extends \PHPUnit_Framework_TestCase
{
public function test()
{
$mock = \Phake::mock(MySubClass::class);
$test = new MyClass($mock)
$obj = new MyObject();
$obj->setVar1('unchanged');
$obj->setVar2('unchanged');
$test->run($obj);
\Phake::verify($mock)->call1(
(new MyObject())
->setVar1('CHANGED')
->setVar2('unchanged') // <-- This will fail, because the final state
// of the object has changed to 'CHANGED'
);
\Phake::verify($mock)->call2(
(new MyObject())
->setVar1('CHANGED')
->setVar2('CHANGED')
);
}
}
The text was updated successfully, but these errors were encountered:
When verifying the parameters that are passed into a method, the state of an object that is passed into the method must match the state at that moment and not the final state of the object.
Example:
The text was updated successfully, but these errors were encountered: