Created
December 20, 2013 09:30
-
-
Save tomphp/8052450 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 | |
/* | |
* Consider the following, fully tested and everything works, | |
*/ | |
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 MyAddedSpec extends \PhpSpec\ObjectBehavior | |
{ | |
function it_is_a_added() | |
{ | |
$this->shouldBeAnInstanceOf('BaseAdded'); | |
} | |
} | |
class MyAdder extends BaseAdder | |
{ | |
} | |
/* | |
* Now consider MyAdder is implemented like so, the tests all still pass | |
* but the functionality is broken. | |
* | |
* This could happen if someone decides to override the method with some | |
* new functionality but the test suite doesn't provided the safety to ensure | |
* that the existing requirements of the method are still met. | |
*/ | |
class MyAdder extends BaseAdder | |
{ | |
public function add() | |
{ | |
return 'Broken!'; | |
} | |
} | |
/* | |
* With phpunit I would create an AbstractAdderTest and extend MyAdderTest and | |
* any other adder tests from it, this way the the full interface of the child | |
* classes is tested. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment