1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @category Zookal_Mock |
5
|
|
|
* @package Model |
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
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Zookal_Mock_Model_Mocks_Abstract |
13
|
|
|
* @method Zookal_Mock_Model_Mocks_Abstract getWildCatsCollection() |
14
|
|
|
* @method Zookal_Mock_Model_Mocks_Abstract zzz() Calling this method throws an error in the test |
15
|
|
|
*/ |
16
|
|
|
abstract class Zookal_Mock_Model_Mocks_Abstract |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Zookal_Mock_Helper_Data |
21
|
|
|
*/ |
22
|
|
|
protected $_helper = null; |
23
|
|
|
|
24
|
|
|
protected $_isLogEnabled = false; |
25
|
|
|
|
26
|
|
|
protected $_mockMethodsReturnThis = array( |
27
|
|
|
'add' => 1, // e.g. addCustomerFilter ... |
28
|
|
|
'cle' => 1, // e.g. clean() clear() clearasil() |
|
|
|
|
29
|
|
|
'collectrates' => 1, // e.g. Mage_Shipping_Model_Shipping::collectRates() |
30
|
|
|
'fil' => 1, // e.g. filterByCustomerId() when getCollection() is called |
31
|
|
|
'gettotals' => 1, // Special case in Sales_Collection |
32
|
|
|
'gro' => 1, // e.g. groupByCustomer |
33
|
|
|
'joi' => 1, // e.g. joinCustomerName |
34
|
|
|
'loa' => 1, // e.g. load and loadBy.... |
35
|
|
|
'lim' => 1, // e.g. limit() -> on collection |
36
|
|
|
'ord' => 1, // e.g. orderByTotalAmount |
37
|
|
|
'pre' => 1, // e.g. prepare() |
38
|
|
|
'resetsortorder' => 1, |
39
|
|
|
'renewsession' => 1, |
40
|
|
|
'sav' => 1, // e.g. save() |
41
|
|
|
'set' => 1, |
42
|
|
|
'too' => 1, // e.g. toOptionArray, toOptionHash |
43
|
|
|
'uns' => 1, |
44
|
|
|
'pro' => 1, // Weee Helper->processTierPrices() |
|
|
|
|
45
|
|
|
); |
46
|
|
|
protected $_mockMethodsReturnNull = array( |
47
|
|
|
'count' => 1, |
48
|
|
|
'get' => 1, |
49
|
|
|
'toh' => 1, // toHtml() on blocks |
50
|
|
|
); |
51
|
|
|
protected $_mockMethodsReturnFalse = array( |
52
|
|
|
'displaygirthvalue' => 1, // Mage_Usa helper in packaging/popup.phtml |
53
|
|
|
'can' => 1, // canCapture and all other payment related methods |
54
|
|
|
'has' => 1, |
55
|
|
|
'isa' => 1, // e.g. isAvailable -> Payment |
56
|
|
|
'isd' => 1, // e.g. isDiscounted e.g. Weee helper |
57
|
|
|
'ise' => 1, // e.g. isEnabled e.g. Weee helper |
58
|
|
|
'isg' => 1, // e.g. isGateway -> Payment |
59
|
|
|
'isi' => 1, // e.g. isInitializeNeeded -> Payment |
60
|
|
|
'ism' => 1, // e.g. isMessagesAvailable -> GiftMessage |
61
|
|
|
'iss' => 1, // e.g. isSubscribed |
62
|
|
|
'ist' => 1, // e.g. isTaxable in Weee |
63
|
|
|
'isv' => 1, // e.g. isValid... |
64
|
|
|
'isl' => 1, // e.g. isLoggedIn |
65
|
|
|
'use' => 1, |
66
|
|
|
'typ' => 1, // Weee Helper->typeofdisplay() |
|
|
|
|
67
|
|
|
'val' => 1, // Weee Helper->validateCatalogPricesAndFptConfiguration() |
|
|
|
|
68
|
|
|
'inc' => 1, // Weee Helper->includeInSubtotal() |
|
|
|
|
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param Zookal_Mock_Helper_Data $helper |
73
|
|
|
*/ |
74
|
|
|
public function __construct($helper = null) |
75
|
|
|
{ |
76
|
|
|
// $helper is sometimes an empty array ... |
77
|
|
|
if (false === empty($helper) && $helper instanceof Zookal_Mock_Helper_Data) { |
78
|
|
|
$this->_helper = $helper; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$this->_isLogEnabled = $this->getHelper()->isLogMethodEnabled(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Add/Set/Get attribute wrapper |
86
|
|
|
* |
87
|
|
|
* @param string $method |
88
|
|
|
* @param array $args |
89
|
|
|
* |
90
|
|
|
* @return $this|bool|null |
91
|
|
|
* @throws Varien_Exception |
92
|
|
|
*/ |
93
|
|
|
public function __call($method, $args) |
94
|
|
|
{ |
95
|
|
|
$lowerMethod = strtolower($method); |
96
|
|
|
$firstThree = substr($lowerMethod, 0, 3); |
97
|
|
|
$methods = array( |
98
|
|
|
'_isReturnThis' => $this, |
99
|
|
|
'_isReturnNull' => null, |
100
|
|
|
'_isReturnFalse' => false, |
101
|
|
|
); |
102
|
|
|
foreach ($methods as $method => $return) { |
103
|
|
|
if (true === $this->$method($lowerMethod, $firstThree)) { |
104
|
|
|
$this->_log('return: ' . $method); |
105
|
|
|
return $return; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
throw new Varien_Exception("Invalid method " . get_class($this) . "::" . $method . ' Cannot print args ...'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param string $lowerMethod |
113
|
|
|
* @param string $firstThree |
114
|
|
|
* |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
protected function _isReturnFalse($lowerMethod, $firstThree) |
118
|
|
|
{ |
119
|
|
|
return isset($this->_mockMethodsReturnFalse[$firstThree]) || |
120
|
|
|
isset($this->_mockMethodsReturnFalse[$lowerMethod]); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $lowerMethod |
125
|
|
|
* @param string $firstThree |
126
|
|
|
* |
127
|
|
|
* @return bool |
128
|
|
|
*/ |
129
|
|
|
protected function _isReturnNull($lowerMethod, $firstThree) |
130
|
|
|
{ |
131
|
|
|
return isset($this->_mockMethodsReturnNull[$lowerMethod]) || |
132
|
|
|
isset($this->_mockMethodsReturnNull[$firstThree]); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param string $lowerMethod |
137
|
|
|
* @param string $firstThree |
138
|
|
|
* |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
protected function _isReturnThis($lowerMethod, $firstThree) |
142
|
|
|
{ |
143
|
|
|
// e.g. getCollection() getItemCollection() and so on |
144
|
|
|
return strpos($lowerMethod, 'collection') !== false || |
145
|
|
|
isset($this->_mockMethodsReturnThis[$lowerMethod]) || |
146
|
|
|
isset($this->_mockMethodsReturnThis[$firstThree]); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Special case if Mage_Tag is disabled or any other module which rely on initLayoutMessages |
151
|
|
|
* |
152
|
|
|
* @return Mage_Core_Model_Message_Collection |
153
|
|
|
*/ |
154
|
|
|
public function getMessages() |
155
|
|
|
{ |
156
|
|
|
return Mage::getModel('core/message_collection'); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* uncomment this in dev env to see what methods are called |
161
|
|
|
* |
162
|
|
|
* @param string $msg |
163
|
|
|
*/ |
164
|
|
|
protected function _log($msg) |
165
|
|
|
{ |
166
|
|
|
if (true === $this->_isLogEnabled) { |
167
|
|
|
Mage::log(get_class($this) . '::' . $msg, null, 'mock.log'); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return Zookal_Mock_Helper_Data |
173
|
|
|
*/ |
174
|
|
|
public function getHelper() |
175
|
|
|
{ |
176
|
|
|
if (null === $this->_helper) { |
177
|
|
|
$this->_helper = Mage::helper('zookal_mock'); |
178
|
|
|
} |
179
|
|
|
return $this->_helper; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return array |
184
|
|
|
*/ |
185
|
|
|
public function getMockMethodsReturnFalse() |
186
|
|
|
{ |
187
|
|
|
return $this->_mockMethodsReturnFalse; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return array |
192
|
|
|
*/ |
193
|
|
|
public function getMockMethodsReturnNull() |
194
|
|
|
{ |
195
|
|
|
return $this->_mockMethodsReturnNull; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return array |
200
|
|
|
*/ |
201
|
|
|
public function getMockMethodsReturnThis() |
202
|
|
|
{ |
203
|
|
|
return $this->_mockMethodsReturnThis; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
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.