Skip to content

Instantly share code, notes, and snippets.

@muhamed-didovic
Forked from mathiasverraes/BankAccount1.php
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save muhamed-didovic/2fc0927755be0933768f to your computer and use it in GitHub Desktop.

Select an option

Save muhamed-didovic/2fc0927755be0933768f to your computer and use it in GitHub Desktop.
<?php
class BankAccount
{
private $twitter;
public function __construct(Twitter $twitter)
{
$this->twitter = $twitter;
}
public function deposit($amount){
}
}
<?php
class BankAccount
{
// ...
public function deposit($amount)
{
$this->twitter->tweet("Yay, someone deposited $amount");
}
}
<?php
class BankAccountTest extends PHPUnit_Framework_TestCase
{
public function testSendEmailWhenReceivingMoney()
{
$twitter = $this->getMock('Twitter');
$account = new BankAccount($twitter);
$account->deposit(10);
}
}
<?php
class BankAccountTest extends PHPUnit_Framework_TestCase
{
public function testSendEmailWhenReceivingMoney()
{
$twitter = $this->getMock('Twitter');
$twitter->expects($this->once())
->method('tweet');
$account = new BankAccount($twitter);
$account->deposit(10);
}
}
<?php
interface Twitter
{
function tweet($message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment