Skip to content

Instantly share code, notes, and snippets.

@tomphp
Created December 20, 2013 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomphp/8052450 to your computer and use it in GitHub Desktop.
Save tomphp/8052450 to your computer and use it in GitHub Desktop.
<?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