Created
February 8, 2011 07:10
-
-
Save mlively/816021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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())); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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