prophecy

How to mock the same method in Prophecy so it returns different response in each of its calls

你。 提交于 2021-02-07 20:35:44
问题 In pure PHPUnit mocking I can do something like this: $mock->expects($this->at(0)) ->method('isReady') ->will($this->returnValue(false)); $mock->expects($this->at(1)) ->method('isReady') ->will($this->returnValue(true)); I was not able to do the same thing using Prophecy. Is it possible? 回答1: You can use: $mock->isReady()->willReturn(false, true); Apparently it's not documented (see https://gist.github.com/gquemener/292e7c5a4bbb72fd48a8). 回答2: There is another documented way to do that. If

PHP unit failure testing

醉酒当歌 提交于 2019-12-08 05:57:57
问题 I have to test this class for failure condition <?php namespace Gpx\Handlers; use Gpx\EntityInfrastructure\Model\Events\PlatformSessionInitiated; use Gpx\EntityInfrastructure\Model\Payload; use Gpx\Hfx\Framework\MessageTransportApplication\Handler\SynchronousHandlerInterface; use Gpx\Hfx\Framework\MessageTransportApplication\Handler\MessageHandlingContextInterface; use Gpx\HfxEventSourcing\HfxAggregateRoot; use Gpx\HfxEventSourcing\HfxEventMetadata; use Gpx\HfxEventSourcing