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 PageTest extends \PHPUnit_Framework_TestCase |
||
8 | { |
||
9 | public function testRoot() |
||
10 | { |
||
11 | $r = new Page(); |
||
12 | $this->assertEquals('/page', $r->root()); |
||
13 | } |
||
14 | |||
15 | public function testEndpoints() |
||
16 | { |
||
17 | $r = new Page(); |
||
18 | $this->assertEquals('/page', $r->create()[RouteInterface::ENDPOINT_KEY]); |
||
19 | $this->assertEquals('/page', $r->getList()[RouteInterface::ENDPOINT_KEY]); |
||
20 | $this->assertEquals('/page/{id}', $r->fetch()[RouteInterface::ENDPOINT_KEY]); |
||
21 | $this->assertEquals('/page/{id}', $r->update()[RouteInterface::ENDPOINT_KEY]); |
||
22 | } |
||
23 | |||
24 | public function testMethods() |
||
25 | { |
||
26 | $r = new Page(); |
||
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 |