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 |
||
| 5 | class SearchTest extends FormTestCase { |
||
| 6 | |||
| 7 | /** @test */ |
||
| 8 | public function it_can_be_rendered() |
||
| 9 | { |
||
| 10 | $form = $this->form(); |
||
| 11 | $form->search('foo'); |
||
| 12 | $this->assertContains('<input name="foo" value=""', $form->render()); |
||
| 13 | $this->assertContains('<button name="foo_button"', $form->render()); |
||
| 14 | } |
||
| 15 | |||
| 16 | /** @test */ |
||
| 17 | public function it_renders_a_default_value() |
||
| 18 | { |
||
| 19 | $form = $this->form(); |
||
| 20 | $form->search('foo')->default('bar'); |
||
| 21 | $this->assertContains('<input name="foo" value="bar"', $form->render()); |
||
| 22 | } |
||
| 23 | |||
| 24 | } |
||
| 25 |