Skip to content

Instantly share code, notes, and snippets.

@mlively
Created February 23, 2011 04:34
Show Gist options
  • Save mlively/840025 to your computer and use it in GitHub Desktop.
Save mlively/840025 to your computer and use it in GitHub Desktop.
<?php
interface CardCollection
{
public function getNumberOfCards();
}
?>
<?php
interface DealerStrategy
{
public function deal(
CardCollection $deck,
PlayerCollection $players);
}
?>
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>)
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>)
<?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());
}
}
?>
<?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());
}
}
?>
<?php
class PhakeTest1 extends PHPUnit_Framework_TestCase
{
public function testBasicVerify()
{
$mock = Phake::mock('MyClass');
$mock->foo();
Phake::verify($mock)->foo();
}
}
?>
<?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));
}
}
?>
<?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));
}
}
?>
<?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