|
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\Generator; |
|
22
|
|
|
|
|
23
|
|
|
class MockConfigurationBuilder |
|
24
|
|
|
{ |
|
25
|
|
|
protected $name; |
|
26
|
|
|
protected $blackListedMethods = array( |
|
27
|
|
|
'__call', |
|
28
|
|
|
'__callStatic', |
|
29
|
|
|
'__clone', |
|
30
|
|
|
'__wakeup', |
|
31
|
|
|
'__set', |
|
32
|
|
|
'__get', |
|
33
|
|
|
'__toString', |
|
34
|
|
|
'__isset', |
|
35
|
|
|
'__destruct', |
|
36
|
|
|
|
|
37
|
|
|
// below are reserved words in PHP |
|
38
|
|
|
"__halt_compiler", "abstract", "and", "array", "as", |
|
39
|
|
|
"break", "callable", "case", "catch", "class", |
|
40
|
|
|
"clone", "const", "continue", "declare", "default", |
|
41
|
|
|
"die", "do", "echo", "else", "elseif", |
|
42
|
|
|
"empty", "enddeclare", "endfor", "endforeach", "endif", |
|
43
|
|
|
"endswitch", "endwhile", "eval", "exit", "extends", |
|
44
|
|
|
"final", "for", "foreach", "function", "global", |
|
45
|
|
|
"goto", "if", "implements", "include", "include_once", |
|
46
|
|
|
"instanceof", "insteadof", "interface", "isset", "list", |
|
47
|
|
|
"namespace", "new", "or", "print", "private", |
|
48
|
|
|
"protected", "public", "require", "require_once", "return", |
|
49
|
|
|
"static", "switch", "throw", "trait", "try", |
|
50
|
|
|
"unset", "use", "var", "while", "xor" |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
protected $php7SemiReservedKeywords = [ |
|
54
|
|
|
"callable", "class", "trait", "extends", "implements", "static", "abstract", "final", |
|
55
|
|
|
"public", "protected", "private", "const", "enddeclare", "endfor", "endforeach", "endif", |
|
56
|
|
|
"endwhile", "and", "global", "goto", "instanceof", "insteadof", "interface", "namespace", "new", |
|
57
|
|
|
"or", "xor", "try", "use", "var", "exit", "list", "clone", "include", "include_once", "throw", |
|
58
|
|
|
"array", "print", "echo", "require", "require_once", "return", "else", "elseif", "default", |
|
59
|
|
|
"break", "continue", "switch", "yield", "function", "if", "endswitch", "finally", "for", "foreach", |
|
60
|
|
|
"declare", "case", "do", "while", "as", "catch", "die", "self", "parent", |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
protected $whiteListedMethods = array(); |
|
64
|
|
|
protected $instanceMock = false; |
|
65
|
|
|
protected $parameterOverrides = array(); |
|
66
|
|
|
|
|
67
|
|
|
protected $mockOriginalDestructor = false; |
|
68
|
|
|
protected $targets = array(); |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
428 |
|
public function __construct() |
|
72
|
|
|
{ |
|
73
|
428 |
|
if (version_compare(PHP_VERSION, '7.0.0') >= 0) { |
|
74
|
|
|
$this->blackListedMethods = array_diff($this->blackListedMethods, $this->php7SemiReservedKeywords); |
|
75
|
|
|
} |
|
76
|
428 |
|
} |
|
77
|
|
|
|
|
78
|
399 |
|
public function addTarget($target) |
|
79
|
|
|
{ |
|
80
|
399 |
|
$this->targets[] = $target; |
|
81
|
|
|
|
|
82
|
399 |
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
6 |
|
public function addTargets($targets) |
|
86
|
|
|
{ |
|
87
|
6 |
|
foreach ($targets as $target) { |
|
88
|
6 |
|
$this->addTarget($target); |
|
89
|
6 |
|
} |
|
90
|
|
|
|
|
91
|
6 |
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
21 |
|
public function setName($name) |
|
95
|
|
|
{ |
|
96
|
21 |
|
$this->name = $name; |
|
97
|
21 |
|
return $this; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
12 |
|
public function addBlackListedMethod($blackListedMethod) |
|
101
|
|
|
{ |
|
102
|
12 |
|
$this->blackListedMethods[] = $blackListedMethod; |
|
103
|
12 |
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
424 |
|
public function addBlackListedMethods(array $blackListedMethods) |
|
107
|
|
|
{ |
|
108
|
424 |
|
foreach ($blackListedMethods as $method) { |
|
109
|
2 |
|
$this->addBlackListedMethod($method); |
|
110
|
424 |
|
} |
|
111
|
424 |
|
return $this; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function setBlackListedMethods(array $blackListedMethods) |
|
115
|
|
|
{ |
|
116
|
|
|
$this->blackListedMethods = $blackListedMethods; |
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function addWhiteListedMethod($whiteListedMethod) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->whiteListedMethods[] = $whiteListedMethod; |
|
123
|
|
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function addWhiteListedMethods(array $whiteListedMethods) |
|
127
|
|
|
{ |
|
128
|
|
|
foreach ($whiteListedMethods as $method) { |
|
129
|
|
|
$this->addWhiteListedMethod($method); |
|
130
|
|
|
} |
|
131
|
|
|
return $this; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
16 |
|
public function setWhiteListedMethods(array $whiteListedMethods) |
|
135
|
|
|
{ |
|
136
|
16 |
|
$this->whiteListedMethods = $whiteListedMethods; |
|
137
|
16 |
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
12 |
|
public function setInstanceMock($instanceMock) |
|
141
|
|
|
{ |
|
142
|
12 |
|
$this->instanceMock = (bool) $instanceMock; |
|
143
|
12 |
|
} |
|
144
|
|
|
|
|
145
|
426 |
|
public function setParameterOverrides(array $overrides) |
|
146
|
|
|
{ |
|
147
|
426 |
|
$this->parameterOverrides = $overrides; |
|
148
|
426 |
|
} |
|
149
|
|
|
|
|
150
|
414 |
|
public function setMockOriginalDestructor($mockDestructor) |
|
151
|
|
|
{ |
|
152
|
414 |
|
$this->mockOriginalDestructor = $mockDestructor; |
|
153
|
414 |
|
return $this; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
426 |
|
public function getMockConfiguration() |
|
157
|
|
|
{ |
|
158
|
426 |
|
return new MockConfiguration( |
|
159
|
426 |
|
$this->targets, |
|
160
|
426 |
|
$this->blackListedMethods, |
|
161
|
426 |
|
$this->whiteListedMethods, |
|
162
|
426 |
|
$this->name, |
|
163
|
426 |
|
$this->instanceMock, |
|
164
|
426 |
|
$this->parameterOverrides, |
|
165
|
426 |
|
$this->mockOriginalDestructor |
|
166
|
426 |
|
); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|