|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Mockery |
|
4
|
|
|
* |
|
5
|
|
|
* LICENSE |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the new BSD license that is bundled |
|
8
|
|
|
* with this package in the file LICENSE.txt. |
|
9
|
|
|
* It is also available through the world-wide-web at this URL: |
|
10
|
|
|
* http://github.com/padraic/mockery/blob/master/LICENSE |
|
11
|
|
|
* If you did not receive a copy of the license and are unable to |
|
12
|
|
|
* obtain it through the world-wide-web, please send an email |
|
13
|
|
|
* to [email protected] so we can send you a copy immediately. |
|
14
|
|
|
* |
|
15
|
|
|
* @category Mockery |
|
16
|
|
|
* @package Mockery |
|
17
|
|
|
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com) |
|
18
|
|
|
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Mockery; |
|
22
|
|
|
|
|
23
|
|
|
class Configuration |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Boolean assertion of whether we can mock methods which do not actually |
|
27
|
|
|
* exist for the given class or object (ignored for unreal mocks) |
|
28
|
|
|
* |
|
29
|
|
|
* @var bool |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $_allowMockingNonExistentMethod = true; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Boolean assertion of whether we ignore unnecessary mocking of methods, |
|
35
|
|
|
* i.e. when method expectations are made, set using a zeroOrMoreTimes() |
|
36
|
|
|
* constraint, and then never called. Essentially such expectations are |
|
37
|
|
|
* not required and are just taking up test space. |
|
38
|
|
|
* |
|
39
|
|
|
* @var bool |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $_allowMockingMethodsUnnecessarily = true; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Parameter map for use with PHP internal classes. |
|
45
|
|
|
* |
|
46
|
|
|
* @var array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $_internalClassParamMap = array(); |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Set boolean to allow/prevent mocking of non-existent methods |
|
52
|
|
|
* |
|
53
|
|
|
* @param bool |
|
54
|
|
|
*/ |
|
55
|
228 |
|
public function allowMockingNonExistentMethods($flag = true) |
|
56
|
|
|
{ |
|
57
|
228 |
|
$this->_allowMockingNonExistentMethod = (bool) $flag; |
|
58
|
228 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Return flag indicating whether mocking non-existent methods allowed |
|
62
|
|
|
* |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
423 |
|
public function mockingNonExistentMethodsAllowed() |
|
66
|
|
|
{ |
|
67
|
423 |
|
return $this->_allowMockingNonExistentMethod; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Set boolean to allow/prevent unnecessary mocking of methods |
|
72
|
|
|
* |
|
73
|
|
|
* @param bool |
|
74
|
|
|
*/ |
|
75
|
|
|
public function allowMockingMethodsUnnecessarily($flag = true) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->_allowMockingMethodsUnnecessarily = (bool) $flag; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Return flag indicating whether mocking non-existent methods allowed |
|
82
|
|
|
* |
|
83
|
|
|
* @return bool |
|
84
|
|
|
*/ |
|
85
|
|
|
public function mockingMethodsUnnecessarilyAllowed() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->_allowMockingMethodsUnnecessarily; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Set a parameter map (array of param signature strings) for the method |
|
92
|
|
|
* of an internal PHP class. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $class |
|
95
|
|
|
* @param string $method |
|
96
|
|
|
* @param array $map |
|
97
|
|
|
*/ |
|
98
|
3 |
|
public function setInternalClassMethodParamMap($class, $method, array $map) |
|
99
|
|
|
{ |
|
100
|
3 |
|
if (!isset($this->_internalClassParamMap[strtolower($class)])) { |
|
101
|
3 |
|
$this->_internalClassParamMap[strtolower($class)] = array(); |
|
102
|
3 |
|
} |
|
103
|
3 |
|
$this->_internalClassParamMap[strtolower($class)][strtolower($method)] = $map; |
|
104
|
3 |
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Remove all overriden parameter maps from internal PHP classes. |
|
108
|
|
|
*/ |
|
109
|
3 |
|
public function resetInternalClassMethodParamMaps() |
|
110
|
|
|
{ |
|
111
|
3 |
|
$this->_internalClassParamMap = array(); |
|
112
|
3 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get the parameter map of an internal PHP class method |
|
116
|
|
|
* |
|
117
|
|
|
* @return array |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getInternalClassMethodParamMap($class, $method) |
|
120
|
|
|
{ |
|
121
|
|
|
if (isset($this->_internalClassParamMap[strtolower($class)][strtolower($method)])) { |
|
122
|
|
|
return $this->_internalClassParamMap[strtolower($class)][strtolower($method)]; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
426 |
|
public function getInternalClassMethodParamMaps() |
|
127
|
|
|
{ |
|
128
|
426 |
|
return $this->_internalClassParamMap; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|