shmock
shmock copied to clipboard
Setting dont_preserve_original_methods interferes with mocking __call methods
e.g.
class MagicMethodTest
{
/**
* @param string $methodName
* @param array $argument
*
* @return string
*/
public function __call($methodName, array $argument)
{
return $methodName;
}
}
class MagicMethodUsage
{
/**
* @param \Box\PHPUnitTestGenerator\tests\_fixture\_input\MagicMethodTest $magicTest
*
* @return string
*/
public function callMagicMethod(
MagicMethodTest $magicTest
)
{
$rc = $magicTest->foo();
return $rc;
}
}
<?php
class MagicMethodUsageGenTest extends \PHPUnit_Framework_TestCase
{
use \Shmock\Shmockers;
public function testCallMagicMethod()
{
// Setup mocks for parameters to the method under test.
$mockMagicMethodTest0 = $this->shmock(
'MagicMethodTest',
function (
$shmock
) {
// $shmock->dont_preserve_original_methods();
/** @var $mock \Shmock\Spec */
$mock = $shmock->__call('foo', array (
));
$mock->return_value('bar');
}
);
// Execute the method under test.
$objectUnderTest = new MagicMethodUsage();
$executionResult = $objectUnderTest->callMagicMethod($mockMagicMethodTest0);
// Validate the execution result.
$expected = 'bar';
$this->assertSame(
$expected,
$executionResult,
'Variable ( executionResult ) doesn\'t have the expected value.'
);
}
}