Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 9 | class CallbackUrlNormalizerTest extends \PHPUnit_Framework_TestCase |
||
| 10 | { |
||
| 11 | public function test_callback_is_called() |
||
| 12 | { |
||
| 13 | $callback = function(Url $url) { |
||
| 14 | $url->__toString(); |
||
| 15 | }; |
||
| 16 | |||
| 17 | $url = m::mock(Url::class); |
||
| 18 | $url->shouldReceive('__toString')->once(); |
||
| 19 | |||
| 20 | $callbackUrlMatcher = new CallbackUrlNormalizer($callback); |
||
| 21 | $callbackUrlMatcher->normalize($url); |
||
| 22 | } |
||
| 23 | |||
| 24 | protected function tearDown() |
||
| 25 | { |
||
| 26 | parent::tearDown(); |
||
| 27 | |||
| 28 | m::close(); |
||
| 29 | } |
||
| 30 | } |