Created
March 5, 2011 18:30
-
-
Save mlively/856582 to your computer and use it in GitHub Desktop.
MyBestPokerGameTest.php
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 MagicClass | |
{ | |
public function __call($method, $args) | |
{ | |
return '__call'; | |
} | |
} | |
?> |
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 MagicClassTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testMagicCall() | |
{ | |
$mock = Phake::mock('MagicClass'); | |
$mock->magicCall(); | |
Phake::verify($mock)->magicCall(); | |
} | |
} | |
?> |
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 MagicClassTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testMagicCall() | |
{ | |
$mock = Phake::mock('MagicClass'); | |
$mock->magicCall(); | |
Phake::verifyCallMethodWith('magicCall')->isCalledOn($mock); | |
} | |
} | |
?> |
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 52CardDeckMatcher implements Phake_Matchers_IArgumentMatcher | |
{ | |
public function matches($argument) | |
{ | |
return ($argument instanceof CardCollection | |
&& $argument->getNumberOfCards() == 52); | |
} | |
public function __toString() | |
{ | |
return '<object:CardCollection with 52 cards>'; | |
} | |
} | |
class MyBestPokerGameTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testDealCards() | |
{ | |
$dealer = Phake::mock('MyPokerDealer'); | |
$players = Phake::mock('PlayerCollection'); | |
$cardGame = new MyPokerGame($dealer, $players); | |
Phake::verify($dealer)->deal(new 52CardDeckMatcher(), $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 MyTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testPHPUnitMock() | |
{ | |
$mock = Phake::mock('PhakeTest_MockedClass'); | |
$mock->fooWithArgument('foo'); | |
$mock->fooWithArgument('bar'); | |
Phake::inOrder( | |
Phake::verify($mock)->fooWithArgument('foo'), | |
Phake::verify($mock)->fooWithArgument('bar') | |
); | |
} | |
} | |
?> |
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 MyTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testPHPUnitMock() | |
{ | |
$mock = Phake::mock('PhakeTest_MockedClass'); | |
$mock->fooWithArgument('foo'); | |
$mock->fooWithArgument('bar'); | |
Phake::verify($mock)->fooWithArgument('foo'); | |
Phake::verify($mock)->fooWithArgument('bar'); | |
} | |
} | |
?> |
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 MyTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testPHPUnitMock() | |
{ | |
$mock = Phake::mock('PhakeTest_MockedClass'); | |
$mock->fooWithArgument('foo'); | |
$mock->fooWithArgument('foo'); | |
Phake::verify($mock, Phake::times(2))->fooWithArgument('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 MyTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testPHPUnitMock() | |
{ | |
$mock = $this->getMock('PhakeTest_MockedClass'); | |
$mock->expects($this->once())->method('fooWithArgument') | |
->with('foo'); | |
$mock->expects($this->once())->method('fooWithArgument') | |
->with('bar'); | |
$mock->fooWithArgument('foo'); | |
$mock->fooWithArgument('bar'); | |
} | |
} | |
?> |
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 MyTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testPHPUnitMock() | |
{ | |
$mock = $this->getMock('PhakeTest_MockedClass'); | |
//NOTICE this is now at() instead of once() | |
$mock->expects($this->at(0))->method('fooWithArgument') | |
->with('foo'); | |
//NOTICE this is now at() instead of once() | |
$mock->expects($this->at(1))->method('fooWithArgument') | |
->with('bar'); | |
$mock->fooWithArgument('foo'); | |
$mock->fooWithArgument('bar'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment