|
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_Helper_Data extends Mage_Core_Helper_Abstract |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var Mage_Core_Model_Store |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $_store = null; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var boolean |
|
20
|
|
|
*/ |
|
21
|
|
|
private $_includePathSet = null; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param Mage_Core_Model_Store $store |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(Mage_Core_Model_Store $store = null) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->_store = $store; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return Mage_Core_Model_Store |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getStore() |
|
35
|
|
|
{ |
|
36
|
|
|
if (null === $this->_store) { |
|
37
|
|
|
$this->_store = Mage::app()->getStore(); |
|
38
|
|
|
} |
|
39
|
|
|
return $this->_store; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return boolean |
|
44
|
|
|
*/ |
|
45
|
|
|
public function isLogMethodEnabled() |
|
46
|
|
|
{ |
|
47
|
|
|
return (int)$this->getStore()->getConfig('dev/zookalmock/enable_method_log') === 1; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Appends a new include path to the current existing one. |
|
52
|
|
|
* Appending is for performance reasons mandatory |
|
53
|
|
|
* |
|
54
|
|
|
* @param array $customFakePath |
|
55
|
|
|
* |
|
56
|
|
|
* @return bool |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setMockPhpIncludePath(array $customFakePath = null) |
|
59
|
|
|
{ |
|
60
|
|
|
if (null === $this->_includePathSet) { |
|
61
|
|
|
$currentIncludePath = get_include_path(); |
|
62
|
|
|
|
|
63
|
|
|
$path = $this->_getCustomFakePath($customFakePath); |
|
64
|
|
|
if (strpos($currentIncludePath, $path) !== false) { |
|
65
|
|
|
$this->_includePathSet = false; // has already been set |
|
66
|
|
|
return $this->_includePathSet; |
|
67
|
|
|
} |
|
68
|
|
|
$this->_includePathSet = set_include_path(get_include_path() . PS . BP . DS . $path) !== false; |
|
69
|
|
|
} else { |
|
70
|
|
|
// every other call returns false as include path has already been set |
|
71
|
|
|
$this->_includePathSet = false; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $this->_includePathSet; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param array $customFakePath |
|
79
|
|
|
* |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function _getCustomFakePath(array $customFakePath = null) |
|
83
|
|
|
{ |
|
84
|
|
|
$path = array( |
|
85
|
|
|
'app', 'code', 'community', 'Zookal', 'Mock', 'Model', 'Mocks' |
|
86
|
|
|
); |
|
87
|
|
|
if (null !== $customFakePath) { |
|
88
|
|
|
$path = $customFakePath; |
|
89
|
|
|
} |
|
90
|
|
|
return implode(DS, $path); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
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.