|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
App::uses('ShellDispatcher', 'Console'); |
|
4
|
|
|
App::uses('ConsoleOutput', 'Console'); |
|
5
|
|
|
App::uses('ConsoleInput', 'Console'); |
|
6
|
|
|
App::uses('Shell', 'Console'); |
|
7
|
|
|
App::uses('ShellModelTruncator', 'FakeSeeder.Lib'); |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* ShellModelTruncator Test |
|
11
|
|
|
* |
|
12
|
|
|
* @coversDefaultClass ShellModelTruncator |
|
13
|
|
|
*/ |
|
14
|
|
|
class ShellModelTruncatorTest extends CakeTestCase { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The fixtures |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
public $fixtures = array( |
|
22
|
|
|
'plugin.fake_seeder.apple', |
|
23
|
|
|
'plugin.fake_seeder.banana', |
|
24
|
|
|
'plugin.fake_seeder.pear', |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The shell object |
|
29
|
|
|
* |
|
30
|
|
|
* @var null|Shell |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $_shell = null; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The object under test |
|
36
|
|
|
* |
|
37
|
|
|
* @var null|ShellModelTruncator |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $_truncator = null; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Setup the object under test |
|
43
|
|
|
* |
|
44
|
|
|
* @return void |
|
45
|
|
|
*/ |
|
46
|
|
|
public function setUp() { |
|
47
|
|
|
parent::setUp(); |
|
48
|
|
|
|
|
49
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false); |
|
50
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false); |
|
51
|
|
|
$this->_shell = $this->getMock('Shell', |
|
52
|
|
|
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop'), |
|
53
|
|
|
array($out, $out, $in) |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$this->_truncator = new ShellModelTruncator($this->_shell); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Test the constructor |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
* @covers ::__construct |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testConstruct() { |
|
66
|
|
|
$truncator = new ShellModelTruncator($this->_shell); |
|
|
|
|
|
|
67
|
|
|
$this->assertAttributeInstanceOf('Shell', '_shell', $truncator); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Tests the truncateModels function |
|
72
|
|
|
* |
|
73
|
|
|
* @return void |
|
74
|
|
|
* @covers ::truncateModels |
|
75
|
|
|
*/ |
|
76
|
|
|
public function testTruncateModels() { |
|
77
|
|
|
$this->_shell->expects($this->at(0))->method('out')->with($this->equalTo('Truncate model Apple...')); |
|
78
|
|
|
$this->_shell->expects($this->at(1))->method('out')->with($this->equalTo('Truncate model Banana...')); |
|
79
|
|
|
$this->_shell->expects($this->at(2))->method('out')->with($this->equalTo('Truncate model Pear...')); |
|
80
|
|
|
|
|
81
|
|
|
$models = array('Apple', 'Banana', 'Pear'); |
|
82
|
|
|
$this->_truncator->truncateModels($models); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: