/** * Check if figure is correct * * @param string $figure * @throws CardException */ public static function checkFigureIsCorrect(string $figure) { if (false === in_array($figure, FigureInterface::FIGURES)) { throw CardException::incorrectFigure($figure); } }
public function testHasCardWithFigure() { $cardCollection = new CardCollection(); foreach (FigureInterface::FIGURES as $figure) { $this->assertFalse($cardCollection->hasCardWithFigure($figure)); } $addedCard = TestDataProvider::getCard2(); $cardCollection->append($addedCard); foreach (FigureInterface::FIGURES as $figure) { if ($addedCard->getFigure() === $figure) { $this->assertTrue($cardCollection->hasCardWithFigure($figure)); } else { $this->assertFalse($cardCollection->hasCardWithFigure($figure)); } } $expectedException = CardException::incorrectFigure('notExistedFigure'); $this->expectException(get_class($expectedException)); $this->expectExceptionMessage($expectedException->getMessage()); $cardCollection->hasCardWithFigure('notExistedFigure'); }
public function testCheckFigureIsCorrect() { foreach (FigureInterface::FIGURES as $figure) { Card::checkFigureIsCorrect($figure); $this->addToAssertionCount(1); } $expectedException = CardException::incorrectFigure('notExistedFigure'); $this->expectException(get_class($expectedException)); $this->expectExceptionMessage($expectedException->getMessage()); Card::checkFigureIsCorrect('notExistedFigure'); }