Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.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
与PHPUnits、returnValueMap等效的模拟_Php_Unit Testing_Mocking_Mockery - Fatal编程技术网

与PHPUnits、returnValueMap等效的模拟

与PHPUnits、returnValueMap等效的模拟,php,unit-testing,mocking,mockery,Php,Unit Testing,Mocking,Mockery,我刚刚开始使用PHPUnits自己的模拟特性来代替PHPUnits mockry是否有PHPUnits的等价物,它可以基于提供给方法调用的特定参数值返回特定值 PHPUnit就是这样做的 <?php $stub = $this->createMock(SomeClass::class); $map = [ ['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h'] ]; $stub->method('doSomething')

我刚刚开始使用PHPUnits自己的模拟特性来代替PHPUnits

mockry是否有PHPUnits的等价物,它可以基于提供给方法调用的特定参数值返回特定值

PHPUnit就是这样做的

<?php

$stub = $this->createMock(SomeClass::class);

$map = [
    ['a', 'b', 'c', 'd'],
    ['e', 'f', 'g', 'h']
];

$stub->method('doSomething')
    ->will($this->returnValueMap($map));

$this->assertEquals('d', $stub->doSomething('a', 'b', 'c'));
$this->assertEquals('h', $stub->doSomething('e', 'f', 'g'));
我的问题对我来说有点“无聊”。这相当于在PHPUnit中使用
returnValueMap()

<?php

$stub = \Mockery::mock(SomeClass::class);

$stub->shouldReceive('doSomething')->with('a', 'b', 'c')->andReturn('d');
$stub->shouldReceive('doSomething')->with('e', 'f', 'g')->andReturn('h');

$this->assertEquals('d', $stub->doSomething('a', 'b', 'c'));
$this->assertEquals('h', $stub->doSomething('e', 'f', 'g'));
我的问题对我来说有点“无聊”。这相当于在PHPUnit中使用
returnValueMap()

<?php

$stub = \Mockery::mock(SomeClass::class);

$stub->shouldReceive('doSomething')->with('a', 'b', 'c')->andReturn('d');
$stub->shouldReceive('doSomething')->with('e', 'f', 'g')->andReturn('h');

$this->assertEquals('d', $stub->doSomething('a', 'b', 'c'));
$this->assertEquals('h', $stub->doSomething('e', 'f', 'g'));