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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.