phpunit mockery找不到匹配的处理程序

时间:2015-08-21 15:49:41

标签: phpunit mockery

当我尝试使用多个测试执行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);

}

由于

0 个答案:

没有答案