Ejemplo n.º 1
0
 /**
  * @param Token $token
  *
  * @throws DomainException If the square is already occupied
  */
 public function occupyWith(Token $token)
 {
     if ($this->isOccupied() && $this->occupiedBy->owner()->equals($token->owner())) {
         throw new DomainException('Cannot occupy square that already keeps a token of the same color.');
     }
     $this->occupiedBy = $token;
 }
Ejemplo n.º 2
0
 /**
  * @param Token $token
  *
  * @throws DomainException If the token is already in play
  */
 public function add(Token $token)
 {
     $number = $token->number();
     if ($this->has($token->owner(), $number)) {
         throw new DomainException(sprintf('Token with number "%d" is already in play.', $number->value()));
     }
     $tokens = $this->tokensFor($token->owner());
     $tokens[$number->value()] = $token;
     $this->tokensOnTrack->attach($token->owner(), $tokens);
 }
Ejemplo n.º 3
0
 /** @test */
 public function notOwnedByGreen()
 {
     $token = new Token(Player::$YELLOW, new TokenNumber(1), new Square(0));
     $this->assertFalse($token->owner()->equals(Player::$GREEN));
 }