예제 #1
0
 public function setUp()
 {
     parent::setUp();
     $user = User::create(['login' => 'test', 'password' => 'a']);
     $game = Game::create(['type' => 'cricket']);
     $game->addPlayer($user->getId());
     $this->gameUser = $gameUser = Arrays::first($game->game_users);
     $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]);
 }
예제 #2
0
 public function setUp()
 {
     parent::setUp();
     /** @var User $user */
     $user = User::create(['login' => 'A']);
     $this->game = $game = Game::create(['type' => '101']);
     $this->gameUser = $gameUser = GameUser::create(['game_id' => $game->getId(), 'user_id' => $user->getId()]);
     $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]);
 }
예제 #3
0
 /**
  * @test
  */
 public function shouldReturnMostFrequentlyHitField()
 {
     //given
     $user = User::create(['login' => 'A']);
     $game = Game::create(['type' => 'cricket']);
     $gameUser = $game->addPlayer($user->getId());
     Hit::createFor('15t', $gameUser);
     Hit::createFor('16s', $gameUser);
     Hit::createFor('16s', $gameUser);
     //when
     $field = $user->mostFrequentlyHitField();
     //then
     $this->assertEquals('16', $field);
 }
예제 #4
0
 /**
  * @test
  */
 public function shouldCalculateIsNotShittyRound()
 {
     //given
     $user = User::create(['login' => 'A']);
     $game = Game::create(['type' => 'cricket']);
     $gameUser = GameUser::create(['game_id' => $game->id, 'user_id' => $user->getId()]);
     $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]);
     Hit::createFor('15t', $gameUser);
     Hit::createFor('16t', $gameUser);
     Hit::createFor('17t', $gameUser);
     //when
     $isShittyRound = $gameUser->isShittyRound();
     //then
     $this->assertFalse($isShittyRound);
 }
예제 #5
0
 /**
  * @test
  */
 public function shouldGetHitsOnlyForPlayersInCurrentGame()
 {
     //given
     $user = User::create(['login' => 'test', 'password' => 'a']);
     $game1 = Game::create();
     $game1->addPlayer($user->getId());
     /** @var GameUser $gameUser1 */
     $gameUser1 = Arrays::first($game1->game_users);
     $game2 = Game::create();
     $game2->addPlayer($user->getId());
     /** @var GameUser $gameUser2 */
     $gameUser2 = Arrays::first($game2->game_users);
     Hit::createFor('4d', $gameUser1);
     Hit::createFor('15t', $gameUser2);
     //when
     $hits = Hit::findForGame($game1);
     //then
     Assert::thatArray($hits)->onProperty('field')->containsExactly('4');
 }
예제 #6
0
 /**
  * @test
  * @dataProvider hits
  */
 public function shouldReturnIsScoredIfFieldIsInRange($hit, $isScored)
 {
     //given
     $user = User::create(['login' => 'A']);
     $game = Game::create(['type' => 'cricket']);
     $gameUser = GameUser::create(['game_id' => $game->id, 'user_id' => $user->getId()]);
     $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]);
     //when
     $hit = Hit::createFor($hit, $gameUser);
     //then
     $this->assertEquals($isScored, $hit->isScored());
 }
예제 #7
0
 /**
  * @test
  */
 public function shouldShowUser()
 {
     //given
     $user = User::create(array('login' => 'login'));
     //when
     $this->get("/users/{$user->id}");
     //then
     $this->assertRenders('Users/show');
 }
예제 #8
0
 /**
  * @test
  */
 public function shouldRestartLastGame()
 {
     //given
     /** @var User $user1 */
     $user1 = User::create(['login' => 'A']);
     /** @var User $user2 */
     $user2 = User::create(['login' => 'B']);
     $game1 = Game::create();
     $game1->addPlayer($user1->getId());
     $game1->addPlayer($user2->getId());
     $game1->updateAttributes(['finished' => true]);
     //when
     Game::restart();
     //then
     $game = Game::findUnfinishedGame();
     $this->assertFalse($game->isFinished());
     $this->assertTrue($game->isStarted());
     Assert::thatArray(GameUser::where(['game_id' => $game->getId()])->fetchAll())->hasSize(2)->onProperty('user_id')->containsExactly($user1->getId(), $user2->getId());
 }