/** * @param Randomiser $randomiser Allows randomiser to be set just for this method - for testing * @return Attack */ public function createAttack(Randomiser $randomiser = null) { $randomiser = isset($randomiser) ? $randomiser : $this->getRandomiser(); $attack = new Attack($this->getStrength()); // 2% chance of stunning if (!$attack->hasMissed()) { $attack->setStunning($randomiser->generateBoolean(0.02)); } return $attack; }
/** * @test * @covers Brute::createAttack */ public function attackCanBeCreatedWithStunningBlow() { $oneRandomiser = new Randomiser(1); $attack = $this->weakCombatant->createAttack($oneRandomiser); $expectedAttack = new Attack($this->weakCombatant->getStrength()); $expectedAttack->setStunning(true); $this->assertInstanceOf('Attack', $attack); $this->assertTrue($attack->isStunning()); $this->assertEquals($expectedAttack, $attack); }