public function testHitDroneByMockCalls() { $game = GameWithoutBees::get(); /** @var Drone | \PHPUnit_Framework_MockObject_MockObject $droneMock */ $droneMock = $this->getMockObject(Drone::class, [$this->game], ['beforeTakeHit' => ['times' => $this->once(), 'return' => true], 'takeHit' => ['times' => $this->once(), 'return' => true]]); $game->getCharacterPool()->addBee($droneMock); $game->start(); $game->hit(); }
public function testHit() { $game = GameWithoutBees::get(); $bee = new Drone($game); $game->getCharacterPool()->addBee($bee); $firstLifespan = $bee->getLifespan(); $this->player->hit($bee); $secondLifespan = $bee->getLifespan(); $this->assertLessThan($firstLifespan, $secondLifespan); }
public function testGetGameLazyLoadFromStorage() { $expectedGame = GameWithoutBees::get(); /** @var Session | \PHPUnit_Framework_MockObject_MockObject $sessionStub */ $sessionStub = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->setMethods(['get', 'set'])->getMock(); $sessionStub->expects($this->exactly(2))->method('get')->with('game')->willReturn(serialize($expectedGame)); $storage = new SessionStorage($sessionStub); $builder = GameWithPlayerAnd10Workers::getBuilder(); $method = new \ReflectionMethod(GameController::class, 'getGame'); $method->setAccessible(true); $actualGame = $method->invokeArgs($this->getMock(GameController::class, [], [], '', false), [$storage, $builder]); $this->assertEquals(serialize($expectedGame), serialize($actualGame)); }
public function setUp() { $this->game = GameWithoutBees::get(); }