| 148 |
lars |
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 padraic@php.net 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 |
'__debugInfo', ## mocking this makes it difficult to debug with xdebug
|
|
|
37 |
|
|
|
38 |
// below are reserved words in PHP
|
|
|
39 |
"__halt_compiler", "abstract", "and", "array", "as",
|
|
|
40 |
"break", "callable", "case", "catch", "class",
|
|
|
41 |
"clone", "const", "continue", "declare", "default",
|
|
|
42 |
"die", "do", "echo", "else", "elseif",
|
|
|
43 |
"empty", "enddeclare", "endfor", "endforeach", "endif",
|
|
|
44 |
"endswitch", "endwhile", "eval", "exit", "extends",
|
|
|
45 |
"final", "for", "foreach", "function", "global",
|
|
|
46 |
"goto", "if", "implements", "include", "include_once",
|
|
|
47 |
"instanceof", "insteadof", "interface", "isset", "list",
|
|
|
48 |
"namespace", "new", "or", "print", "private",
|
|
|
49 |
"protected", "public", "require", "require_once", "return",
|
|
|
50 |
"static", "switch", "throw", "trait", "try",
|
|
|
51 |
"unset", "use", "var", "while", "xor"
|
|
|
52 |
);
|
|
|
53 |
|
|
|
54 |
protected $php7SemiReservedKeywords = [
|
|
|
55 |
"callable", "class", "trait", "extends", "implements", "static", "abstract", "final",
|
|
|
56 |
"public", "protected", "private", "const", "enddeclare", "endfor", "endforeach", "endif",
|
|
|
57 |
"endwhile", "and", "global", "goto", "instanceof", "insteadof", "interface", "namespace", "new",
|
|
|
58 |
"or", "xor", "try", "use", "var", "exit", "list", "clone", "include", "include_once", "throw",
|
|
|
59 |
"array", "print", "echo", "require", "require_once", "return", "else", "elseif", "default",
|
|
|
60 |
"break", "continue", "switch", "yield", "function", "if", "endswitch", "finally", "for", "foreach",
|
|
|
61 |
"declare", "case", "do", "while", "as", "catch", "die", "self", "parent",
|
|
|
62 |
];
|
|
|
63 |
|
|
|
64 |
protected $whiteListedMethods = array();
|
|
|
65 |
protected $instanceMock = false;
|
|
|
66 |
protected $parameterOverrides = array();
|
|
|
67 |
|
|
|
68 |
protected $mockOriginalDestructor = false;
|
|
|
69 |
protected $targets = array();
|
|
|
70 |
|
|
|
71 |
protected $constantsMap = array();
|
|
|
72 |
|
|
|
73 |
public function __construct()
|
|
|
74 |
{
|
|
|
75 |
$this->blackListedMethods = array_diff($this->blackListedMethods, $this->php7SemiReservedKeywords);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
public function addTarget($target)
|
|
|
79 |
{
|
|
|
80 |
$this->targets[] = $target;
|
|
|
81 |
|
|
|
82 |
return $this;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public function addTargets($targets)
|
|
|
86 |
{
|
|
|
87 |
foreach ($targets as $target) {
|
|
|
88 |
$this->addTarget($target);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
return $this;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public function setName($name)
|
|
|
95 |
{
|
|
|
96 |
$this->name = $name;
|
|
|
97 |
return $this;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
public function addBlackListedMethod($blackListedMethod)
|
|
|
101 |
{
|
|
|
102 |
$this->blackListedMethods[] = $blackListedMethod;
|
|
|
103 |
return $this;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public function addBlackListedMethods(array $blackListedMethods)
|
|
|
107 |
{
|
|
|
108 |
foreach ($blackListedMethods as $method) {
|
|
|
109 |
$this->addBlackListedMethod($method);
|
|
|
110 |
}
|
|
|
111 |
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 |
public function setWhiteListedMethods(array $whiteListedMethods)
|
|
|
135 |
{
|
|
|
136 |
$this->whiteListedMethods = $whiteListedMethods;
|
|
|
137 |
return $this;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
public function setInstanceMock($instanceMock)
|
|
|
141 |
{
|
|
|
142 |
$this->instanceMock = (bool) $instanceMock;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
public function setParameterOverrides(array $overrides)
|
|
|
146 |
{
|
|
|
147 |
$this->parameterOverrides = $overrides;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
public function setMockOriginalDestructor($mockDestructor)
|
|
|
151 |
{
|
|
|
152 |
$this->mockOriginalDestructor = $mockDestructor;
|
|
|
153 |
return $this;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public function setConstantsMap(array $map)
|
|
|
157 |
{
|
|
|
158 |
$this->constantsMap = $map;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
public function getMockConfiguration()
|
|
|
162 |
{
|
|
|
163 |
return new MockConfiguration(
|
|
|
164 |
$this->targets,
|
|
|
165 |
$this->blackListedMethods,
|
|
|
166 |
$this->whiteListedMethods,
|
|
|
167 |
$this->name,
|
|
|
168 |
$this->instanceMock,
|
|
|
169 |
$this->parameterOverrides,
|
|
|
170 |
$this->mockOriginalDestructor,
|
|
|
171 |
$this->constantsMap
|
|
|
172 |
);
|
|
|
173 |
}
|
|
|
174 |
}
|