示例#1
0
文件: Card.php 项目: bnowak/card-game
 /**
  * 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);
     }
 }
示例#2
0
 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');
 }
示例#3
0
 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');
 }