Skip to content

Commit

Permalink
Add methods for retrieving starting/benched players
Browse files Browse the repository at this point in the history
  • Loading branch information
cspivack committed Nov 27, 2021
1 parent 693a9d4 commit f92831b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/FightingBaseballProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ public function player()
return new Player(static::randomElement(static::$players));
}

public function startingPlayer()
{
static $startingPlayers;
$startingPlayers = $startingPlayers ?: array_filter(static::$players, function ($player) { return !$player['bench']; });

return new Player(static::randomElement($startingPlayers));
}

public function benchedPlayer()
{
static $benchedPlayers;
$benchedPlayers = $benchedPlayers ?: array_filter(static::$players, function ($player) { return $player['bench']; });

return new Player(static::randomElement($benchedPlayers));
}

public function playerPosition()
{
return static::randomElement(static::$positions);
Expand Down
10 changes: 10 additions & 0 deletions tests/PlayerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ public function testCanReturnPlayerObjectBenched(): void
{
$this->assertIsBool($this->faker->player()->benched());
}

public function testCanReturnStartingPlayer(): void
{
$this->assertFalse($this->faker->startingPlayer()->benched());
}

public function testCanReturnBenchedPlayer(): void
{
$this->assertTrue($this->faker->benchedPlayer()->benched());
}
}

0 comments on commit f92831b

Please sign in to comment.