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 WidgetMinificationTest extends TestCase |
||
| 6 | { |
||
| 7 | public function test_minifies_the_output() |
||
| 8 | { |
||
| 9 | config(['widgetize.minify_html' => true]); |
||
| 10 | config(['widgetize.debug_info' => false]); |
||
| 11 | |||
| 12 | app()['env'] = 'local'; |
||
| 13 | |||
| 14 | $widgetOutput = ' <p> </p> '; |
||
| 15 | $minified = ' <p> </p> '; |
||
| 16 | |||
| 17 | View::shouldReceive('exists')->once()->andReturn(true); |
||
| 18 | View::shouldReceive('make')->once()->with('hello', ['data' => null], [])->andReturn(app('view')); |
||
| 19 | View::shouldReceive('render')->once()->andReturn($widgetOutput); |
||
| 20 | |||
| 21 | //act |
||
| 22 | $widget = new Widget7(); |
||
| 23 | $widgetOutput = render_widget($widget); |
||
| 24 | $this->assertEquals($minified, $widgetOutput); |
||
| 25 | } |
||
| 26 | |||
| 27 | public function test_minifies_the_output_in_production_with_cache_turned_off() |
||
| 28 | { |
||
| 29 | config(['widgetize.minify_html' => false]); |
||
| 30 | config(['widgetize.debug_info' => false]); |
||
| 31 | app()['env'] = 'production'; |
||
| 32 | |||
| 33 | $html = ' <p> </p> '; |
||
| 34 | $minified = ' <p> </p> '; |
||
| 35 | |||
| 36 | View::shouldReceive('exists')->once()->andReturn(true); |
||
| 37 | View::shouldReceive('make')->once()->with('hello', ['data' => null], [])->andReturn(app('view')); |
||
| 38 | View::shouldReceive('render')->once()->andReturn($html); |
||
| 39 | |||
| 40 | //act |
||
| 41 | $widget = new Widget7(); |
||
| 42 | $html = render_widget($widget); |
||
| 43 | $this->assertEquals($minified, $html); |
||
| 44 | } |
||
| 45 | } |
||
| 46 |