phpunit mockry未找到匹配的处理程序

phpunit mockry未找到匹配的处理程序,phpunit,mockery,Phpunit,Mockery,当我尝试通过多次测试执行phpUnit时,有人输出失败: No matching handler found [...] Either the method was unexpected or its arguments matched no expected argument list for this method. 但是,如果我单独执行测试,就可以无误地通过。如何在每次测试中强制使用不同的模拟对象 编辑: 如果我单独运行phpunit,工作正常并且所有测试都通过了,但是如果我使用包含两个

当我尝试通过多次测试执行phpUnit时,有人输出失败:

No matching handler found [...] Either the method was unexpected or its arguments matched no expected argument list for this method.
但是,如果我单独执行测试,就可以无误地通过。如何在每次测试中强制使用不同的模拟对象

编辑:

如果我单独运行phpunit,工作正常并且所有测试都通过了,但是如果我使用包含两个类的目录。。。第一个方法已通过,但第二个方法抛出此异常

我在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);

}
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);

}
这是ReadCountryTest类中的一个:

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);

}
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);

}

谢谢

你能发布一些代码来复制这个问题吗?你已经看到了吗?我认为杰克不是一个比较问题