Passed
Push — master ( 75387a...e2c3a7 )
by Iman
02:08
created

WidgetMinificationTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 90.24 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 37
loc 41
rs 10
wmc 2
lcom 0
cbo 2

How to fix   Duplicated Code   

Duplicated Code

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
2
3
require_once 'test_stubs.php';
4
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