1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @category Zookal_Mock |
5
|
|
|
* @package Helper |
6
|
|
|
* @author Cyrill Schumacher | {firstName}@{lastName}.fm | @SchumacherFM |
7
|
|
|
* @copyright Copyright (c) Zookal Pty Ltd |
8
|
|
|
* @license OSL - Open Software Licence 3.0 | http://opensource.org/licenses/osl-3.0.php |
9
|
|
|
*/ |
10
|
|
|
class Zookal_Mock_Test_Model_Mocks_AbstractTest extends EcomDev_PHPUnit_Test_Case |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
protected $_class = 'Zookal_Mock_Model_Mocks_Abstract'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @return Zookal_Mock_Model_Mocks_Abstract |
16
|
|
|
*/ |
17
|
|
|
public function getInstance() |
18
|
|
|
{ |
19
|
|
|
return $this->getMockForAbstractClass($this->_class); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @test |
24
|
|
|
*/ |
25
|
|
|
public function itShouldExist() |
26
|
|
|
{ |
27
|
|
|
$this->assertTrue(class_exists($this->_class), "Failed asserting {$this->_class} exists"); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @test |
32
|
|
|
*/ |
33
|
|
|
public function itShouldBeAnInstanceOfMocksAbstract() |
34
|
|
|
{ |
35
|
|
|
$this->assertInstanceOf($this->_class, $this->getInstance()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @test |
40
|
|
|
*/ |
41
|
|
|
public function itShouldHaveAMethod__Call() |
42
|
|
|
{ |
43
|
|
|
$this->assertTrue(method_exists($this->_class, '__call')); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @test |
48
|
|
|
*/ |
49
|
|
|
public function itShouldHaveAMethodGetMessages() |
50
|
|
|
{ |
51
|
|
|
$this->assertTrue(method_exists($this->_class, 'getMessages')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @test |
56
|
|
|
*/ |
57
|
|
|
public function itShouldHaveAMethodGetMockMethodsReturnThis() |
58
|
|
|
{ |
59
|
|
|
$this->assertTrue(method_exists($this->_class, 'getMockMethodsReturnThis')); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @test |
64
|
|
|
*/ |
65
|
|
|
public function itShouldHaveAMethodgetMockMethodsReturnNull() |
66
|
|
|
{ |
67
|
|
|
$this->assertTrue(method_exists($this->_class, 'getMockMethodsReturnNull')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @test |
72
|
|
|
*/ |
73
|
|
|
public function itShouldHaveAMethodgetMockMethodsReturnFalse() |
74
|
|
|
{ |
75
|
|
|
$this->assertTrue(method_exists($this->_class, 'getMockMethodsReturnFalse')); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @test |
80
|
|
|
*/ |
81
|
|
|
public function itShouldReturnAMessageCollectionWhenCallingGetMessagesMethod() |
82
|
|
|
{ |
83
|
|
|
$this->assertInstanceOf('Mage_Core_Model_Message_Collection', $this->getInstance()->getMessages()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @test |
88
|
|
|
*/ |
89
|
|
|
public function itShouldReturnTheMocksHelper() |
90
|
|
|
{ |
91
|
|
|
$this->assertInstanceOf('Zookal_Mock_Helper_Data', $this->getInstance()->getHelper()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @test |
96
|
|
|
*/ |
97
|
|
|
public function itShouldReturnThis() |
98
|
|
|
{ |
99
|
|
|
$instance = $this->getInstance(); |
100
|
|
|
$thisMethods = $instance->getMockMethodsReturnThis(); |
101
|
|
|
foreach ($thisMethods as $method => $int) { |
102
|
|
|
$this->assertInstanceOf($this->_class, $instance->$method()); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @test |
108
|
|
|
*/ |
109
|
|
|
public function itShouldReturnThisWhenCallingACollection() |
110
|
|
|
{ |
111
|
|
|
$instance = $this->getInstance(); |
112
|
|
|
$this->assertInstanceOf($this->_class, $instance->getWildCatsCollection()); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @test |
117
|
|
|
*/ |
118
|
|
|
public function itShouldReturnNull() |
119
|
|
|
{ |
120
|
|
|
$instance = $this->getInstance(); |
121
|
|
|
$thisMethods = $instance->getMockMethodsReturnNull(); |
122
|
|
|
foreach ($thisMethods as $method => $int) { |
123
|
|
|
$this->assertNull($instance->$method()); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @test |
129
|
|
|
*/ |
130
|
|
|
public function itShouldReturnFalse() |
131
|
|
|
{ |
132
|
|
|
$instance = $this->getInstance(); |
133
|
|
|
$thisMethods = $instance->getMockMethodsReturnFalse(); |
134
|
|
|
foreach ($thisMethods as $method => $int) { |
135
|
|
|
$this->assertFalse($instance->$method()); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @test |
141
|
|
|
* @expectedException Varien_Exception |
142
|
|
|
*/ |
143
|
|
|
public function itShouldThrowAnExceptionWhenCallingUnknownMethod() |
144
|
|
|
{ |
145
|
|
|
$this->getInstance()->zzz(); |
146
|
|
|
} |
147
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.