Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
确定对象是否为PHPUnit mock_Php_Unit Testing_Phpunit - Fatal编程技术网

确定对象是否为PHPUnit mock

确定对象是否为PHPUnit mock,php,unit-testing,phpunit,Php,Unit Testing,Phpunit,我想断言,传递到PHPUnit测试方法中的值/对象是由getMockBuilder初始化的模拟。例如: class Example_Test extends PHPUnit_Framework_TestCase { ... public function testMethod(Some_Class $object_mock) { // since methods like "expects" will be used below, //

我想断言,传递到PHPUnit测试方法中的值/对象是由getMockBuilder初始化的模拟。例如:

class Example_Test extends PHPUnit_Framework_TestCase
{
    ...

    public function testMethod(Some_Class $object_mock)
    {

        // since methods like "expects" will be used below,
        // this needs to be a mock
        assert('$this->isMock($object_mock)');

        ...

        $object_mock->expects($this->atLeastOnce())
                    ->method('reallyCoolThingThatMustHappen')
                    ->with(
                        $this->equalTo('absolutely_necessary_argument')
                    );

        ...

    }
}

有人知道可以用来断言
$object\u mock
是PHPUnit mock的方法吗?(我知道isMock不存在,但我把它作为我试图做的一个例子放在那里)。

$o PHPUnit\u Framework\u MockObject\u MockObject
计算为
true
,而
$o
是使用
getMock()
(已弃用),
getMockWithoutInvokingTheOriginalConstructor()创建的测试双精度
(已弃用)、
createMock()
(最佳实践)、
createConfiguredMock()
createPartialMock()
getMockBuilder()
等方法。调用
isMock()
方法时,可以将模拟设置为返回true:
$object\u mock->method('isMock')->将返回(true)@MarkBaker好主意。但如果不是模拟的话,我还需要它返回false。