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 |
||
| 7 | class PlanTest extends \PHPUnit_Framework_TestCase |
||
| 8 | { |
||
| 9 | public function testRoot() |
||
| 10 | { |
||
| 11 | $r = new Plan(); |
||
| 12 | $this->assertEquals('/plan', $r->root()); |
||
| 13 | } |
||
| 14 | |||
| 15 | public function testEndpoints() |
||
| 16 | { |
||
| 17 | $r = new Plan(); |
||
| 18 | $this->assertEquals('/plan', $r->create()[RouteInterface::ENDPOINT_KEY]); |
||
| 19 | $this->assertEquals('/plan', $r->getList()[RouteInterface::ENDPOINT_KEY]); |
||
| 20 | $this->assertEquals('/plan/{id}', $r->fetch()[RouteInterface::ENDPOINT_KEY]); |
||
| 21 | $this->assertEquals('/plan/{id}', $r->update()[RouteInterface::ENDPOINT_KEY]); |
||
| 22 | } |
||
| 23 | |||
| 24 | public function testMethods() |
||
| 25 | { |
||
| 26 | $r = new Plan(); |
||
| 27 | $this->assertEquals(RouteInterface::POST_METHOD, $r->create()[RouteInterface::METHOD_KEY]); |
||
| 28 | $this->assertEquals(RouteInterface::GET_METHOD, $r->getList()[RouteInterface::METHOD_KEY]); |
||
| 29 | $this->assertEquals(RouteInterface::GET_METHOD, $r->fetch()[RouteInterface::METHOD_KEY]); |
||
| 30 | $this->assertEquals(RouteInterface::PUT_METHOD, $r->update()[RouteInterface::METHOD_KEY]); |
||
| 31 | } |
||
| 32 | } |
||
| 33 |