与PHPUnits、returnValueMap等效的模拟
我刚刚开始使用PHPUnits自己的模拟特性来代替PHPUnits mockry是否有PHPUnits的等价物,它可以基于提供给方法调用的特定参数值返回特定值 PHPUnit就是这样做的与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')
<?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'));