Created
December 20, 2013 10:11
-
-
Save tomphp/8052832 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BaseAdder | |
{ | |
public function add($a, $b) | |
{ | |
return $a + $b; | |
} | |
} | |
class BaseAdderSpec extends \PhpSpec\ObjectBehavior | |
{ | |
function it_adds() | |
{ | |
$this->add(1, 2)->shouldReturn(3); | |
} | |
} | |
class LogAdder extends BaseAdder | |
{ | |
protected $logger; | |
public function __construct($logger) | |
{ | |
$this->logger = $logger; | |
} | |
public function add($a, $b) | |
{ | |
$this->logger->log("adding $a and $b"); | |
parent::add($a + $b); | |
} | |
} | |
class LogAddedSpec extends \PhpSpec\ObjectBehavior | |
{ | |
function it_is_a_added() | |
{ | |
$this->shouldBeAnInstanceOf('BaseAdded'); | |
} | |
function it_logs() | |
{ | |
$this->logger->log("adding 1 and 2")->shouldBeCalled(); | |
$this->add(1, 2); | |
} | |
/* | |
* This test appears in BaseAdderSpec too but if it is left out of here | |
* there's no proof that the actually adding functionality works. | |
* | |
* Having it in 2 places also means that we have to remember to update | |
* here if the base class add() functionality is changed otherwise tests | |
* will still pass with a broken codebase. | |
*/ | |
function it_adds() | |
{ | |
$this->add(1, 2)->shouldReturn(3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment