Example #1
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);
 }
Example #2
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;
 }
Example #3
0
 /** @test */
 public function notOwnedByGreen()
 {
     $token = new Token(Player::$YELLOW, new TokenNumber(1), new Square(0));
     $this->assertFalse($token->owner()->equals(Player::$GREEN));
 }