Created
February 23, 2011 04:34
-
-
Save mlively/840025 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 | |
interface CardCollection | |
{ | |
public function getNumberOfCards(); | |
} | |
?> |
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 | |
interface DealerStrategy | |
{ | |
public function deal( | |
CardCollection $deck, | |
PlayerCollection $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
Exception: Expected MyPokerDealer->deal(<captured parameter>, | |
equal to <object:PlayerCollection>) to be called exactly 1 | |
times, actually called 0 times. | |
Other Invocations: | |
PhakeTest_MockedClass->fooWithArgument(<array>, | |
<object:PlayerCollection>) |
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
Expected DealerStrategy->fooWithArgument(equal to | |
<object:CardCollection>, equal to <object:PlayerCollection>) | |
to be called exactly 1 times, actually called 0 times. | |
Other Invocations: | |
PhakeTest_MockedClass->fooWithArgument(<null>, | |
equal to <object:PlayerCollection>) |
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 MyBetterPokerGameTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testDealCards() | |
{ | |
$dealer = Phake::mock('MyPokerDealer'); | |
$players = Phake::mock('PlayerCollection'); | |
$cardGame = new MyPokerGame($dealer, $players); | |
Phake::verify($dealer)->deal( | |
Phake::capture($deck) | |
->when($this->isInstanceOf('CardCollection')), | |
$players | |
); | |
$this->assertEquals(52, $deck->getNumberOfCards()); | |
} | |
} | |
?> |
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 MyPokerGameTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testDealCards() | |
{ | |
$dealer = Phake::mock('MyPokerDealer'); | |
$players = Phake::mock('PlayerCollection'); | |
$cardGame = new MyPokerGame($dealer, $players); | |
Phake::verify($dealer)->deal(Phake::capture($deck), $players); | |
$this->assertEquals(52, $deck->getNumberOfCards()); | |
} | |
} | |
?> |
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 PhakeTest1 extends PHPUnit_Framework_TestCase | |
{ | |
public function testBasicVerify() | |
{ | |
$mock = Phake::mock('MyClass'); | |
$mock->foo(); | |
Phake::verify($mock)->foo(); | |
} | |
} | |
?> |
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 TestHamcrestMatcher extends UnitTestCase | |
{ | |
public function testDealNumberOfCards() | |
{ | |
$deck = Phake::mock('CardCollection'); | |
$players = Phake::mock('PlayerCollection'); | |
$dealer = Phake::mock('DealerStrategy'); | |
$dealer->deal($deck, $players, 11); | |
Phake::verify($dealer)->deal($deck, $players, greaterThan(10)); | |
} | |
} | |
?> |
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 TestPHPUnitConstraint extends PHPUnit_Framework_TestCase | |
{ | |
public function testDealNumberOfCards() | |
{ | |
$deck = Phake::mock('CardCollection'); | |
$players = Phake::mock('PlayerCollection'); | |
$dealer = Phake::mock('DealerStrategy'); | |
$dealer->deal($deck, $players, 11); | |
Phake::verify($dealer) | |
->deal($deck, $players, $this->greaterThan(10)); | |
} | |
} | |
?> |
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 | |
//I don't have Concrete versions of | |
// CardCollection or PlayerCollection yet | |
$deck = Phake::mock('CardCollection'); | |
$players = Phake::mock('PlayerCollection'); | |
$dealer = Phake::mock('DealerStrategy'); | |
$dealer->deal($deck, $players); | |
Phake::verify($dealer)->deal($deck, $players); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment