Skip to content

Instantly share code, notes, and snippets.

@mlively
Created February 8, 2011 07:10
Show Gist options
  • Save mlively/816021 to your computer and use it in GitHub Desktop.
Save mlively/816021 to your computer and use it in GitHub Desktop.
<?php
class CardGame
{
private $dealerStrategy;
private $deck;
private $players;
public function CardGame(DealerStrategy $dealerStrategy, CardCollection $deck, PlayerCollection $players)
{
$this->dealerStrategy = $dealerStrategy;
$this->deck = $deck;
$this->players = $players;
}
public function dealCards()
{
$this->deck->shuffle();
$this->dealerStrategy->deal($deck, $players);
}
}
?>
<?php
class CardGameTest1 extends PHPUnit_Framework_TestCase
{
public function testDealCards()
{
$dealer = new FiveCardPokerDealer();
$deck = new StandardDeck();
$player1 = new Player();
$player2 = new Player();
$player3 = new Player();
$player4 = new Player();
$players = new PlayerCollection(array($player1, $player2, $player3, $player4);
$cardGame = new CardGame($dealer, $deck, $players);
$cardGame->dealCards();
$this->assertEquals(5, count($player1->getCards()));
$this->assertEquals(5, count($player2->getCards()));
$this->assertEquals(5, count($player3->getCards()));
$this->assertEquals(5, count($player4->getCards()));
}
}
?>
<?php
class CardGameTest2 extends PHPUnit_Framework_TestCase
{
public function testDealCards()
{
$dealer = Phake::mock('DealerStrategy');
$deck = Phake::mock('CardCollection');
$players = Phake::mock('PlayerCollection');
$cardGame = new CardGame($dealer, $deck, $players);
$cardGame->dealCards();
Phake::verify($deck)->shuffle();
Phake::verify($dealer)->deal($deck, $players);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment