ViewRenderTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 14
loc 42
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testDefaultRender() 0 6 1
A testMobileRender() 7 7 1
A testTabletRender() 7 7 1
A testRestoreRenderer() 0 7 1
A mockApplication() 0 6 1

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
 * @link https://github.com/vuongxuongminh/yii2-mobile-first
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace vxm\test\unit\mobileFirst;
9
10
use Yii;
11
12
/**
13
 * Class ViewRenderBehaviorTest
14
 *
15
 * @author Vuong Minh <[email protected]>
16
 * @since 1.0.0
17
 */
18
class ViewRenderTest extends TestCase
19
{
20
21
    public function testDefaultRender()
22
    {
23
        $output = Yii::$app->runAction('test/test');
24
25
        $this->assertEquals('default', trim($output));
26
    }
27
28 View Code Duplication
    public function testMobileRender()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1';
31
        $output = Yii::$app->runAction('test/test');
32
33
        $this->assertEquals('mobile', trim($output));
34
    }
35
36 View Code Duplication
    public function testTabletRender()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25';
39
        $output = Yii::$app->runAction('test/test');
40
41
        $this->assertEquals('tablet', trim($output));
42
    }
43
44
    public function testRestoreRenderer()
45
    {
46
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25';
47
        Yii::$app->runAction('test/test');
48
49
        $this->assertEquals(TestRenderer::class, get_class(Yii::$app->getView()->renderers['php']));
50
    }
51
52
    public function mockApplication($config = [], $appClass = '\yii\web\Application'): void
53
    {
54
        parent::mockApplication($config, $appClass);
55
56
        Yii::$app->getBehavior('mobileFirst')->detach();
57
    }
58
59
}
60