Completed
Push — master ( ccdc3c...202605 )
by Andrii
04:16
created

CommandTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 16
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A tearDown() 0 3 1
A testSearch() 8 8 1
A testPerform() 8 8 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
/*
4
 * Tools to use API as ActiveRecord for Yii2
5
 *
6
 * @link      https://github.com/hiqdev/yii2-hiart
7
 * @package   yii2-hiart
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\hiart\tests\unit;
13
14
use hiqdev\hiart\Command;
15
use hiqdev\hiart\tests\Mock;
16
use Yii;
17
18
/**
19
 * Command test class.
20
 */
21
class CommandTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var Command
25
     */
26
    protected $object;
27
28
    /**
29
     * @var Mock
30
     */
31
    protected $mock;
32
33
    protected $action  = 'testAction';
34
    protected $options = ['a' => 'b'];
35
    protected $result  = ['x' => 'z'];
36
37
    protected function setUp()
38
    {
39
        $this->mock = new Mock($this->result);
40
        $this->object = Yii::createObject([
41
            'class' => Command::className(),
42
            'index' => 'test',
43
            'db'    => $this->mock,
44
        ]);
45
    }
46
47
    protected function tearDown()
48
    {
49
    }
50
51 View Code Duplication
    public function testSearch()
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...
52
    {
53
        $result = $this->object->search($this->options);
54
        $this->assertSame($this->result, $result);
55
        $this->assertSame('post', $this->mock->name);
56
        $this->assertSame('testSearch', $this->mock->args[0]);
57
        $this->assertSame($this->options, $this->mock->args[1]);
58
    }
59
60 View Code Duplication
    public function testPerform()
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...
61
    {
62
        $result = $this->object->perform($this->action, $this->options);
63
        $this->assertSame($this->result, $result);
64
        $this->assertSame('post', $this->mock->name);
65
        $this->assertSame($this->action, $this->mock->args[0]);
66
        $this->assertSame($this->options, $this->mock->args[1]);
67
    }
68
}
69