【发布时间】:2015-11-15 15:29:48
【问题描述】:
当我尝试使用多个测试执行 phpUnit 时,有人失败并显示以下输出:
No matching handler found [...] Either the method was unexpected or its arguments matched no expected argument list for this method.
但如果我单独执行测试,则可以通过而不会出错。我如何强制在每个测试中使用不同的 Mockery 对象?
编辑:
如果我单独运行 phpunit,工作正常并且所有测试都通过了,但是如果我使用包含 2 个类的目录...第一个方法通过但第二个方法抛出了这个异常。
我在 AddCountryTest 类中有这个方法:
public function testAddCountry()
{
$name = 'test testAddCountryCommand';
$iso = 'derd';
$telPrefix = '+34 5';
$languageId = 1;
/* @var WtsCqrsRequest $wtsCqrsRequest */
$wtsCqrsRequest = \Mockery::mock('Wts\Country\App\Cqrs\Country\Request\AddCountryRequest')->makePartial();
/** @noinspection PhpUndefinedMethodInspection */
$wtsCqrsRequest
->shouldReceive('getIso')->andReturn($iso)
->shouldReceive('getTelPrefix')->andReturn($telPrefix)
->shouldReceive('getName')->andReturn($name)
->shouldReceive('getDefaultLanguageId')->andReturn($languageId)
;
$commandHandler = $this->getCommandHandler($wtsCqrsRequest);
/* @var Country $country */
$country = $commandHandler->handle($wtsCqrsRequest);
$this->assertEquals($country->getIso(), $iso);
}
这个在 ReadCountryTest 类中:
public function testReadCountry()
{
$name = 'test testAddCountryCommand';
$iso = 'zzz';
$telPrefix = '+34 5';
$languageId = 1;
$this->createCountry($name,$iso,$telPrefix,$languageId);
$iso = 'aaa';
$this->createCountry($name,$iso,$telPrefix,$languageId);
$iso = 'vvv';
$this->createCountry($name,$iso,$telPrefix,$languageId);
//Read
/* @var WtsCqrsRequest $wtsCqrsRequest */
$wtsCqrsRequest = \Mockery::mock('Wts\Country\App\Cqrs\Country\Request\ReadCountriesRequest')->makePartial();
$commandHandler = $this->getCommandHandler($wtsCqrsRequest);
/** @var WtsCqrsResponse $wtsCqrsResponse */
$wtsCqrsResponse = $commandHandler->handle($wtsCqrsRequest);
/* @var CountryDto[] countries */
$countries = $wtsCqrsResponse->getData();
/** @var CountryDto $countryRead */
$this->assertEquals(count($countries), 3);
}
谢谢
【问题讨论】:
-
你能发布一些代码来复制这个问题吗?
-
你已经看到这个github.com/padraic/mockery/issues/328了吗?
-
@jack 我认为不是比较问题