Completed
Push — master ( 52755b...6c4366 )
by smiley
02:13
created
vendor/phpunit/phpunit-mock-objects/src/InvocationMocker.php 2 patches
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -17,157 +17,157 @@
 block discarded – undo
17 17
  */
18 18
 class PHPUnit_Framework_MockObject_InvocationMocker implements PHPUnit_Framework_MockObject_Stub_MatcherCollection, PHPUnit_Framework_MockObject_Invokable, PHPUnit_Framework_MockObject_Builder_Namespace
19 19
 {
20
-    /**
21
-     * @var PHPUnit_Framework_MockObject_Matcher_Invocation[]
22
-     */
23
-    protected $matchers = [];
24
-
25
-    /**
26
-     * @var PHPUnit_Framework_MockObject_Builder_Match[]
27
-     */
28
-    protected $builderMap = [];
29
-
30
-    /**
31
-     * @var string[]
32
-     */
33
-    private $configurableMethods = [];
34
-
35
-    /**
36
-     * @param array $configurableMethods
37
-     */
38
-    public function __construct(array $configurableMethods)
39
-    {
40
-        $this->configurableMethods = $configurableMethods;
41
-    }
42
-
43
-    /**
44
-     * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
45
-     */
46
-    public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
47
-    {
48
-        $this->matchers[] = $matcher;
49
-    }
50
-
51
-    public function hasMatchers()
52
-    {
53
-        foreach ($this->matchers as $matcher) {
54
-            if ($matcher->hasMatchers()) {
55
-                return true;
56
-            }
57
-        }
58
-
59
-        return false;
60
-    }
61
-
62
-    /**
63
-     * @param mixed $id
64
-     *
65
-     * @return bool|null
66
-     */
67
-    public function lookupId($id)
68
-    {
69
-        if (isset($this->builderMap[$id])) {
70
-            return $this->builderMap[$id];
71
-        }
72
-
73
-        return;
74
-    }
75
-
76
-    /**
77
-     * @param mixed                                      $id
78
-     * @param PHPUnit_Framework_MockObject_Builder_Match $builder
79
-     *
80
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
81
-     */
82
-    public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder)
83
-    {
84
-        if (isset($this->builderMap[$id])) {
85
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
86
-                'Match builder with id <' . $id . '> is already registered.'
87
-            );
88
-        }
89
-
90
-        $this->builderMap[$id] = $builder;
91
-    }
92
-
93
-    /**
94
-     * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
95
-     *
96
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
97
-     */
98
-    public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
99
-    {
100
-        return new PHPUnit_Framework_MockObject_Builder_InvocationMocker(
101
-            $this,
102
-            $matcher,
103
-            $this->configurableMethods
104
-        );
105
-    }
106
-
107
-    /**
108
-     * @param PHPUnit_Framework_MockObject_Invocation $invocation
109
-     *
110
-     * @return mixed
111
-     *
112
-     * @throws Exception
113
-     */
114
-    public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
115
-    {
116
-        $exception      = null;
117
-        $hasReturnValue = false;
118
-        $returnValue    = null;
119
-
120
-        foreach ($this->matchers as $match) {
121
-            try {
122
-                if ($match->matches($invocation)) {
123
-                    $value = $match->invoked($invocation);
124
-
125
-                    if (!$hasReturnValue) {
126
-                        $returnValue    = $value;
127
-                        $hasReturnValue = true;
128
-                    }
129
-                }
130
-            } catch (Exception $e) {
131
-                $exception = $e;
132
-            }
133
-        }
134
-
135
-        if ($exception !== null) {
136
-            throw $exception;
137
-        }
138
-
139
-        if ($hasReturnValue) {
140
-            return $returnValue;
141
-        } elseif (strtolower($invocation->methodName) == '__tostring') {
142
-            return '';
143
-        }
144
-
145
-        return $invocation->generateReturnValue();
146
-    }
147
-
148
-    /**
149
-     * @param PHPUnit_Framework_MockObject_Invocation $invocation
150
-     *
151
-     * @return bool
152
-     */
153
-    public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
154
-    {
155
-        foreach ($this->matchers as $matcher) {
156
-            if (!$matcher->matches($invocation)) {
157
-                return false;
158
-            }
159
-        }
160
-
161
-        return true;
162
-    }
163
-
164
-    /**
165
-     * @return bool
166
-     */
167
-    public function verify()
168
-    {
169
-        foreach ($this->matchers as $matcher) {
170
-            $matcher->verify();
171
-        }
172
-    }
20
+	/**
21
+	 * @var PHPUnit_Framework_MockObject_Matcher_Invocation[]
22
+	 */
23
+	protected $matchers = [];
24
+
25
+	/**
26
+	 * @var PHPUnit_Framework_MockObject_Builder_Match[]
27
+	 */
28
+	protected $builderMap = [];
29
+
30
+	/**
31
+	 * @var string[]
32
+	 */
33
+	private $configurableMethods = [];
34
+
35
+	/**
36
+	 * @param array $configurableMethods
37
+	 */
38
+	public function __construct(array $configurableMethods)
39
+	{
40
+		$this->configurableMethods = $configurableMethods;
41
+	}
42
+
43
+	/**
44
+	 * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
45
+	 */
46
+	public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
47
+	{
48
+		$this->matchers[] = $matcher;
49
+	}
50
+
51
+	public function hasMatchers()
52
+	{
53
+		foreach ($this->matchers as $matcher) {
54
+			if ($matcher->hasMatchers()) {
55
+				return true;
56
+			}
57
+		}
58
+
59
+		return false;
60
+	}
61
+
62
+	/**
63
+	 * @param mixed $id
64
+	 *
65
+	 * @return bool|null
66
+	 */
67
+	public function lookupId($id)
68
+	{
69
+		if (isset($this->builderMap[$id])) {
70
+			return $this->builderMap[$id];
71
+		}
72
+
73
+		return;
74
+	}
75
+
76
+	/**
77
+	 * @param mixed                                      $id
78
+	 * @param PHPUnit_Framework_MockObject_Builder_Match $builder
79
+	 *
80
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
81
+	 */
82
+	public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder)
83
+	{
84
+		if (isset($this->builderMap[$id])) {
85
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
86
+				'Match builder with id <' . $id . '> is already registered.'
87
+			);
88
+		}
89
+
90
+		$this->builderMap[$id] = $builder;
91
+	}
92
+
93
+	/**
94
+	 * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
95
+	 *
96
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
97
+	 */
98
+	public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
99
+	{
100
+		return new PHPUnit_Framework_MockObject_Builder_InvocationMocker(
101
+			$this,
102
+			$matcher,
103
+			$this->configurableMethods
104
+		);
105
+	}
106
+
107
+	/**
108
+	 * @param PHPUnit_Framework_MockObject_Invocation $invocation
109
+	 *
110
+	 * @return mixed
111
+	 *
112
+	 * @throws Exception
113
+	 */
114
+	public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
115
+	{
116
+		$exception      = null;
117
+		$hasReturnValue = false;
118
+		$returnValue    = null;
119
+
120
+		foreach ($this->matchers as $match) {
121
+			try {
122
+				if ($match->matches($invocation)) {
123
+					$value = $match->invoked($invocation);
124
+
125
+					if (!$hasReturnValue) {
126
+						$returnValue    = $value;
127
+						$hasReturnValue = true;
128
+					}
129
+				}
130
+			} catch (Exception $e) {
131
+				$exception = $e;
132
+			}
133
+		}
134
+
135
+		if ($exception !== null) {
136
+			throw $exception;
137
+		}
138
+
139
+		if ($hasReturnValue) {
140
+			return $returnValue;
141
+		} elseif (strtolower($invocation->methodName) == '__tostring') {
142
+			return '';
143
+		}
144
+
145
+		return $invocation->generateReturnValue();
146
+	}
147
+
148
+	/**
149
+	 * @param PHPUnit_Framework_MockObject_Invocation $invocation
150
+	 *
151
+	 * @return bool
152
+	 */
153
+	public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
154
+	{
155
+		foreach ($this->matchers as $matcher) {
156
+			if (!$matcher->matches($invocation)) {
157
+				return false;
158
+			}
159
+		}
160
+
161
+		return true;
162
+	}
163
+
164
+	/**
165
+	 * @return bool
166
+	 */
167
+	public function verify()
168
+	{
169
+		foreach ($this->matchers as $matcher) {
170
+			$matcher->verify();
171
+		}
172
+	}
173 173
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@
 block discarded – undo
83 83
     {
84 84
         if (isset($this->builderMap[$id])) {
85 85
             throw new PHPUnit_Framework_MockObject_RuntimeException(
86
-                'Match builder with id <' . $id . '> is already registered.'
86
+                'Match builder with id <'.$id.'> is already registered.'
87 87
             );
88 88
         }
89 89
 
Please login to merge, or discard this patch.
vendor/phpunit/phpunit-mock-objects/src/Matcher.php 2 patches
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -22,251 +22,251 @@
 block discarded – undo
22 22
  */
23 23
 class PHPUnit_Framework_MockObject_Matcher implements PHPUnit_Framework_MockObject_Matcher_Invocation
24 24
 {
25
-    /**
26
-     * @var PHPUnit_Framework_MockObject_Matcher_Invocation
27
-     */
28
-    public $invocationMatcher;
29
-
30
-    /**
31
-     * @var mixed
32
-     */
33
-    public $afterMatchBuilderId = null;
34
-
35
-    /**
36
-     * @var bool
37
-     */
38
-    public $afterMatchBuilderIsInvoked = false;
39
-
40
-    /**
41
-     * @var PHPUnit_Framework_MockObject_Matcher_MethodName
42
-     */
43
-    public $methodNameMatcher = null;
44
-
45
-    /**
46
-     * @var PHPUnit_Framework_MockObject_Matcher_Parameters
47
-     */
48
-    public $parametersMatcher = null;
49
-
50
-    /**
51
-     * @var PHPUnit_Framework_MockObject_Stub
52
-     */
53
-    public $stub = null;
54
-
55
-    /**
56
-     * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher
57
-     */
58
-    public function __construct(PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher)
59
-    {
60
-        $this->invocationMatcher = $invocationMatcher;
61
-    }
62
-
63
-    /**
64
-     * @return string
65
-     */
66
-    public function toString()
67
-    {
68
-        $list = [];
69
-
70
-        if ($this->invocationMatcher !== null) {
71
-            $list[] = $this->invocationMatcher->toString();
72
-        }
73
-
74
-        if ($this->methodNameMatcher !== null) {
75
-            $list[] = 'where ' . $this->methodNameMatcher->toString();
76
-        }
77
-
78
-        if ($this->parametersMatcher !== null) {
79
-            $list[] = 'and ' . $this->parametersMatcher->toString();
80
-        }
81
-
82
-        if ($this->afterMatchBuilderId !== null) {
83
-            $list[] = 'after ' . $this->afterMatchBuilderId;
84
-        }
85
-
86
-        if ($this->stub !== null) {
87
-            $list[] = 'will ' . $this->stub->toString();
88
-        }
89
-
90
-        return implode(' ', $list);
91
-    }
92
-
93
-    /**
94
-     * @param PHPUnit_Framework_MockObject_Invocation $invocation
95
-     *
96
-     * @return mixed
97
-     */
98
-    public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation)
99
-    {
100
-        if ($this->invocationMatcher === null) {
101
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
102
-                'No invocation matcher is set'
103
-            );
104
-        }
105
-
106
-        if ($this->methodNameMatcher === null) {
107
-            throw new PHPUnit_Framework_MockObject_RuntimeException('No method matcher is set');
108
-        }
109
-
110
-        if ($this->afterMatchBuilderId !== null) {
111
-            $builder = $invocation->object
112
-                                  ->__phpunit_getInvocationMocker()
113
-                                  ->lookupId($this->afterMatchBuilderId);
114
-
115
-            if (!$builder) {
116
-                throw new PHPUnit_Framework_MockObject_RuntimeException(
117
-                    sprintf(
118
-                        'No builder found for match builder identification <%s>',
119
-                        $this->afterMatchBuilderId
120
-                    )
121
-                );
122
-            }
123
-
124
-            $matcher = $builder->getMatcher();
125
-
126
-            if ($matcher && $matcher->invocationMatcher->hasBeenInvoked()) {
127
-                $this->afterMatchBuilderIsInvoked = true;
128
-            }
129
-        }
130
-
131
-        $this->invocationMatcher->invoked($invocation);
132
-
133
-        try {
134
-            if ($this->parametersMatcher !== null &&
135
-                !$this->parametersMatcher->matches($invocation)) {
136
-                $this->parametersMatcher->verify();
137
-            }
138
-        } catch (ExpectationFailedException $e) {
139
-            throw new ExpectationFailedException(
140
-                sprintf(
141
-                    "Expectation failed for %s when %s\n%s",
142
-                    $this->methodNameMatcher->toString(),
143
-                    $this->invocationMatcher->toString(),
144
-                    $e->getMessage()
145
-                ),
146
-                $e->getComparisonFailure()
147
-            );
148
-        }
149
-
150
-        if ($this->stub) {
151
-            return $this->stub->invoke($invocation);
152
-        }
153
-
154
-        return $invocation->generateReturnValue();
155
-    }
156
-
157
-    /**
158
-     * @param PHPUnit_Framework_MockObject_Invocation $invocation
159
-     *
160
-     * @return bool
161
-     */
162
-    public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
163
-    {
164
-        if ($this->afterMatchBuilderId !== null) {
165
-            $builder = $invocation->object
166
-                                  ->__phpunit_getInvocationMocker()
167
-                                  ->lookupId($this->afterMatchBuilderId);
168
-
169
-            if (!$builder) {
170
-                throw new PHPUnit_Framework_MockObject_RuntimeException(
171
-                    sprintf(
172
-                        'No builder found for match builder identification <%s>',
173
-                        $this->afterMatchBuilderId
174
-                    )
175
-                );
176
-            }
177
-
178
-            $matcher = $builder->getMatcher();
179
-
180
-            if (!$matcher) {
181
-                return false;
182
-            }
183
-
184
-            if (!$matcher->invocationMatcher->hasBeenInvoked()) {
185
-                return false;
186
-            }
187
-        }
188
-
189
-        if ($this->invocationMatcher === null) {
190
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
191
-                'No invocation matcher is set'
192
-            );
193
-        }
194
-
195
-        if ($this->methodNameMatcher === null) {
196
-            throw new PHPUnit_Framework_MockObject_RuntimeException('No method matcher is set');
197
-        }
198
-
199
-        if (!$this->invocationMatcher->matches($invocation)) {
200
-            return false;
201
-        }
202
-
203
-        try {
204
-            if (!$this->methodNameMatcher->matches($invocation)) {
205
-                return false;
206
-            }
207
-        } catch (ExpectationFailedException $e) {
208
-            throw new ExpectationFailedException(
209
-                sprintf(
210
-                    "Expectation failed for %s when %s\n%s",
211
-                    $this->methodNameMatcher->toString(),
212
-                    $this->invocationMatcher->toString(),
213
-                    $e->getMessage()
214
-                ),
215
-                $e->getComparisonFailure()
216
-            );
217
-        }
218
-
219
-        return true;
220
-    }
221
-
222
-    /**
223
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
224
-     * @throws ExpectationFailedException
225
-     */
226
-    public function verify()
227
-    {
228
-        if ($this->invocationMatcher === null) {
229
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
230
-                'No invocation matcher is set'
231
-            );
232
-        }
233
-
234
-        if ($this->methodNameMatcher === null) {
235
-            throw new PHPUnit_Framework_MockObject_RuntimeException('No method matcher is set');
236
-        }
237
-
238
-        try {
239
-            $this->invocationMatcher->verify();
240
-
241
-            if ($this->parametersMatcher === null) {
242
-                $this->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters;
243
-            }
244
-
245
-            $invocationIsAny   = $this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
246
-            $invocationIsNever = $this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_InvokedCount && $this->invocationMatcher->isNever();
247
-
248
-            if (!$invocationIsAny && !$invocationIsNever) {
249
-                $this->parametersMatcher->verify();
250
-            }
251
-        } catch (ExpectationFailedException $e) {
252
-            throw new ExpectationFailedException(
253
-                sprintf(
254
-                    "Expectation failed for %s when %s.\n%s",
255
-                    $this->methodNameMatcher->toString(),
256
-                    $this->invocationMatcher->toString(),
257
-                    TestFailure::exceptionToString($e)
258
-                )
259
-            );
260
-        }
261
-    }
262
-
263
-    public function hasMatchers()
264
-    {
265
-        if ($this->invocationMatcher !== null &&
266
-            !$this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount) {
267
-            return true;
268
-        }
269
-
270
-        return false;
271
-    }
25
+	/**
26
+	 * @var PHPUnit_Framework_MockObject_Matcher_Invocation
27
+	 */
28
+	public $invocationMatcher;
29
+
30
+	/**
31
+	 * @var mixed
32
+	 */
33
+	public $afterMatchBuilderId = null;
34
+
35
+	/**
36
+	 * @var bool
37
+	 */
38
+	public $afterMatchBuilderIsInvoked = false;
39
+
40
+	/**
41
+	 * @var PHPUnit_Framework_MockObject_Matcher_MethodName
42
+	 */
43
+	public $methodNameMatcher = null;
44
+
45
+	/**
46
+	 * @var PHPUnit_Framework_MockObject_Matcher_Parameters
47
+	 */
48
+	public $parametersMatcher = null;
49
+
50
+	/**
51
+	 * @var PHPUnit_Framework_MockObject_Stub
52
+	 */
53
+	public $stub = null;
54
+
55
+	/**
56
+	 * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher
57
+	 */
58
+	public function __construct(PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher)
59
+	{
60
+		$this->invocationMatcher = $invocationMatcher;
61
+	}
62
+
63
+	/**
64
+	 * @return string
65
+	 */
66
+	public function toString()
67
+	{
68
+		$list = [];
69
+
70
+		if ($this->invocationMatcher !== null) {
71
+			$list[] = $this->invocationMatcher->toString();
72
+		}
73
+
74
+		if ($this->methodNameMatcher !== null) {
75
+			$list[] = 'where ' . $this->methodNameMatcher->toString();
76
+		}
77
+
78
+		if ($this->parametersMatcher !== null) {
79
+			$list[] = 'and ' . $this->parametersMatcher->toString();
80
+		}
81
+
82
+		if ($this->afterMatchBuilderId !== null) {
83
+			$list[] = 'after ' . $this->afterMatchBuilderId;
84
+		}
85
+
86
+		if ($this->stub !== null) {
87
+			$list[] = 'will ' . $this->stub->toString();
88
+		}
89
+
90
+		return implode(' ', $list);
91
+	}
92
+
93
+	/**
94
+	 * @param PHPUnit_Framework_MockObject_Invocation $invocation
95
+	 *
96
+	 * @return mixed
97
+	 */
98
+	public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation)
99
+	{
100
+		if ($this->invocationMatcher === null) {
101
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
102
+				'No invocation matcher is set'
103
+			);
104
+		}
105
+
106
+		if ($this->methodNameMatcher === null) {
107
+			throw new PHPUnit_Framework_MockObject_RuntimeException('No method matcher is set');
108
+		}
109
+
110
+		if ($this->afterMatchBuilderId !== null) {
111
+			$builder = $invocation->object
112
+								  ->__phpunit_getInvocationMocker()
113
+								  ->lookupId($this->afterMatchBuilderId);
114
+
115
+			if (!$builder) {
116
+				throw new PHPUnit_Framework_MockObject_RuntimeException(
117
+					sprintf(
118
+						'No builder found for match builder identification <%s>',
119
+						$this->afterMatchBuilderId
120
+					)
121
+				);
122
+			}
123
+
124
+			$matcher = $builder->getMatcher();
125
+
126
+			if ($matcher && $matcher->invocationMatcher->hasBeenInvoked()) {
127
+				$this->afterMatchBuilderIsInvoked = true;
128
+			}
129
+		}
130
+
131
+		$this->invocationMatcher->invoked($invocation);
132
+
133
+		try {
134
+			if ($this->parametersMatcher !== null &&
135
+				!$this->parametersMatcher->matches($invocation)) {
136
+				$this->parametersMatcher->verify();
137
+			}
138
+		} catch (ExpectationFailedException $e) {
139
+			throw new ExpectationFailedException(
140
+				sprintf(
141
+					"Expectation failed for %s when %s\n%s",
142
+					$this->methodNameMatcher->toString(),
143
+					$this->invocationMatcher->toString(),
144
+					$e->getMessage()
145
+				),
146
+				$e->getComparisonFailure()
147
+			);
148
+		}
149
+
150
+		if ($this->stub) {
151
+			return $this->stub->invoke($invocation);
152
+		}
153
+
154
+		return $invocation->generateReturnValue();
155
+	}
156
+
157
+	/**
158
+	 * @param PHPUnit_Framework_MockObject_Invocation $invocation
159
+	 *
160
+	 * @return bool
161
+	 */
162
+	public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
163
+	{
164
+		if ($this->afterMatchBuilderId !== null) {
165
+			$builder = $invocation->object
166
+								  ->__phpunit_getInvocationMocker()
167
+								  ->lookupId($this->afterMatchBuilderId);
168
+
169
+			if (!$builder) {
170
+				throw new PHPUnit_Framework_MockObject_RuntimeException(
171
+					sprintf(
172
+						'No builder found for match builder identification <%s>',
173
+						$this->afterMatchBuilderId
174
+					)
175
+				);
176
+			}
177
+
178
+			$matcher = $builder->getMatcher();
179
+
180
+			if (!$matcher) {
181
+				return false;
182
+			}
183
+
184
+			if (!$matcher->invocationMatcher->hasBeenInvoked()) {
185
+				return false;
186
+			}
187
+		}
188
+
189
+		if ($this->invocationMatcher === null) {
190
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
191
+				'No invocation matcher is set'
192
+			);
193
+		}
194
+
195
+		if ($this->methodNameMatcher === null) {
196
+			throw new PHPUnit_Framework_MockObject_RuntimeException('No method matcher is set');
197
+		}
198
+
199
+		if (!$this->invocationMatcher->matches($invocation)) {
200
+			return false;
201
+		}
202
+
203
+		try {
204
+			if (!$this->methodNameMatcher->matches($invocation)) {
205
+				return false;
206
+			}
207
+		} catch (ExpectationFailedException $e) {
208
+			throw new ExpectationFailedException(
209
+				sprintf(
210
+					"Expectation failed for %s when %s\n%s",
211
+					$this->methodNameMatcher->toString(),
212
+					$this->invocationMatcher->toString(),
213
+					$e->getMessage()
214
+				),
215
+				$e->getComparisonFailure()
216
+			);
217
+		}
218
+
219
+		return true;
220
+	}
221
+
222
+	/**
223
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
224
+	 * @throws ExpectationFailedException
225
+	 */
226
+	public function verify()
227
+	{
228
+		if ($this->invocationMatcher === null) {
229
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
230
+				'No invocation matcher is set'
231
+			);
232
+		}
233
+
234
+		if ($this->methodNameMatcher === null) {
235
+			throw new PHPUnit_Framework_MockObject_RuntimeException('No method matcher is set');
236
+		}
237
+
238
+		try {
239
+			$this->invocationMatcher->verify();
240
+
241
+			if ($this->parametersMatcher === null) {
242
+				$this->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters;
243
+			}
244
+
245
+			$invocationIsAny   = $this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
246
+			$invocationIsNever = $this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_InvokedCount && $this->invocationMatcher->isNever();
247
+
248
+			if (!$invocationIsAny && !$invocationIsNever) {
249
+				$this->parametersMatcher->verify();
250
+			}
251
+		} catch (ExpectationFailedException $e) {
252
+			throw new ExpectationFailedException(
253
+				sprintf(
254
+					"Expectation failed for %s when %s.\n%s",
255
+					$this->methodNameMatcher->toString(),
256
+					$this->invocationMatcher->toString(),
257
+					TestFailure::exceptionToString($e)
258
+				)
259
+			);
260
+		}
261
+	}
262
+
263
+	public function hasMatchers()
264
+	{
265
+		if ($this->invocationMatcher !== null &&
266
+			!$this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount) {
267
+			return true;
268
+		}
269
+
270
+		return false;
271
+	}
272 272
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -72,19 +72,19 @@
 block discarded – undo
72 72
         }
73 73
 
74 74
         if ($this->methodNameMatcher !== null) {
75
-            $list[] = 'where ' . $this->methodNameMatcher->toString();
75
+            $list[] = 'where '.$this->methodNameMatcher->toString();
76 76
         }
77 77
 
78 78
         if ($this->parametersMatcher !== null) {
79
-            $list[] = 'and ' . $this->parametersMatcher->toString();
79
+            $list[] = 'and '.$this->parametersMatcher->toString();
80 80
         }
81 81
 
82 82
         if ($this->afterMatchBuilderId !== null) {
83
-            $list[] = 'after ' . $this->afterMatchBuilderId;
83
+            $list[] = 'after '.$this->afterMatchBuilderId;
84 84
         }
85 85
 
86 86
         if ($this->stub !== null) {
87
-            $list[] = 'will ' . $this->stub->toString();
87
+            $list[] = 'will '.$this->stub->toString();
88 88
         }
89 89
 
90 90
         return implode(' ', $list);
Please login to merge, or discard this patch.
vendor/phpunit/phpunit-mock-objects/src/Generator.php 2 patches
Indentation   +1142 added lines, -1142 removed lines patch added patch discarded remove patch
@@ -18,1148 +18,1148 @@
 block discarded – undo
18 18
  */
19 19
 class PHPUnit_Framework_MockObject_Generator
20 20
 {
21
-    /**
22
-     * @var array
23
-     */
24
-    private static $cache = [];
25
-
26
-    /**
27
-     * @var Text_Template[]
28
-     */
29
-    private static $templates = [];
30
-
31
-    /**
32
-     * @var array
33
-     */
34
-    private $blacklistedMethodNames = [
35
-        '__CLASS__'       => true,
36
-        '__DIR__'         => true,
37
-        '__FILE__'        => true,
38
-        '__FUNCTION__'    => true,
39
-        '__LINE__'        => true,
40
-        '__METHOD__'      => true,
41
-        '__NAMESPACE__'   => true,
42
-        '__TRAIT__'       => true,
43
-        '__clone'         => true,
44
-        '__halt_compiler' => true,
45
-    ];
46
-
47
-    /**
48
-     * Returns a mock object for the specified class.
49
-     *
50
-     * @param string|string[] $type
51
-     * @param array           $methods
52
-     * @param array           $arguments
53
-     * @param string          $mockClassName
54
-     * @param bool            $callOriginalConstructor
55
-     * @param bool            $callOriginalClone
56
-     * @param bool            $callAutoload
57
-     * @param bool            $cloneArguments
58
-     * @param bool            $callOriginalMethods
59
-     * @param object          $proxyTarget
60
-     * @param bool            $allowMockingUnknownTypes
61
-     *
62
-     * @return PHPUnit_Framework_MockObject_MockObject
63
-     *
64
-     * @throws InvalidArgumentException
65
-     * @throws PHPUnit\Framework\Exception
66
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
67
-     */
68
-    public function getMock($type, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = true, $callOriginalMethods = false, $proxyTarget = null, $allowMockingUnknownTypes = true)
69
-    {
70
-        if (!is_array($type) && !is_string($type)) {
71
-            throw InvalidArgumentHelper::factory(1, 'array or string');
72
-        }
73
-
74
-        if (!is_string($mockClassName)) {
75
-            throw InvalidArgumentHelper::factory(4, 'string');
76
-        }
77
-
78
-        if (!is_array($methods) && !is_null($methods)) {
79
-            throw InvalidArgumentHelper::factory(2, 'array', $methods);
80
-        }
81
-
82
-        if ($type === 'Traversable' || $type === '\\Traversable') {
83
-            $type = 'Iterator';
84
-        }
85
-
86
-        if (is_array($type)) {
87
-            $type = array_unique(
88
-                array_map(
89
-                    function ($type) {
90
-                        if ($type === 'Traversable' ||
91
-                            $type === '\\Traversable' ||
92
-                            $type === '\\Iterator') {
93
-                            return 'Iterator';
94
-                        }
95
-
96
-                        return $type;
97
-                    },
98
-                    $type
99
-                )
100
-            );
101
-        }
102
-
103
-        if (!$allowMockingUnknownTypes) {
104
-            if (is_array($type)) {
105
-                foreach ($type as $_type) {
106
-                    if (!class_exists($_type, $callAutoload) &&
107
-                        !interface_exists($_type, $callAutoload)) {
108
-                        throw new PHPUnit_Framework_MockObject_RuntimeException(
109
-                            sprintf(
110
-                                'Cannot stub or mock class or interface "%s" which does not exist',
111
-                                $_type
112
-                            )
113
-                        );
114
-                    }
115
-                }
116
-            } else {
117
-                if (!class_exists($type, $callAutoload) &&
118
-                    !interface_exists($type, $callAutoload)
119
-                ) {
120
-                    throw new PHPUnit_Framework_MockObject_RuntimeException(
121
-                        sprintf(
122
-                            'Cannot stub or mock class or interface "%s" which does not exist',
123
-                            $type
124
-                        )
125
-                    );
126
-                }
127
-            }
128
-        }
129
-
130
-        if (null !== $methods) {
131
-            foreach ($methods as $method) {
132
-                if (!preg_match('~[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*~', $method)) {
133
-                    throw new PHPUnit_Framework_MockObject_RuntimeException(
134
-                        sprintf(
135
-                            'Cannot stub or mock method with invalid name "%s"',
136
-                            $method
137
-                        )
138
-                    );
139
-                }
140
-            }
141
-
142
-            if ($methods != array_unique($methods)) {
143
-                throw new PHPUnit_Framework_MockObject_RuntimeException(
144
-                    sprintf(
145
-                        'Cannot stub or mock using a method list that contains duplicates: "%s" (duplicate: "%s")',
146
-                        implode(', ', $methods),
147
-                        implode(', ', array_unique(array_diff_assoc($methods, array_unique($methods))))
148
-                    )
149
-                );
150
-            }
151
-        }
152
-
153
-        if ($mockClassName != '' && class_exists($mockClassName, false)) {
154
-            $reflect = new ReflectionClass($mockClassName);
155
-
156
-            if (!$reflect->implementsInterface('PHPUnit_Framework_MockObject_MockObject')) {
157
-                throw new PHPUnit_Framework_MockObject_RuntimeException(
158
-                    sprintf(
159
-                        'Class "%s" already exists.',
160
-                        $mockClassName
161
-                    )
162
-                );
163
-            }
164
-        }
165
-
166
-        if ($callOriginalConstructor === false && $callOriginalMethods === true) {
167
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
168
-                'Proxying to original methods requires invoking the original constructor'
169
-            );
170
-        }
171
-
172
-        $mock = $this->generate(
173
-            $type,
174
-            $methods,
175
-            $mockClassName,
176
-            $callOriginalClone,
177
-            $callAutoload,
178
-            $cloneArguments,
179
-            $callOriginalMethods
180
-        );
181
-
182
-        return $this->getObject(
183
-            $mock['code'],
184
-            $mock['mockClassName'],
185
-            $type,
186
-            $callOriginalConstructor,
187
-            $callAutoload,
188
-            $arguments,
189
-            $callOriginalMethods,
190
-            $proxyTarget
191
-        );
192
-    }
193
-
194
-    /**
195
-     * @param string       $code
196
-     * @param string       $className
197
-     * @param array|string $type
198
-     * @param bool         $callOriginalConstructor
199
-     * @param bool         $callAutoload
200
-     * @param array        $arguments
201
-     * @param bool         $callOriginalMethods
202
-     * @param object       $proxyTarget
203
-     *
204
-     * @return PHPUnit_Framework_MockObject_MockObject
205
-     *
206
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
207
-     */
208
-    private function getObject($code, $className, $type = '', $callOriginalConstructor = false, $callAutoload = false, array $arguments = [], $callOriginalMethods = false, $proxyTarget = null)
209
-    {
210
-        $this->evalClass($code, $className);
211
-
212
-        if ($callOriginalConstructor &&
213
-            is_string($type) &&
214
-            !interface_exists($type, $callAutoload)) {
215
-            if (count($arguments) == 0) {
216
-                $object = new $className;
217
-            } else {
218
-                $class  = new ReflectionClass($className);
219
-                $object = $class->newInstanceArgs($arguments);
220
-            }
221
-        } else {
222
-            try {
223
-                $instantiator = new Instantiator;
224
-                $object       = $instantiator->instantiate($className);
225
-            } catch (InstantiatorUnexpectedValueException $exception) {
226
-                if ($exception->getPrevious()) {
227
-                    $exception = $exception->getPrevious();
228
-                }
229
-
230
-                throw new PHPUnit_Framework_MockObject_RuntimeException(
231
-                    $exception->getMessage()
232
-                );
233
-            } catch (InstantiatorInvalidArgumentException $exception) {
234
-                throw new PHPUnit_Framework_MockObject_RuntimeException(
235
-                    $exception->getMessage()
236
-                );
237
-            }
238
-        }
239
-
240
-        if ($callOriginalMethods) {
241
-            if (!is_object($proxyTarget)) {
242
-                if (count($arguments) == 0) {
243
-                    $proxyTarget = new $type;
244
-                } else {
245
-                    $class       = new ReflectionClass($type);
246
-                    $proxyTarget = $class->newInstanceArgs($arguments);
247
-                }
248
-            }
249
-
250
-            $object->__phpunit_setOriginalObject($proxyTarget);
251
-        }
252
-
253
-        return $object;
254
-    }
255
-
256
-    /**
257
-     * @param string $code
258
-     * @param string $className
259
-     */
260
-    private function evalClass($code, $className)
261
-    {
262
-        if (!class_exists($className, false)) {
263
-            eval($code);
264
-        }
265
-    }
266
-
267
-    /**
268
-     * Returns a mock object for the specified abstract class with all abstract
269
-     * methods of the class mocked. Concrete methods to mock can be specified with
270
-     * the last parameter
271
-     *
272
-     * @param string $originalClassName
273
-     * @param array  $arguments
274
-     * @param string $mockClassName
275
-     * @param bool   $callOriginalConstructor
276
-     * @param bool   $callOriginalClone
277
-     * @param bool   $callAutoload
278
-     * @param array  $mockedMethods
279
-     * @param bool   $cloneArguments
280
-     *
281
-     * @return PHPUnit_Framework_MockObject_MockObject
282
-     *
283
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
284
-     * @throws PHPUnit\Framework\Exception
285
-     */
286
-    public function getMockForAbstractClass($originalClassName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = true)
287
-    {
288
-        if (!is_string($originalClassName)) {
289
-            throw InvalidArgumentHelper::factory(1, 'string');
290
-        }
291
-
292
-        if (!is_string($mockClassName)) {
293
-            throw InvalidArgumentHelper::factory(3, 'string');
294
-        }
295
-
296
-        if (class_exists($originalClassName, $callAutoload) ||
297
-            interface_exists($originalClassName, $callAutoload)) {
298
-            $reflector = new ReflectionClass($originalClassName);
299
-            $methods   = $mockedMethods;
300
-
301
-            foreach ($reflector->getMethods() as $method) {
302
-                if ($method->isAbstract() && !in_array($method->getName(), $methods)) {
303
-                    $methods[] = $method->getName();
304
-                }
305
-            }
306
-
307
-            if (empty($methods)) {
308
-                $methods = null;
309
-            }
310
-
311
-            return $this->getMock(
312
-                $originalClassName,
313
-                $methods,
314
-                $arguments,
315
-                $mockClassName,
316
-                $callOriginalConstructor,
317
-                $callOriginalClone,
318
-                $callAutoload,
319
-                $cloneArguments
320
-            );
321
-        }
322
-
323
-        throw new PHPUnit_Framework_MockObject_RuntimeException(
324
-            sprintf('Class "%s" does not exist.', $originalClassName)
325
-        );
326
-    }
327
-
328
-    /**
329
-     * Returns a mock object for the specified trait with all abstract methods
330
-     * of the trait mocked. Concrete methods to mock can be specified with the
331
-     * `$mockedMethods` parameter.
332
-     *
333
-     * @param string $traitName
334
-     * @param array  $arguments
335
-     * @param string $mockClassName
336
-     * @param bool   $callOriginalConstructor
337
-     * @param bool   $callOriginalClone
338
-     * @param bool   $callAutoload
339
-     * @param array  $mockedMethods
340
-     * @param bool   $cloneArguments
341
-     *
342
-     * @return PHPUnit_Framework_MockObject_MockObject
343
-     *
344
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
345
-     * @throws PHPUnit\Framework\Exception
346
-     */
347
-    public function getMockForTrait($traitName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = true)
348
-    {
349
-        if (!is_string($traitName)) {
350
-            throw InvalidArgumentHelper::factory(1, 'string');
351
-        }
352
-
353
-        if (!is_string($mockClassName)) {
354
-            throw InvalidArgumentHelper::factory(3, 'string');
355
-        }
356
-
357
-        if (!trait_exists($traitName, $callAutoload)) {
358
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
359
-                sprintf(
360
-                    'Trait "%s" does not exist.',
361
-                    $traitName
362
-                )
363
-            );
364
-        }
365
-
366
-        $className = $this->generateClassName(
367
-            $traitName,
368
-            '',
369
-            'Trait_'
370
-        );
371
-
372
-        $classTemplate = $this->getTemplate('trait_class.tpl');
373
-
374
-        $classTemplate->setVar(
375
-            [
376
-                'prologue'   => 'abstract ',
377
-                'class_name' => $className['className'],
378
-                'trait_name' => $traitName
379
-            ]
380
-        );
381
-
382
-        $this->evalClass(
383
-            $classTemplate->render(),
384
-            $className['className']
385
-        );
386
-
387
-        return $this->getMockForAbstractClass($className['className'], $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $mockedMethods, $cloneArguments);
388
-    }
389
-
390
-    /**
391
-     * Returns an object for the specified trait.
392
-     *
393
-     * @param string $traitName
394
-     * @param array  $arguments
395
-     * @param string $traitClassName
396
-     * @param bool   $callOriginalConstructor
397
-     * @param bool   $callOriginalClone
398
-     * @param bool   $callAutoload
399
-     *
400
-     * @return object
401
-     *
402
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
403
-     * @throws PHPUnit\Framework\Exception
404
-     */
405
-    public function getObjectForTrait($traitName, array $arguments = [], $traitClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true)
406
-    {
407
-        if (!is_string($traitName)) {
408
-            throw InvalidArgumentHelper::factory(1, 'string');
409
-        }
410
-
411
-        if (!is_string($traitClassName)) {
412
-            throw InvalidArgumentHelper::factory(3, 'string');
413
-        }
414
-
415
-        if (!trait_exists($traitName, $callAutoload)) {
416
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
417
-                sprintf(
418
-                    'Trait "%s" does not exist.',
419
-                    $traitName
420
-                )
421
-            );
422
-        }
423
-
424
-        $className = $this->generateClassName(
425
-            $traitName,
426
-            $traitClassName,
427
-            'Trait_'
428
-        );
429
-
430
-        $classTemplate = $this->getTemplate('trait_class.tpl');
431
-
432
-        $classTemplate->setVar(
433
-            [
434
-                'prologue'   => '',
435
-                'class_name' => $className['className'],
436
-                'trait_name' => $traitName
437
-            ]
438
-        );
439
-
440
-        return $this->getObject(
441
-            $classTemplate->render(),
442
-            $className['className']
443
-        );
444
-    }
445
-
446
-    /**
447
-     * @param array|string $type
448
-     * @param array        $methods
449
-     * @param string       $mockClassName
450
-     * @param bool         $callOriginalClone
451
-     * @param bool         $callAutoload
452
-     * @param bool         $cloneArguments
453
-     * @param bool         $callOriginalMethods
454
-     *
455
-     * @return array
456
-     */
457
-    public function generate($type, array $methods = null, $mockClassName = '', $callOriginalClone = true, $callAutoload = true, $cloneArguments = true, $callOriginalMethods = false)
458
-    {
459
-        if (is_array($type)) {
460
-            sort($type);
461
-        }
462
-
463
-        if ($mockClassName == '') {
464
-            $key = md5(
465
-                is_array($type) ? implode('_', $type) : $type .
466
-                serialize($methods) .
467
-                serialize($callOriginalClone) .
468
-                serialize($cloneArguments) .
469
-                serialize($callOriginalMethods)
470
-            );
471
-
472
-            if (isset(self::$cache[$key])) {
473
-                return self::$cache[$key];
474
-            }
475
-        }
476
-
477
-        $mock = $this->generateMock(
478
-            $type,
479
-            $methods,
480
-            $mockClassName,
481
-            $callOriginalClone,
482
-            $callAutoload,
483
-            $cloneArguments,
484
-            $callOriginalMethods
485
-        );
486
-
487
-        if (isset($key)) {
488
-            self::$cache[$key] = $mock;
489
-        }
490
-
491
-        return $mock;
492
-    }
493
-
494
-    /**
495
-     * @param string $wsdlFile
496
-     * @param string $className
497
-     * @param array  $methods
498
-     * @param array  $options
499
-     *
500
-     * @return string
501
-     *
502
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
503
-     */
504
-    public function generateClassFromWsdl($wsdlFile, $className, array $methods = [], array $options = [])
505
-    {
506
-        if (!extension_loaded('soap')) {
507
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
508
-                'The SOAP extension is required to generate a mock object from WSDL.'
509
-            );
510
-        }
511
-
512
-        $options  = array_merge($options, ['cache_wsdl' => WSDL_CACHE_NONE]);
513
-        $client   = new SoapClient($wsdlFile, $options);
514
-        $_methods = array_unique($client->__getFunctions());
515
-        unset($client);
516
-
517
-        sort($_methods);
518
-
519
-        $methodTemplate = $this->getTemplate('wsdl_method.tpl');
520
-        $methodsBuffer  = '';
521
-
522
-        foreach ($_methods as $method) {
523
-            $nameStart = strpos($method, ' ') + 1;
524
-            $nameEnd   = strpos($method, '(');
525
-            $name      = substr($method, $nameStart, $nameEnd - $nameStart);
526
-
527
-            if (empty($methods) || in_array($name, $methods)) {
528
-                $args    = explode(
529
-                    ',',
530
-                    substr(
531
-                        $method,
532
-                        $nameEnd + 1,
533
-                        strpos($method, ')') - $nameEnd - 1
534
-                    )
535
-                );
536
-
537
-                foreach (range(0, count($args) - 1) as $i) {
538
-                    $args[$i] = substr($args[$i], strpos($args[$i], '$'));
539
-                }
540
-
541
-                $methodTemplate->setVar(
542
-                    [
543
-                        'method_name' => $name,
544
-                        'arguments'   => implode(', ', $args)
545
-                    ]
546
-                );
547
-
548
-                $methodsBuffer .= $methodTemplate->render();
549
-            }
550
-        }
551
-
552
-        $optionsBuffer = 'array(';
553
-
554
-        foreach ($options as $key => $value) {
555
-            $optionsBuffer .= $key . ' => ' . $value;
556
-        }
557
-
558
-        $optionsBuffer .= ')';
559
-
560
-        $classTemplate = $this->getTemplate('wsdl_class.tpl');
561
-        $namespace     = '';
562
-
563
-        if (strpos($className, '\\') !== false) {
564
-            $parts     = explode('\\', $className);
565
-            $className = array_pop($parts);
566
-            $namespace = 'namespace ' . implode('\\', $parts) . ';' . "\n\n";
567
-        }
568
-
569
-        $classTemplate->setVar(
570
-            [
571
-                'namespace'  => $namespace,
572
-                'class_name' => $className,
573
-                'wsdl'       => $wsdlFile,
574
-                'options'    => $optionsBuffer,
575
-                'methods'    => $methodsBuffer
576
-            ]
577
-        );
578
-
579
-        return $classTemplate->render();
580
-    }
581
-
582
-    /**
583
-     * @param array|string $type
584
-     * @param array|null   $methods
585
-     * @param string       $mockClassName
586
-     * @param bool         $callOriginalClone
587
-     * @param bool         $callAutoload
588
-     * @param bool         $cloneArguments
589
-     * @param bool         $callOriginalMethods
590
-     *
591
-     * @return array
592
-     *
593
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
594
-     */
595
-    private function generateMock($type, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods)
596
-    {
597
-        $methodReflections   = [];
598
-        $classTemplate       = $this->getTemplate('mocked_class.tpl');
599
-
600
-        $additionalInterfaces = [];
601
-        $cloneTemplate        = '';
602
-        $isClass              = false;
603
-        $isInterface          = false;
604
-        $isMultipleInterfaces = false;
605
-
606
-        if (is_array($type)) {
607
-            foreach ($type as $_type) {
608
-                if (!interface_exists($_type, $callAutoload)) {
609
-                    throw new PHPUnit_Framework_MockObject_RuntimeException(
610
-                        sprintf(
611
-                            'Interface "%s" does not exist.',
612
-                            $_type
613
-                        )
614
-                    );
615
-                }
616
-
617
-                $isMultipleInterfaces = true;
618
-
619
-                $additionalInterfaces[] = $_type;
620
-                $typeClass              = new ReflectionClass($this->generateClassName(
621
-                    $_type,
622
-                    $mockClassName,
623
-                    'Mock_'
624
-                    )['fullClassName']
625
-                );
626
-
627
-                foreach ($this->getClassMethods($_type) as $method) {
628
-                    if (in_array($method, $methods)) {
629
-                        throw new PHPUnit_Framework_MockObject_RuntimeException(
630
-                            sprintf(
631
-                                'Duplicate method "%s" not allowed.',
632
-                                $method
633
-                            )
634
-                        );
635
-                    }
636
-
637
-                    $methodReflections[$method] = $typeClass->getMethod($method);
638
-                    $methods[]                  = $method;
639
-                }
640
-            }
641
-        }
642
-
643
-        $mockClassName = $this->generateClassName(
644
-            $type,
645
-            $mockClassName,
646
-            'Mock_'
647
-        );
648
-
649
-        if (class_exists($mockClassName['fullClassName'], $callAutoload)) {
650
-            $isClass = true;
651
-        } elseif (interface_exists($mockClassName['fullClassName'], $callAutoload)) {
652
-            $isInterface = true;
653
-        }
654
-
655
-        if (!$isClass && !$isInterface) {
656
-            $prologue = 'class ' . $mockClassName['originalClassName'] . "\n{\n}\n\n";
657
-
658
-            if (!empty($mockClassName['namespaceName'])) {
659
-                $prologue = 'namespace ' . $mockClassName['namespaceName'] .
660
-                            " {\n\n" . $prologue . "}\n\n" .
661
-                            "namespace {\n\n";
662
-
663
-                $epilogue = "\n\n}";
664
-            }
665
-
666
-            $cloneTemplate = $this->getTemplate('mocked_clone.tpl');
667
-        } else {
668
-            $class = new ReflectionClass($mockClassName['fullClassName']);
669
-
670
-            if ($class->isFinal()) {
671
-                throw new PHPUnit_Framework_MockObject_RuntimeException(
672
-                    sprintf(
673
-                        'Class "%s" is declared "final" and cannot be mocked.',
674
-                        $mockClassName['fullClassName']
675
-                    )
676
-                );
677
-            }
678
-
679
-            if ($class->hasMethod('__clone')) {
680
-                $cloneMethod = $class->getMethod('__clone');
681
-
682
-                if (!$cloneMethod->isFinal()) {
683
-                    if ($callOriginalClone && !$isInterface) {
684
-                        $cloneTemplate = $this->getTemplate('unmocked_clone.tpl');
685
-                    } else {
686
-                        $cloneTemplate = $this->getTemplate('mocked_clone.tpl');
687
-                    }
688
-                }
689
-            } else {
690
-                $cloneTemplate = $this->getTemplate('mocked_clone.tpl');
691
-            }
692
-        }
693
-
694
-        if (is_object($cloneTemplate)) {
695
-            $cloneTemplate = $cloneTemplate->render();
696
-        }
697
-
698
-        if (is_array($methods) && empty($methods) &&
699
-            ($isClass || $isInterface)) {
700
-            $methods = $this->getClassMethods($mockClassName['fullClassName']);
701
-        }
702
-
703
-        if (!is_array($methods)) {
704
-            $methods = [];
705
-        }
706
-
707
-        $mockedMethods = '';
708
-        $configurable  = [];
709
-
710
-        foreach ($methods as $methodName) {
711
-            if ($methodName != '__construct' && $methodName != '__clone') {
712
-                $configurable[] = strtolower($methodName);
713
-            }
714
-        }
715
-
716
-        if (isset($class)) {
717
-            // https://github.com/sebastianbergmann/phpunit-mock-objects/issues/103
718
-            if ($isInterface && $class->implementsInterface(Traversable::class) &&
719
-                !$class->implementsInterface(Iterator::class) &&
720
-                !$class->implementsInterface(IteratorAggregate::class)) {
721
-                $additionalInterfaces[] = Iterator::class;
722
-                $methods                = array_merge($methods, $this->getClassMethods(Iterator::class));
723
-            }
724
-
725
-            foreach ($methods as $methodName) {
726
-                try {
727
-                    $method = $class->getMethod($methodName);
728
-
729
-                    if ($this->canMockMethod($method)) {
730
-                        $mockedMethods .= $this->generateMockedMethodDefinitionFromExisting(
731
-                            $method,
732
-                            $cloneArguments,
733
-                            $callOriginalMethods
734
-                        );
735
-                    }
736
-                } catch (ReflectionException $e) {
737
-                    $mockedMethods .= $this->generateMockedMethodDefinition(
738
-                        $mockClassName['fullClassName'],
739
-                        $methodName,
740
-                        $cloneArguments
741
-                    );
742
-                }
743
-            }
744
-        } elseif ($isMultipleInterfaces) {
745
-            foreach ($methods as $methodName) {
746
-                if ($this->canMockMethod($methodReflections[$methodName])) {
747
-                    $mockedMethods .= $this->generateMockedMethodDefinitionFromExisting(
748
-                        $methodReflections[$methodName],
749
-                        $cloneArguments,
750
-                        $callOriginalMethods
751
-                    );
752
-                }
753
-            }
754
-        } else {
755
-            foreach ($methods as $methodName) {
756
-                $mockedMethods .= $this->generateMockedMethodDefinition(
757
-                    $mockClassName['fullClassName'],
758
-                    $methodName,
759
-                    $cloneArguments
760
-                );
761
-            }
762
-        }
763
-
764
-        $method = '';
765
-
766
-        if (!in_array('method', $methods) && (!isset($class) || !$class->hasMethod('method'))) {
767
-            $methodTemplate = $this->getTemplate('mocked_class_method.tpl');
768
-
769
-            $method = $methodTemplate->render();
770
-        }
771
-
772
-        $classTemplate->setVar(
773
-            [
774
-                'prologue'          => isset($prologue) ? $prologue : '',
775
-                'epilogue'          => isset($epilogue) ? $epilogue : '',
776
-                'class_declaration' => $this->generateMockClassDeclaration(
777
-                    $mockClassName,
778
-                    $isInterface,
779
-                    $additionalInterfaces
780
-                ),
781
-                'clone'             => $cloneTemplate,
782
-                'mock_class_name'   => $mockClassName['className'],
783
-                'mocked_methods'    => $mockedMethods,
784
-                'method'            => $method,
785
-                'configurable'      => '[' . implode(', ', array_map(function ($m) {
786
-                    return '\'' . $m . '\'';
787
-                }, $configurable)) . ']'
788
-            ]
789
-        );
790
-
791
-        return [
792
-          'code'          => $classTemplate->render(),
793
-          'mockClassName' => $mockClassName['className']
794
-        ];
795
-    }
796
-
797
-    /**
798
-     * @param array|string $type
799
-     * @param string       $className
800
-     * @param string       $prefix
801
-     *
802
-     * @return array
803
-     */
804
-    private function generateClassName($type, $className, $prefix)
805
-    {
806
-        if (is_array($type)) {
807
-            $type = implode('_', $type);
808
-        }
809
-
810
-        if ($type[0] == '\\') {
811
-            $type = substr($type, 1);
812
-        }
813
-
814
-        $classNameParts = explode('\\', $type);
815
-
816
-        if (count($classNameParts) > 1) {
817
-            $type          = array_pop($classNameParts);
818
-            $namespaceName = implode('\\', $classNameParts);
819
-            $fullClassName = $namespaceName . '\\' . $type;
820
-        } else {
821
-            $namespaceName = '';
822
-            $fullClassName = $type;
823
-        }
824
-
825
-        if ($className == '') {
826
-            do {
827
-                $className = $prefix . $type . '_' .
828
-                             substr(md5(mt_rand()), 0, 8);
829
-            } while (class_exists($className, false));
830
-        }
831
-
832
-        return [
833
-          'className'         => $className,
834
-          'originalClassName' => $type,
835
-          'fullClassName'     => $fullClassName,
836
-          'namespaceName'     => $namespaceName
837
-        ];
838
-    }
839
-
840
-    /**
841
-     * @param array $mockClassName
842
-     * @param bool  $isInterface
843
-     * @param array $additionalInterfaces
844
-     *
845
-     * @return string
846
-     */
847
-    private function generateMockClassDeclaration(array $mockClassName, $isInterface, array $additionalInterfaces = [])
848
-    {
849
-        $buffer = 'class ';
850
-
851
-        $additionalInterfaces[] = 'PHPUnit_Framework_MockObject_MockObject';
852
-        $interfaces             = implode(', ', $additionalInterfaces);
853
-
854
-        if ($isInterface) {
855
-            $buffer .= sprintf(
856
-                '%s implements %s',
857
-                $mockClassName['className'],
858
-                $interfaces
859
-            );
860
-
861
-            if (!in_array($mockClassName['originalClassName'], $additionalInterfaces)) {
862
-                $buffer .= ', ';
863
-
864
-                if (!empty($mockClassName['namespaceName'])) {
865
-                    $buffer .= $mockClassName['namespaceName'] . '\\';
866
-                }
867
-
868
-                $buffer .= $mockClassName['originalClassName'];
869
-            }
870
-        } else {
871
-            $buffer .= sprintf(
872
-                '%s extends %s%s implements %s',
873
-                $mockClassName['className'],
874
-                !empty($mockClassName['namespaceName']) ? $mockClassName['namespaceName'] . '\\' : '',
875
-                $mockClassName['originalClassName'],
876
-                $interfaces
877
-            );
878
-        }
879
-
880
-        return $buffer;
881
-    }
882
-
883
-    /**
884
-     * @param ReflectionMethod $method
885
-     * @param bool             $cloneArguments
886
-     * @param bool             $callOriginalMethods
887
-     *
888
-     * @return string
889
-     */
890
-    private function generateMockedMethodDefinitionFromExisting(ReflectionMethod $method, $cloneArguments, $callOriginalMethods)
891
-    {
892
-        if ($method->isPrivate()) {
893
-            $modifier = 'private';
894
-        } elseif ($method->isProtected()) {
895
-            $modifier = 'protected';
896
-        } else {
897
-            $modifier = 'public';
898
-        }
899
-
900
-        if ($method->isStatic()) {
901
-            $modifier .= ' static';
902
-        }
903
-
904
-        if ($method->returnsReference()) {
905
-            $reference = '&';
906
-        } else {
907
-            $reference = '';
908
-        }
909
-
910
-        if ($method->hasReturnType()) {
911
-            $returnType = (string) $method->getReturnType();
912
-        } else {
913
-            $returnType = '';
914
-        }
915
-
916
-        if (preg_match('#\*[ \t]*+@deprecated[ \t]*+(.*?)\r?+\n[ \t]*+\*(?:[ \t]*+@|/$)#s', $method->getDocComment(), $deprecation)) {
917
-            $deprecation = trim(preg_replace('#[ \t]*\r?\n[ \t]*+\*[ \t]*+#', ' ', $deprecation[1]));
918
-        } else {
919
-            $deprecation = false;
920
-        }
921
-
922
-        return $this->generateMockedMethodDefinition(
923
-            $method->getDeclaringClass()->getName(),
924
-            $method->getName(),
925
-            $cloneArguments,
926
-            $modifier,
927
-            $this->getMethodParameters($method),
928
-            $this->getMethodParameters($method, true),
929
-            $returnType,
930
-            $reference,
931
-            $callOriginalMethods,
932
-            $method->isStatic(),
933
-            $deprecation,
934
-            $method->hasReturnType() && $method->getReturnType()->allowsNull()
935
-        );
936
-    }
937
-
938
-    /**
939
-     * @param string      $className
940
-     * @param string      $methodName
941
-     * @param bool        $cloneArguments
942
-     * @param string      $modifier
943
-     * @param string      $argumentsForDeclaration
944
-     * @param string      $argumentsForCall
945
-     * @param string      $returnType
946
-     * @param string      $reference
947
-     * @param bool        $callOriginalMethods
948
-     * @param bool        $static
949
-     * @param bool|string $deprecation
950
-     * @param bool        $allowsReturnNull
951
-     *
952
-     * @return string
953
-     */
954
-    private function generateMockedMethodDefinition($className, $methodName, $cloneArguments = true, $modifier = 'public', $argumentsForDeclaration = '', $argumentsForCall = '', $returnType = '', $reference = '', $callOriginalMethods = false, $static = false, $deprecation = false, $allowsReturnNull = false)
955
-    {
956
-        if ($static) {
957
-            $templateFile = 'mocked_static_method.tpl';
958
-        } else {
959
-            if ($returnType === 'void') {
960
-                $templateFile = sprintf(
961
-                    '%s_method_void.tpl',
962
-                    $callOriginalMethods ? 'proxied' : 'mocked'
963
-                );
964
-            } else {
965
-                $templateFile = sprintf(
966
-                    '%s_method.tpl',
967
-                    $callOriginalMethods ? 'proxied' : 'mocked'
968
-                );
969
-            }
970
-        }
971
-
972
-        // Mocked interfaces returning 'self' must explicitly declare the
973
-        // interface name as the return type. See
974
-        // https://bugs.php.net/bug.php?id=70722
975
-        if ($returnType === 'self') {
976
-            $returnType = $className;
977
-        }
978
-
979
-        if (false !== $deprecation) {
980
-            $deprecation         = "The $className::$methodName method is deprecated ($deprecation).";
981
-            $deprecationTemplate = $this->getTemplate('deprecation.tpl');
982
-
983
-            $deprecationTemplate->setVar(
984
-                [
985
-                    'deprecation' => var_export($deprecation, true),
986
-                ]
987
-            );
988
-
989
-            $deprecation = $deprecationTemplate->render();
990
-        }
991
-
992
-        $template = $this->getTemplate($templateFile);
993
-
994
-        $template->setVar(
995
-            [
996
-                'arguments_decl'  => $argumentsForDeclaration,
997
-                'arguments_call'  => $argumentsForCall,
998
-                'return_delim'    => $returnType ? ': ' : '',
999
-                'return_type'     => $allowsReturnNull ? '?' . $returnType : $returnType,
1000
-                'arguments_count' => !empty($argumentsForCall) ? count(explode(',', $argumentsForCall)) : 0,
1001
-                'class_name'      => $className,
1002
-                'method_name'     => $methodName,
1003
-                'modifier'        => $modifier,
1004
-                'reference'       => $reference,
1005
-                'clone_arguments' => $cloneArguments ? 'true' : 'false',
1006
-                'deprecation'     => $deprecation
1007
-            ]
1008
-        );
1009
-
1010
-        return $template->render();
1011
-    }
1012
-
1013
-    /**
1014
-     * @param ReflectionMethod $method
1015
-     *
1016
-     * @return bool
1017
-     */
1018
-    private function canMockMethod(ReflectionMethod $method)
1019
-    {
1020
-        if ($method->isConstructor() ||
1021
-            $method->isFinal() ||
1022
-            $method->isPrivate() ||
1023
-            $this->isMethodNameBlacklisted($method->getName())) {
1024
-            return false;
1025
-        }
1026
-
1027
-        return true;
1028
-    }
1029
-
1030
-    /**
1031
-     * Returns whether a method name is blacklisted
1032
-     *
1033
-     * @param string $name
1034
-     *
1035
-     * @return bool
1036
-     */
1037
-    private function isMethodNameBlacklisted($name)
1038
-    {
1039
-        return isset($this->blacklistedMethodNames[$name]);
1040
-    }
1041
-
1042
-    /**
1043
-     * Returns the parameters of a function or method.
1044
-     *
1045
-     * @param ReflectionMethod $method
1046
-     * @param bool             $forCall
1047
-     *
1048
-     * @return string
1049
-     *
1050
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
1051
-     */
1052
-    private function getMethodParameters(ReflectionMethod $method, $forCall = false)
1053
-    {
1054
-        $parameters = [];
1055
-
1056
-        foreach ($method->getParameters() as $i => $parameter) {
1057
-            $name = '$' . $parameter->getName();
1058
-
1059
-            /* Note: PHP extensions may use empty names for reference arguments
21
+	/**
22
+	 * @var array
23
+	 */
24
+	private static $cache = [];
25
+
26
+	/**
27
+	 * @var Text_Template[]
28
+	 */
29
+	private static $templates = [];
30
+
31
+	/**
32
+	 * @var array
33
+	 */
34
+	private $blacklistedMethodNames = [
35
+		'__CLASS__'       => true,
36
+		'__DIR__'         => true,
37
+		'__FILE__'        => true,
38
+		'__FUNCTION__'    => true,
39
+		'__LINE__'        => true,
40
+		'__METHOD__'      => true,
41
+		'__NAMESPACE__'   => true,
42
+		'__TRAIT__'       => true,
43
+		'__clone'         => true,
44
+		'__halt_compiler' => true,
45
+	];
46
+
47
+	/**
48
+	 * Returns a mock object for the specified class.
49
+	 *
50
+	 * @param string|string[] $type
51
+	 * @param array           $methods
52
+	 * @param array           $arguments
53
+	 * @param string          $mockClassName
54
+	 * @param bool            $callOriginalConstructor
55
+	 * @param bool            $callOriginalClone
56
+	 * @param bool            $callAutoload
57
+	 * @param bool            $cloneArguments
58
+	 * @param bool            $callOriginalMethods
59
+	 * @param object          $proxyTarget
60
+	 * @param bool            $allowMockingUnknownTypes
61
+	 *
62
+	 * @return PHPUnit_Framework_MockObject_MockObject
63
+	 *
64
+	 * @throws InvalidArgumentException
65
+	 * @throws PHPUnit\Framework\Exception
66
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
67
+	 */
68
+	public function getMock($type, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = true, $callOriginalMethods = false, $proxyTarget = null, $allowMockingUnknownTypes = true)
69
+	{
70
+		if (!is_array($type) && !is_string($type)) {
71
+			throw InvalidArgumentHelper::factory(1, 'array or string');
72
+		}
73
+
74
+		if (!is_string($mockClassName)) {
75
+			throw InvalidArgumentHelper::factory(4, 'string');
76
+		}
77
+
78
+		if (!is_array($methods) && !is_null($methods)) {
79
+			throw InvalidArgumentHelper::factory(2, 'array', $methods);
80
+		}
81
+
82
+		if ($type === 'Traversable' || $type === '\\Traversable') {
83
+			$type = 'Iterator';
84
+		}
85
+
86
+		if (is_array($type)) {
87
+			$type = array_unique(
88
+				array_map(
89
+					function ($type) {
90
+						if ($type === 'Traversable' ||
91
+							$type === '\\Traversable' ||
92
+							$type === '\\Iterator') {
93
+							return 'Iterator';
94
+						}
95
+
96
+						return $type;
97
+					},
98
+					$type
99
+				)
100
+			);
101
+		}
102
+
103
+		if (!$allowMockingUnknownTypes) {
104
+			if (is_array($type)) {
105
+				foreach ($type as $_type) {
106
+					if (!class_exists($_type, $callAutoload) &&
107
+						!interface_exists($_type, $callAutoload)) {
108
+						throw new PHPUnit_Framework_MockObject_RuntimeException(
109
+							sprintf(
110
+								'Cannot stub or mock class or interface "%s" which does not exist',
111
+								$_type
112
+							)
113
+						);
114
+					}
115
+				}
116
+			} else {
117
+				if (!class_exists($type, $callAutoload) &&
118
+					!interface_exists($type, $callAutoload)
119
+				) {
120
+					throw new PHPUnit_Framework_MockObject_RuntimeException(
121
+						sprintf(
122
+							'Cannot stub or mock class or interface "%s" which does not exist',
123
+							$type
124
+						)
125
+					);
126
+				}
127
+			}
128
+		}
129
+
130
+		if (null !== $methods) {
131
+			foreach ($methods as $method) {
132
+				if (!preg_match('~[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*~', $method)) {
133
+					throw new PHPUnit_Framework_MockObject_RuntimeException(
134
+						sprintf(
135
+							'Cannot stub or mock method with invalid name "%s"',
136
+							$method
137
+						)
138
+					);
139
+				}
140
+			}
141
+
142
+			if ($methods != array_unique($methods)) {
143
+				throw new PHPUnit_Framework_MockObject_RuntimeException(
144
+					sprintf(
145
+						'Cannot stub or mock using a method list that contains duplicates: "%s" (duplicate: "%s")',
146
+						implode(', ', $methods),
147
+						implode(', ', array_unique(array_diff_assoc($methods, array_unique($methods))))
148
+					)
149
+				);
150
+			}
151
+		}
152
+
153
+		if ($mockClassName != '' && class_exists($mockClassName, false)) {
154
+			$reflect = new ReflectionClass($mockClassName);
155
+
156
+			if (!$reflect->implementsInterface('PHPUnit_Framework_MockObject_MockObject')) {
157
+				throw new PHPUnit_Framework_MockObject_RuntimeException(
158
+					sprintf(
159
+						'Class "%s" already exists.',
160
+						$mockClassName
161
+					)
162
+				);
163
+			}
164
+		}
165
+
166
+		if ($callOriginalConstructor === false && $callOriginalMethods === true) {
167
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
168
+				'Proxying to original methods requires invoking the original constructor'
169
+			);
170
+		}
171
+
172
+		$mock = $this->generate(
173
+			$type,
174
+			$methods,
175
+			$mockClassName,
176
+			$callOriginalClone,
177
+			$callAutoload,
178
+			$cloneArguments,
179
+			$callOriginalMethods
180
+		);
181
+
182
+		return $this->getObject(
183
+			$mock['code'],
184
+			$mock['mockClassName'],
185
+			$type,
186
+			$callOriginalConstructor,
187
+			$callAutoload,
188
+			$arguments,
189
+			$callOriginalMethods,
190
+			$proxyTarget
191
+		);
192
+	}
193
+
194
+	/**
195
+	 * @param string       $code
196
+	 * @param string       $className
197
+	 * @param array|string $type
198
+	 * @param bool         $callOriginalConstructor
199
+	 * @param bool         $callAutoload
200
+	 * @param array        $arguments
201
+	 * @param bool         $callOriginalMethods
202
+	 * @param object       $proxyTarget
203
+	 *
204
+	 * @return PHPUnit_Framework_MockObject_MockObject
205
+	 *
206
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
207
+	 */
208
+	private function getObject($code, $className, $type = '', $callOriginalConstructor = false, $callAutoload = false, array $arguments = [], $callOriginalMethods = false, $proxyTarget = null)
209
+	{
210
+		$this->evalClass($code, $className);
211
+
212
+		if ($callOriginalConstructor &&
213
+			is_string($type) &&
214
+			!interface_exists($type, $callAutoload)) {
215
+			if (count($arguments) == 0) {
216
+				$object = new $className;
217
+			} else {
218
+				$class  = new ReflectionClass($className);
219
+				$object = $class->newInstanceArgs($arguments);
220
+			}
221
+		} else {
222
+			try {
223
+				$instantiator = new Instantiator;
224
+				$object       = $instantiator->instantiate($className);
225
+			} catch (InstantiatorUnexpectedValueException $exception) {
226
+				if ($exception->getPrevious()) {
227
+					$exception = $exception->getPrevious();
228
+				}
229
+
230
+				throw new PHPUnit_Framework_MockObject_RuntimeException(
231
+					$exception->getMessage()
232
+				);
233
+			} catch (InstantiatorInvalidArgumentException $exception) {
234
+				throw new PHPUnit_Framework_MockObject_RuntimeException(
235
+					$exception->getMessage()
236
+				);
237
+			}
238
+		}
239
+
240
+		if ($callOriginalMethods) {
241
+			if (!is_object($proxyTarget)) {
242
+				if (count($arguments) == 0) {
243
+					$proxyTarget = new $type;
244
+				} else {
245
+					$class       = new ReflectionClass($type);
246
+					$proxyTarget = $class->newInstanceArgs($arguments);
247
+				}
248
+			}
249
+
250
+			$object->__phpunit_setOriginalObject($proxyTarget);
251
+		}
252
+
253
+		return $object;
254
+	}
255
+
256
+	/**
257
+	 * @param string $code
258
+	 * @param string $className
259
+	 */
260
+	private function evalClass($code, $className)
261
+	{
262
+		if (!class_exists($className, false)) {
263
+			eval($code);
264
+		}
265
+	}
266
+
267
+	/**
268
+	 * Returns a mock object for the specified abstract class with all abstract
269
+	 * methods of the class mocked. Concrete methods to mock can be specified with
270
+	 * the last parameter
271
+	 *
272
+	 * @param string $originalClassName
273
+	 * @param array  $arguments
274
+	 * @param string $mockClassName
275
+	 * @param bool   $callOriginalConstructor
276
+	 * @param bool   $callOriginalClone
277
+	 * @param bool   $callAutoload
278
+	 * @param array  $mockedMethods
279
+	 * @param bool   $cloneArguments
280
+	 *
281
+	 * @return PHPUnit_Framework_MockObject_MockObject
282
+	 *
283
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
284
+	 * @throws PHPUnit\Framework\Exception
285
+	 */
286
+	public function getMockForAbstractClass($originalClassName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = true)
287
+	{
288
+		if (!is_string($originalClassName)) {
289
+			throw InvalidArgumentHelper::factory(1, 'string');
290
+		}
291
+
292
+		if (!is_string($mockClassName)) {
293
+			throw InvalidArgumentHelper::factory(3, 'string');
294
+		}
295
+
296
+		if (class_exists($originalClassName, $callAutoload) ||
297
+			interface_exists($originalClassName, $callAutoload)) {
298
+			$reflector = new ReflectionClass($originalClassName);
299
+			$methods   = $mockedMethods;
300
+
301
+			foreach ($reflector->getMethods() as $method) {
302
+				if ($method->isAbstract() && !in_array($method->getName(), $methods)) {
303
+					$methods[] = $method->getName();
304
+				}
305
+			}
306
+
307
+			if (empty($methods)) {
308
+				$methods = null;
309
+			}
310
+
311
+			return $this->getMock(
312
+				$originalClassName,
313
+				$methods,
314
+				$arguments,
315
+				$mockClassName,
316
+				$callOriginalConstructor,
317
+				$callOriginalClone,
318
+				$callAutoload,
319
+				$cloneArguments
320
+			);
321
+		}
322
+
323
+		throw new PHPUnit_Framework_MockObject_RuntimeException(
324
+			sprintf('Class "%s" does not exist.', $originalClassName)
325
+		);
326
+	}
327
+
328
+	/**
329
+	 * Returns a mock object for the specified trait with all abstract methods
330
+	 * of the trait mocked. Concrete methods to mock can be specified with the
331
+	 * `$mockedMethods` parameter.
332
+	 *
333
+	 * @param string $traitName
334
+	 * @param array  $arguments
335
+	 * @param string $mockClassName
336
+	 * @param bool   $callOriginalConstructor
337
+	 * @param bool   $callOriginalClone
338
+	 * @param bool   $callAutoload
339
+	 * @param array  $mockedMethods
340
+	 * @param bool   $cloneArguments
341
+	 *
342
+	 * @return PHPUnit_Framework_MockObject_MockObject
343
+	 *
344
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
345
+	 * @throws PHPUnit\Framework\Exception
346
+	 */
347
+	public function getMockForTrait($traitName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = true)
348
+	{
349
+		if (!is_string($traitName)) {
350
+			throw InvalidArgumentHelper::factory(1, 'string');
351
+		}
352
+
353
+		if (!is_string($mockClassName)) {
354
+			throw InvalidArgumentHelper::factory(3, 'string');
355
+		}
356
+
357
+		if (!trait_exists($traitName, $callAutoload)) {
358
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
359
+				sprintf(
360
+					'Trait "%s" does not exist.',
361
+					$traitName
362
+				)
363
+			);
364
+		}
365
+
366
+		$className = $this->generateClassName(
367
+			$traitName,
368
+			'',
369
+			'Trait_'
370
+		);
371
+
372
+		$classTemplate = $this->getTemplate('trait_class.tpl');
373
+
374
+		$classTemplate->setVar(
375
+			[
376
+				'prologue'   => 'abstract ',
377
+				'class_name' => $className['className'],
378
+				'trait_name' => $traitName
379
+			]
380
+		);
381
+
382
+		$this->evalClass(
383
+			$classTemplate->render(),
384
+			$className['className']
385
+		);
386
+
387
+		return $this->getMockForAbstractClass($className['className'], $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $mockedMethods, $cloneArguments);
388
+	}
389
+
390
+	/**
391
+	 * Returns an object for the specified trait.
392
+	 *
393
+	 * @param string $traitName
394
+	 * @param array  $arguments
395
+	 * @param string $traitClassName
396
+	 * @param bool   $callOriginalConstructor
397
+	 * @param bool   $callOriginalClone
398
+	 * @param bool   $callAutoload
399
+	 *
400
+	 * @return object
401
+	 *
402
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
403
+	 * @throws PHPUnit\Framework\Exception
404
+	 */
405
+	public function getObjectForTrait($traitName, array $arguments = [], $traitClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true)
406
+	{
407
+		if (!is_string($traitName)) {
408
+			throw InvalidArgumentHelper::factory(1, 'string');
409
+		}
410
+
411
+		if (!is_string($traitClassName)) {
412
+			throw InvalidArgumentHelper::factory(3, 'string');
413
+		}
414
+
415
+		if (!trait_exists($traitName, $callAutoload)) {
416
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
417
+				sprintf(
418
+					'Trait "%s" does not exist.',
419
+					$traitName
420
+				)
421
+			);
422
+		}
423
+
424
+		$className = $this->generateClassName(
425
+			$traitName,
426
+			$traitClassName,
427
+			'Trait_'
428
+		);
429
+
430
+		$classTemplate = $this->getTemplate('trait_class.tpl');
431
+
432
+		$classTemplate->setVar(
433
+			[
434
+				'prologue'   => '',
435
+				'class_name' => $className['className'],
436
+				'trait_name' => $traitName
437
+			]
438
+		);
439
+
440
+		return $this->getObject(
441
+			$classTemplate->render(),
442
+			$className['className']
443
+		);
444
+	}
445
+
446
+	/**
447
+	 * @param array|string $type
448
+	 * @param array        $methods
449
+	 * @param string       $mockClassName
450
+	 * @param bool         $callOriginalClone
451
+	 * @param bool         $callAutoload
452
+	 * @param bool         $cloneArguments
453
+	 * @param bool         $callOriginalMethods
454
+	 *
455
+	 * @return array
456
+	 */
457
+	public function generate($type, array $methods = null, $mockClassName = '', $callOriginalClone = true, $callAutoload = true, $cloneArguments = true, $callOriginalMethods = false)
458
+	{
459
+		if (is_array($type)) {
460
+			sort($type);
461
+		}
462
+
463
+		if ($mockClassName == '') {
464
+			$key = md5(
465
+				is_array($type) ? implode('_', $type) : $type .
466
+				serialize($methods) .
467
+				serialize($callOriginalClone) .
468
+				serialize($cloneArguments) .
469
+				serialize($callOriginalMethods)
470
+			);
471
+
472
+			if (isset(self::$cache[$key])) {
473
+				return self::$cache[$key];
474
+			}
475
+		}
476
+
477
+		$mock = $this->generateMock(
478
+			$type,
479
+			$methods,
480
+			$mockClassName,
481
+			$callOriginalClone,
482
+			$callAutoload,
483
+			$cloneArguments,
484
+			$callOriginalMethods
485
+		);
486
+
487
+		if (isset($key)) {
488
+			self::$cache[$key] = $mock;
489
+		}
490
+
491
+		return $mock;
492
+	}
493
+
494
+	/**
495
+	 * @param string $wsdlFile
496
+	 * @param string $className
497
+	 * @param array  $methods
498
+	 * @param array  $options
499
+	 *
500
+	 * @return string
501
+	 *
502
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
503
+	 */
504
+	public function generateClassFromWsdl($wsdlFile, $className, array $methods = [], array $options = [])
505
+	{
506
+		if (!extension_loaded('soap')) {
507
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
508
+				'The SOAP extension is required to generate a mock object from WSDL.'
509
+			);
510
+		}
511
+
512
+		$options  = array_merge($options, ['cache_wsdl' => WSDL_CACHE_NONE]);
513
+		$client   = new SoapClient($wsdlFile, $options);
514
+		$_methods = array_unique($client->__getFunctions());
515
+		unset($client);
516
+
517
+		sort($_methods);
518
+
519
+		$methodTemplate = $this->getTemplate('wsdl_method.tpl');
520
+		$methodsBuffer  = '';
521
+
522
+		foreach ($_methods as $method) {
523
+			$nameStart = strpos($method, ' ') + 1;
524
+			$nameEnd   = strpos($method, '(');
525
+			$name      = substr($method, $nameStart, $nameEnd - $nameStart);
526
+
527
+			if (empty($methods) || in_array($name, $methods)) {
528
+				$args    = explode(
529
+					',',
530
+					substr(
531
+						$method,
532
+						$nameEnd + 1,
533
+						strpos($method, ')') - $nameEnd - 1
534
+					)
535
+				);
536
+
537
+				foreach (range(0, count($args) - 1) as $i) {
538
+					$args[$i] = substr($args[$i], strpos($args[$i], '$'));
539
+				}
540
+
541
+				$methodTemplate->setVar(
542
+					[
543
+						'method_name' => $name,
544
+						'arguments'   => implode(', ', $args)
545
+					]
546
+				);
547
+
548
+				$methodsBuffer .= $methodTemplate->render();
549
+			}
550
+		}
551
+
552
+		$optionsBuffer = 'array(';
553
+
554
+		foreach ($options as $key => $value) {
555
+			$optionsBuffer .= $key . ' => ' . $value;
556
+		}
557
+
558
+		$optionsBuffer .= ')';
559
+
560
+		$classTemplate = $this->getTemplate('wsdl_class.tpl');
561
+		$namespace     = '';
562
+
563
+		if (strpos($className, '\\') !== false) {
564
+			$parts     = explode('\\', $className);
565
+			$className = array_pop($parts);
566
+			$namespace = 'namespace ' . implode('\\', $parts) . ';' . "\n\n";
567
+		}
568
+
569
+		$classTemplate->setVar(
570
+			[
571
+				'namespace'  => $namespace,
572
+				'class_name' => $className,
573
+				'wsdl'       => $wsdlFile,
574
+				'options'    => $optionsBuffer,
575
+				'methods'    => $methodsBuffer
576
+			]
577
+		);
578
+
579
+		return $classTemplate->render();
580
+	}
581
+
582
+	/**
583
+	 * @param array|string $type
584
+	 * @param array|null   $methods
585
+	 * @param string       $mockClassName
586
+	 * @param bool         $callOriginalClone
587
+	 * @param bool         $callAutoload
588
+	 * @param bool         $cloneArguments
589
+	 * @param bool         $callOriginalMethods
590
+	 *
591
+	 * @return array
592
+	 *
593
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
594
+	 */
595
+	private function generateMock($type, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods)
596
+	{
597
+		$methodReflections   = [];
598
+		$classTemplate       = $this->getTemplate('mocked_class.tpl');
599
+
600
+		$additionalInterfaces = [];
601
+		$cloneTemplate        = '';
602
+		$isClass              = false;
603
+		$isInterface          = false;
604
+		$isMultipleInterfaces = false;
605
+
606
+		if (is_array($type)) {
607
+			foreach ($type as $_type) {
608
+				if (!interface_exists($_type, $callAutoload)) {
609
+					throw new PHPUnit_Framework_MockObject_RuntimeException(
610
+						sprintf(
611
+							'Interface "%s" does not exist.',
612
+							$_type
613
+						)
614
+					);
615
+				}
616
+
617
+				$isMultipleInterfaces = true;
618
+
619
+				$additionalInterfaces[] = $_type;
620
+				$typeClass              = new ReflectionClass($this->generateClassName(
621
+					$_type,
622
+					$mockClassName,
623
+					'Mock_'
624
+					)['fullClassName']
625
+				);
626
+
627
+				foreach ($this->getClassMethods($_type) as $method) {
628
+					if (in_array($method, $methods)) {
629
+						throw new PHPUnit_Framework_MockObject_RuntimeException(
630
+							sprintf(
631
+								'Duplicate method "%s" not allowed.',
632
+								$method
633
+							)
634
+						);
635
+					}
636
+
637
+					$methodReflections[$method] = $typeClass->getMethod($method);
638
+					$methods[]                  = $method;
639
+				}
640
+			}
641
+		}
642
+
643
+		$mockClassName = $this->generateClassName(
644
+			$type,
645
+			$mockClassName,
646
+			'Mock_'
647
+		);
648
+
649
+		if (class_exists($mockClassName['fullClassName'], $callAutoload)) {
650
+			$isClass = true;
651
+		} elseif (interface_exists($mockClassName['fullClassName'], $callAutoload)) {
652
+			$isInterface = true;
653
+		}
654
+
655
+		if (!$isClass && !$isInterface) {
656
+			$prologue = 'class ' . $mockClassName['originalClassName'] . "\n{\n}\n\n";
657
+
658
+			if (!empty($mockClassName['namespaceName'])) {
659
+				$prologue = 'namespace ' . $mockClassName['namespaceName'] .
660
+							" {\n\n" . $prologue . "}\n\n" .
661
+							"namespace {\n\n";
662
+
663
+				$epilogue = "\n\n}";
664
+			}
665
+
666
+			$cloneTemplate = $this->getTemplate('mocked_clone.tpl');
667
+		} else {
668
+			$class = new ReflectionClass($mockClassName['fullClassName']);
669
+
670
+			if ($class->isFinal()) {
671
+				throw new PHPUnit_Framework_MockObject_RuntimeException(
672
+					sprintf(
673
+						'Class "%s" is declared "final" and cannot be mocked.',
674
+						$mockClassName['fullClassName']
675
+					)
676
+				);
677
+			}
678
+
679
+			if ($class->hasMethod('__clone')) {
680
+				$cloneMethod = $class->getMethod('__clone');
681
+
682
+				if (!$cloneMethod->isFinal()) {
683
+					if ($callOriginalClone && !$isInterface) {
684
+						$cloneTemplate = $this->getTemplate('unmocked_clone.tpl');
685
+					} else {
686
+						$cloneTemplate = $this->getTemplate('mocked_clone.tpl');
687
+					}
688
+				}
689
+			} else {
690
+				$cloneTemplate = $this->getTemplate('mocked_clone.tpl');
691
+			}
692
+		}
693
+
694
+		if (is_object($cloneTemplate)) {
695
+			$cloneTemplate = $cloneTemplate->render();
696
+		}
697
+
698
+		if (is_array($methods) && empty($methods) &&
699
+			($isClass || $isInterface)) {
700
+			$methods = $this->getClassMethods($mockClassName['fullClassName']);
701
+		}
702
+
703
+		if (!is_array($methods)) {
704
+			$methods = [];
705
+		}
706
+
707
+		$mockedMethods = '';
708
+		$configurable  = [];
709
+
710
+		foreach ($methods as $methodName) {
711
+			if ($methodName != '__construct' && $methodName != '__clone') {
712
+				$configurable[] = strtolower($methodName);
713
+			}
714
+		}
715
+
716
+		if (isset($class)) {
717
+			// https://github.com/sebastianbergmann/phpunit-mock-objects/issues/103
718
+			if ($isInterface && $class->implementsInterface(Traversable::class) &&
719
+				!$class->implementsInterface(Iterator::class) &&
720
+				!$class->implementsInterface(IteratorAggregate::class)) {
721
+				$additionalInterfaces[] = Iterator::class;
722
+				$methods                = array_merge($methods, $this->getClassMethods(Iterator::class));
723
+			}
724
+
725
+			foreach ($methods as $methodName) {
726
+				try {
727
+					$method = $class->getMethod($methodName);
728
+
729
+					if ($this->canMockMethod($method)) {
730
+						$mockedMethods .= $this->generateMockedMethodDefinitionFromExisting(
731
+							$method,
732
+							$cloneArguments,
733
+							$callOriginalMethods
734
+						);
735
+					}
736
+				} catch (ReflectionException $e) {
737
+					$mockedMethods .= $this->generateMockedMethodDefinition(
738
+						$mockClassName['fullClassName'],
739
+						$methodName,
740
+						$cloneArguments
741
+					);
742
+				}
743
+			}
744
+		} elseif ($isMultipleInterfaces) {
745
+			foreach ($methods as $methodName) {
746
+				if ($this->canMockMethod($methodReflections[$methodName])) {
747
+					$mockedMethods .= $this->generateMockedMethodDefinitionFromExisting(
748
+						$methodReflections[$methodName],
749
+						$cloneArguments,
750
+						$callOriginalMethods
751
+					);
752
+				}
753
+			}
754
+		} else {
755
+			foreach ($methods as $methodName) {
756
+				$mockedMethods .= $this->generateMockedMethodDefinition(
757
+					$mockClassName['fullClassName'],
758
+					$methodName,
759
+					$cloneArguments
760
+				);
761
+			}
762
+		}
763
+
764
+		$method = '';
765
+
766
+		if (!in_array('method', $methods) && (!isset($class) || !$class->hasMethod('method'))) {
767
+			$methodTemplate = $this->getTemplate('mocked_class_method.tpl');
768
+
769
+			$method = $methodTemplate->render();
770
+		}
771
+
772
+		$classTemplate->setVar(
773
+			[
774
+				'prologue'          => isset($prologue) ? $prologue : '',
775
+				'epilogue'          => isset($epilogue) ? $epilogue : '',
776
+				'class_declaration' => $this->generateMockClassDeclaration(
777
+					$mockClassName,
778
+					$isInterface,
779
+					$additionalInterfaces
780
+				),
781
+				'clone'             => $cloneTemplate,
782
+				'mock_class_name'   => $mockClassName['className'],
783
+				'mocked_methods'    => $mockedMethods,
784
+				'method'            => $method,
785
+				'configurable'      => '[' . implode(', ', array_map(function ($m) {
786
+					return '\'' . $m . '\'';
787
+				}, $configurable)) . ']'
788
+			]
789
+		);
790
+
791
+		return [
792
+		  'code'          => $classTemplate->render(),
793
+		  'mockClassName' => $mockClassName['className']
794
+		];
795
+	}
796
+
797
+	/**
798
+	 * @param array|string $type
799
+	 * @param string       $className
800
+	 * @param string       $prefix
801
+	 *
802
+	 * @return array
803
+	 */
804
+	private function generateClassName($type, $className, $prefix)
805
+	{
806
+		if (is_array($type)) {
807
+			$type = implode('_', $type);
808
+		}
809
+
810
+		if ($type[0] == '\\') {
811
+			$type = substr($type, 1);
812
+		}
813
+
814
+		$classNameParts = explode('\\', $type);
815
+
816
+		if (count($classNameParts) > 1) {
817
+			$type          = array_pop($classNameParts);
818
+			$namespaceName = implode('\\', $classNameParts);
819
+			$fullClassName = $namespaceName . '\\' . $type;
820
+		} else {
821
+			$namespaceName = '';
822
+			$fullClassName = $type;
823
+		}
824
+
825
+		if ($className == '') {
826
+			do {
827
+				$className = $prefix . $type . '_' .
828
+							 substr(md5(mt_rand()), 0, 8);
829
+			} while (class_exists($className, false));
830
+		}
831
+
832
+		return [
833
+		  'className'         => $className,
834
+		  'originalClassName' => $type,
835
+		  'fullClassName'     => $fullClassName,
836
+		  'namespaceName'     => $namespaceName
837
+		];
838
+	}
839
+
840
+	/**
841
+	 * @param array $mockClassName
842
+	 * @param bool  $isInterface
843
+	 * @param array $additionalInterfaces
844
+	 *
845
+	 * @return string
846
+	 */
847
+	private function generateMockClassDeclaration(array $mockClassName, $isInterface, array $additionalInterfaces = [])
848
+	{
849
+		$buffer = 'class ';
850
+
851
+		$additionalInterfaces[] = 'PHPUnit_Framework_MockObject_MockObject';
852
+		$interfaces             = implode(', ', $additionalInterfaces);
853
+
854
+		if ($isInterface) {
855
+			$buffer .= sprintf(
856
+				'%s implements %s',
857
+				$mockClassName['className'],
858
+				$interfaces
859
+			);
860
+
861
+			if (!in_array($mockClassName['originalClassName'], $additionalInterfaces)) {
862
+				$buffer .= ', ';
863
+
864
+				if (!empty($mockClassName['namespaceName'])) {
865
+					$buffer .= $mockClassName['namespaceName'] . '\\';
866
+				}
867
+
868
+				$buffer .= $mockClassName['originalClassName'];
869
+			}
870
+		} else {
871
+			$buffer .= sprintf(
872
+				'%s extends %s%s implements %s',
873
+				$mockClassName['className'],
874
+				!empty($mockClassName['namespaceName']) ? $mockClassName['namespaceName'] . '\\' : '',
875
+				$mockClassName['originalClassName'],
876
+				$interfaces
877
+			);
878
+		}
879
+
880
+		return $buffer;
881
+	}
882
+
883
+	/**
884
+	 * @param ReflectionMethod $method
885
+	 * @param bool             $cloneArguments
886
+	 * @param bool             $callOriginalMethods
887
+	 *
888
+	 * @return string
889
+	 */
890
+	private function generateMockedMethodDefinitionFromExisting(ReflectionMethod $method, $cloneArguments, $callOriginalMethods)
891
+	{
892
+		if ($method->isPrivate()) {
893
+			$modifier = 'private';
894
+		} elseif ($method->isProtected()) {
895
+			$modifier = 'protected';
896
+		} else {
897
+			$modifier = 'public';
898
+		}
899
+
900
+		if ($method->isStatic()) {
901
+			$modifier .= ' static';
902
+		}
903
+
904
+		if ($method->returnsReference()) {
905
+			$reference = '&';
906
+		} else {
907
+			$reference = '';
908
+		}
909
+
910
+		if ($method->hasReturnType()) {
911
+			$returnType = (string) $method->getReturnType();
912
+		} else {
913
+			$returnType = '';
914
+		}
915
+
916
+		if (preg_match('#\*[ \t]*+@deprecated[ \t]*+(.*?)\r?+\n[ \t]*+\*(?:[ \t]*+@|/$)#s', $method->getDocComment(), $deprecation)) {
917
+			$deprecation = trim(preg_replace('#[ \t]*\r?\n[ \t]*+\*[ \t]*+#', ' ', $deprecation[1]));
918
+		} else {
919
+			$deprecation = false;
920
+		}
921
+
922
+		return $this->generateMockedMethodDefinition(
923
+			$method->getDeclaringClass()->getName(),
924
+			$method->getName(),
925
+			$cloneArguments,
926
+			$modifier,
927
+			$this->getMethodParameters($method),
928
+			$this->getMethodParameters($method, true),
929
+			$returnType,
930
+			$reference,
931
+			$callOriginalMethods,
932
+			$method->isStatic(),
933
+			$deprecation,
934
+			$method->hasReturnType() && $method->getReturnType()->allowsNull()
935
+		);
936
+	}
937
+
938
+	/**
939
+	 * @param string      $className
940
+	 * @param string      $methodName
941
+	 * @param bool        $cloneArguments
942
+	 * @param string      $modifier
943
+	 * @param string      $argumentsForDeclaration
944
+	 * @param string      $argumentsForCall
945
+	 * @param string      $returnType
946
+	 * @param string      $reference
947
+	 * @param bool        $callOriginalMethods
948
+	 * @param bool        $static
949
+	 * @param bool|string $deprecation
950
+	 * @param bool        $allowsReturnNull
951
+	 *
952
+	 * @return string
953
+	 */
954
+	private function generateMockedMethodDefinition($className, $methodName, $cloneArguments = true, $modifier = 'public', $argumentsForDeclaration = '', $argumentsForCall = '', $returnType = '', $reference = '', $callOriginalMethods = false, $static = false, $deprecation = false, $allowsReturnNull = false)
955
+	{
956
+		if ($static) {
957
+			$templateFile = 'mocked_static_method.tpl';
958
+		} else {
959
+			if ($returnType === 'void') {
960
+				$templateFile = sprintf(
961
+					'%s_method_void.tpl',
962
+					$callOriginalMethods ? 'proxied' : 'mocked'
963
+				);
964
+			} else {
965
+				$templateFile = sprintf(
966
+					'%s_method.tpl',
967
+					$callOriginalMethods ? 'proxied' : 'mocked'
968
+				);
969
+			}
970
+		}
971
+
972
+		// Mocked interfaces returning 'self' must explicitly declare the
973
+		// interface name as the return type. See
974
+		// https://bugs.php.net/bug.php?id=70722
975
+		if ($returnType === 'self') {
976
+			$returnType = $className;
977
+		}
978
+
979
+		if (false !== $deprecation) {
980
+			$deprecation         = "The $className::$methodName method is deprecated ($deprecation).";
981
+			$deprecationTemplate = $this->getTemplate('deprecation.tpl');
982
+
983
+			$deprecationTemplate->setVar(
984
+				[
985
+					'deprecation' => var_export($deprecation, true),
986
+				]
987
+			);
988
+
989
+			$deprecation = $deprecationTemplate->render();
990
+		}
991
+
992
+		$template = $this->getTemplate($templateFile);
993
+
994
+		$template->setVar(
995
+			[
996
+				'arguments_decl'  => $argumentsForDeclaration,
997
+				'arguments_call'  => $argumentsForCall,
998
+				'return_delim'    => $returnType ? ': ' : '',
999
+				'return_type'     => $allowsReturnNull ? '?' . $returnType : $returnType,
1000
+				'arguments_count' => !empty($argumentsForCall) ? count(explode(',', $argumentsForCall)) : 0,
1001
+				'class_name'      => $className,
1002
+				'method_name'     => $methodName,
1003
+				'modifier'        => $modifier,
1004
+				'reference'       => $reference,
1005
+				'clone_arguments' => $cloneArguments ? 'true' : 'false',
1006
+				'deprecation'     => $deprecation
1007
+			]
1008
+		);
1009
+
1010
+		return $template->render();
1011
+	}
1012
+
1013
+	/**
1014
+	 * @param ReflectionMethod $method
1015
+	 *
1016
+	 * @return bool
1017
+	 */
1018
+	private function canMockMethod(ReflectionMethod $method)
1019
+	{
1020
+		if ($method->isConstructor() ||
1021
+			$method->isFinal() ||
1022
+			$method->isPrivate() ||
1023
+			$this->isMethodNameBlacklisted($method->getName())) {
1024
+			return false;
1025
+		}
1026
+
1027
+		return true;
1028
+	}
1029
+
1030
+	/**
1031
+	 * Returns whether a method name is blacklisted
1032
+	 *
1033
+	 * @param string $name
1034
+	 *
1035
+	 * @return bool
1036
+	 */
1037
+	private function isMethodNameBlacklisted($name)
1038
+	{
1039
+		return isset($this->blacklistedMethodNames[$name]);
1040
+	}
1041
+
1042
+	/**
1043
+	 * Returns the parameters of a function or method.
1044
+	 *
1045
+	 * @param ReflectionMethod $method
1046
+	 * @param bool             $forCall
1047
+	 *
1048
+	 * @return string
1049
+	 *
1050
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
1051
+	 */
1052
+	private function getMethodParameters(ReflectionMethod $method, $forCall = false)
1053
+	{
1054
+		$parameters = [];
1055
+
1056
+		foreach ($method->getParameters() as $i => $parameter) {
1057
+			$name = '$' . $parameter->getName();
1058
+
1059
+			/* Note: PHP extensions may use empty names for reference arguments
1060 1060
              * or "..." for methods taking a variable number of arguments.
1061 1061
              */
1062
-            if ($name === '$' || $name === '$...') {
1063
-                $name = '$arg' . $i;
1064
-            }
1065
-
1066
-            if ($parameter->isVariadic()) {
1067
-                if ($forCall) {
1068
-                    continue;
1069
-                }
1070
-
1071
-                $name = '...' . $name;
1072
-            }
1073
-
1074
-            $nullable        = '';
1075
-            $default         = '';
1076
-            $reference       = '';
1077
-            $typeDeclaration = '';
1078
-
1079
-            if (!$forCall) {
1080
-                if ($parameter->hasType() && (string) $parameter->getType() !== 'self') {
1081
-                    if (version_compare(PHP_VERSION, '7.1', '>=') && $parameter->allowsNull()) {
1082
-                        $nullable = '?';
1083
-                    }
1084
-
1085
-                    $typeDeclaration = (string) $parameter->getType() . ' ';
1086
-                } elseif ($parameter->isArray()) {
1087
-                    $typeDeclaration = 'array ';
1088
-                } elseif ($parameter->isCallable()) {
1089
-                    $typeDeclaration = 'callable ';
1090
-                } else {
1091
-                    try {
1092
-                        $class = $parameter->getClass();
1093
-                    } catch (ReflectionException $e) {
1094
-                        throw new PHPUnit_Framework_MockObject_RuntimeException(
1095
-                            sprintf(
1096
-                                'Cannot mock %s::%s() because a class or ' .
1097
-                                'interface used in the signature is not loaded',
1098
-                                $method->getDeclaringClass()->getName(),
1099
-                                $method->getName()
1100
-                            ),
1101
-                            0,
1102
-                            $e
1103
-                        );
1104
-                    }
1105
-
1106
-                    if ($class !== null) {
1107
-                        $typeDeclaration = $class->getName() . ' ';
1108
-                    }
1109
-                }
1110
-
1111
-                if (!$parameter->isVariadic()) {
1112
-                    if ($parameter->isDefaultValueAvailable()) {
1113
-                        $value   = $parameter->getDefaultValue();
1114
-                        $default = ' = ' . var_export($value, true);
1115
-                    } elseif ($parameter->isOptional()) {
1116
-                        $default = ' = null';
1117
-                    }
1118
-                }
1119
-            }
1120
-
1121
-            if ($parameter->isPassedByReference()) {
1122
-                $reference = '&';
1123
-            }
1124
-
1125
-            $parameters[] = $nullable . $typeDeclaration . $reference . $name . $default;
1126
-        }
1127
-
1128
-        return implode(', ', $parameters);
1129
-    }
1130
-
1131
-    /**
1132
-     * @param string $className
1133
-     *
1134
-     * @return array
1135
-     */
1136
-    public function getClassMethods($className)
1137
-    {
1138
-        $class   = new ReflectionClass($className);
1139
-        $methods = [];
1140
-
1141
-        foreach ($class->getMethods() as $method) {
1142
-            if ($method->isPublic() || $method->isAbstract()) {
1143
-                $methods[] = $method->getName();
1144
-            }
1145
-        }
1146
-
1147
-        return $methods;
1148
-    }
1149
-
1150
-    /**
1151
-     * @param string $template
1152
-     *
1153
-     * @return Text_Template
1154
-     */
1155
-    private function getTemplate($template)
1156
-    {
1157
-        $filename = __DIR__ . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR . $template;
1158
-
1159
-        if (!isset(self::$templates[$filename])) {
1160
-            self::$templates[$filename] = new Text_Template($filename);
1161
-        }
1162
-
1163
-        return self::$templates[$filename];
1164
-    }
1062
+			if ($name === '$' || $name === '$...') {
1063
+				$name = '$arg' . $i;
1064
+			}
1065
+
1066
+			if ($parameter->isVariadic()) {
1067
+				if ($forCall) {
1068
+					continue;
1069
+				}
1070
+
1071
+				$name = '...' . $name;
1072
+			}
1073
+
1074
+			$nullable        = '';
1075
+			$default         = '';
1076
+			$reference       = '';
1077
+			$typeDeclaration = '';
1078
+
1079
+			if (!$forCall) {
1080
+				if ($parameter->hasType() && (string) $parameter->getType() !== 'self') {
1081
+					if (version_compare(PHP_VERSION, '7.1', '>=') && $parameter->allowsNull()) {
1082
+						$nullable = '?';
1083
+					}
1084
+
1085
+					$typeDeclaration = (string) $parameter->getType() . ' ';
1086
+				} elseif ($parameter->isArray()) {
1087
+					$typeDeclaration = 'array ';
1088
+				} elseif ($parameter->isCallable()) {
1089
+					$typeDeclaration = 'callable ';
1090
+				} else {
1091
+					try {
1092
+						$class = $parameter->getClass();
1093
+					} catch (ReflectionException $e) {
1094
+						throw new PHPUnit_Framework_MockObject_RuntimeException(
1095
+							sprintf(
1096
+								'Cannot mock %s::%s() because a class or ' .
1097
+								'interface used in the signature is not loaded',
1098
+								$method->getDeclaringClass()->getName(),
1099
+								$method->getName()
1100
+							),
1101
+							0,
1102
+							$e
1103
+						);
1104
+					}
1105
+
1106
+					if ($class !== null) {
1107
+						$typeDeclaration = $class->getName() . ' ';
1108
+					}
1109
+				}
1110
+
1111
+				if (!$parameter->isVariadic()) {
1112
+					if ($parameter->isDefaultValueAvailable()) {
1113
+						$value   = $parameter->getDefaultValue();
1114
+						$default = ' = ' . var_export($value, true);
1115
+					} elseif ($parameter->isOptional()) {
1116
+						$default = ' = null';
1117
+					}
1118
+				}
1119
+			}
1120
+
1121
+			if ($parameter->isPassedByReference()) {
1122
+				$reference = '&';
1123
+			}
1124
+
1125
+			$parameters[] = $nullable . $typeDeclaration . $reference . $name . $default;
1126
+		}
1127
+
1128
+		return implode(', ', $parameters);
1129
+	}
1130
+
1131
+	/**
1132
+	 * @param string $className
1133
+	 *
1134
+	 * @return array
1135
+	 */
1136
+	public function getClassMethods($className)
1137
+	{
1138
+		$class   = new ReflectionClass($className);
1139
+		$methods = [];
1140
+
1141
+		foreach ($class->getMethods() as $method) {
1142
+			if ($method->isPublic() || $method->isAbstract()) {
1143
+				$methods[] = $method->getName();
1144
+			}
1145
+		}
1146
+
1147
+		return $methods;
1148
+	}
1149
+
1150
+	/**
1151
+	 * @param string $template
1152
+	 *
1153
+	 * @return Text_Template
1154
+	 */
1155
+	private function getTemplate($template)
1156
+	{
1157
+		$filename = __DIR__ . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR . $template;
1158
+
1159
+		if (!isset(self::$templates[$filename])) {
1160
+			self::$templates[$filename] = new Text_Template($filename);
1161
+		}
1162
+
1163
+		return self::$templates[$filename];
1164
+	}
1165 1165
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
         if (is_array($type)) {
87 87
             $type = array_unique(
88 88
                 array_map(
89
-                    function ($type) {
89
+                    function($type) {
90 90
                         if ($type === 'Traversable' ||
91 91
                             $type === '\\Traversable' ||
92 92
                             $type === '\\Iterator') {
@@ -462,10 +462,10 @@  discard block
 block discarded – undo
462 462
 
463 463
         if ($mockClassName == '') {
464 464
             $key = md5(
465
-                is_array($type) ? implode('_', $type) : $type .
466
-                serialize($methods) .
467
-                serialize($callOriginalClone) .
468
-                serialize($cloneArguments) .
465
+                is_array($type) ? implode('_', $type) : $type.
466
+                serialize($methods).
467
+                serialize($callOriginalClone).
468
+                serialize($cloneArguments).
469 469
                 serialize($callOriginalMethods)
470 470
             );
471 471
 
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
             $name      = substr($method, $nameStart, $nameEnd - $nameStart);
526 526
 
527 527
             if (empty($methods) || in_array($name, $methods)) {
528
-                $args    = explode(
528
+                $args = explode(
529 529
                     ',',
530 530
                     substr(
531 531
                         $method,
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
         $optionsBuffer = 'array(';
553 553
 
554 554
         foreach ($options as $key => $value) {
555
-            $optionsBuffer .= $key . ' => ' . $value;
555
+            $optionsBuffer .= $key.' => '.$value;
556 556
         }
557 557
 
558 558
         $optionsBuffer .= ')';
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
         if (strpos($className, '\\') !== false) {
564 564
             $parts     = explode('\\', $className);
565 565
             $className = array_pop($parts);
566
-            $namespace = 'namespace ' . implode('\\', $parts) . ';' . "\n\n";
566
+            $namespace = 'namespace '.implode('\\', $parts).';'."\n\n";
567 567
         }
568 568
 
569 569
         $classTemplate->setVar(
@@ -653,11 +653,11 @@  discard block
 block discarded – undo
653 653
         }
654 654
 
655 655
         if (!$isClass && !$isInterface) {
656
-            $prologue = 'class ' . $mockClassName['originalClassName'] . "\n{\n}\n\n";
656
+            $prologue = 'class '.$mockClassName['originalClassName']."\n{\n}\n\n";
657 657
 
658 658
             if (!empty($mockClassName['namespaceName'])) {
659
-                $prologue = 'namespace ' . $mockClassName['namespaceName'] .
660
-                            " {\n\n" . $prologue . "}\n\n" .
659
+                $prologue = 'namespace '.$mockClassName['namespaceName'].
660
+                            " {\n\n".$prologue."}\n\n".
661 661
                             "namespace {\n\n";
662 662
 
663 663
                 $epilogue = "\n\n}";
@@ -782,9 +782,9 @@  discard block
 block discarded – undo
782 782
                 'mock_class_name'   => $mockClassName['className'],
783 783
                 'mocked_methods'    => $mockedMethods,
784 784
                 'method'            => $method,
785
-                'configurable'      => '[' . implode(', ', array_map(function ($m) {
786
-                    return '\'' . $m . '\'';
787
-                }, $configurable)) . ']'
785
+                'configurable'      => '['.implode(', ', array_map(function($m) {
786
+                    return '\''.$m.'\'';
787
+                }, $configurable)).']'
788 788
             ]
789 789
         );
790 790
 
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
         if (count($classNameParts) > 1) {
817 817
             $type          = array_pop($classNameParts);
818 818
             $namespaceName = implode('\\', $classNameParts);
819
-            $fullClassName = $namespaceName . '\\' . $type;
819
+            $fullClassName = $namespaceName.'\\'.$type;
820 820
         } else {
821 821
             $namespaceName = '';
822 822
             $fullClassName = $type;
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 
825 825
         if ($className == '') {
826 826
             do {
827
-                $className = $prefix . $type . '_' .
827
+                $className = $prefix.$type.'_'.
828 828
                              substr(md5(mt_rand()), 0, 8);
829 829
             } while (class_exists($className, false));
830 830
         }
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
                 $buffer .= ', ';
863 863
 
864 864
                 if (!empty($mockClassName['namespaceName'])) {
865
-                    $buffer .= $mockClassName['namespaceName'] . '\\';
865
+                    $buffer .= $mockClassName['namespaceName'].'\\';
866 866
                 }
867 867
 
868 868
                 $buffer .= $mockClassName['originalClassName'];
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
             $buffer .= sprintf(
872 872
                 '%s extends %s%s implements %s',
873 873
                 $mockClassName['className'],
874
-                !empty($mockClassName['namespaceName']) ? $mockClassName['namespaceName'] . '\\' : '',
874
+                !empty($mockClassName['namespaceName']) ? $mockClassName['namespaceName'].'\\' : '',
875 875
                 $mockClassName['originalClassName'],
876 876
                 $interfaces
877 877
             );
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
                 'arguments_decl'  => $argumentsForDeclaration,
997 997
                 'arguments_call'  => $argumentsForCall,
998 998
                 'return_delim'    => $returnType ? ': ' : '',
999
-                'return_type'     => $allowsReturnNull ? '?' . $returnType : $returnType,
999
+                'return_type'     => $allowsReturnNull ? '?'.$returnType : $returnType,
1000 1000
                 'arguments_count' => !empty($argumentsForCall) ? count(explode(',', $argumentsForCall)) : 0,
1001 1001
                 'class_name'      => $className,
1002 1002
                 'method_name'     => $methodName,
@@ -1054,13 +1054,13 @@  discard block
 block discarded – undo
1054 1054
         $parameters = [];
1055 1055
 
1056 1056
         foreach ($method->getParameters() as $i => $parameter) {
1057
-            $name = '$' . $parameter->getName();
1057
+            $name = '$'.$parameter->getName();
1058 1058
 
1059 1059
             /* Note: PHP extensions may use empty names for reference arguments
1060 1060
              * or "..." for methods taking a variable number of arguments.
1061 1061
              */
1062 1062
             if ($name === '$' || $name === '$...') {
1063
-                $name = '$arg' . $i;
1063
+                $name = '$arg'.$i;
1064 1064
             }
1065 1065
 
1066 1066
             if ($parameter->isVariadic()) {
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
                     continue;
1069 1069
                 }
1070 1070
 
1071
-                $name = '...' . $name;
1071
+                $name = '...'.$name;
1072 1072
             }
1073 1073
 
1074 1074
             $nullable        = '';
@@ -1082,7 +1082,7 @@  discard block
 block discarded – undo
1082 1082
                         $nullable = '?';
1083 1083
                     }
1084 1084
 
1085
-                    $typeDeclaration = (string) $parameter->getType() . ' ';
1085
+                    $typeDeclaration = (string) $parameter->getType().' ';
1086 1086
                 } elseif ($parameter->isArray()) {
1087 1087
                     $typeDeclaration = 'array ';
1088 1088
                 } elseif ($parameter->isCallable()) {
@@ -1093,7 +1093,7 @@  discard block
 block discarded – undo
1093 1093
                     } catch (ReflectionException $e) {
1094 1094
                         throw new PHPUnit_Framework_MockObject_RuntimeException(
1095 1095
                             sprintf(
1096
-                                'Cannot mock %s::%s() because a class or ' .
1096
+                                'Cannot mock %s::%s() because a class or '.
1097 1097
                                 'interface used in the signature is not loaded',
1098 1098
                                 $method->getDeclaringClass()->getName(),
1099 1099
                                 $method->getName()
@@ -1104,14 +1104,14 @@  discard block
 block discarded – undo
1104 1104
                     }
1105 1105
 
1106 1106
                     if ($class !== null) {
1107
-                        $typeDeclaration = $class->getName() . ' ';
1107
+                        $typeDeclaration = $class->getName().' ';
1108 1108
                     }
1109 1109
                 }
1110 1110
 
1111 1111
                 if (!$parameter->isVariadic()) {
1112 1112
                     if ($parameter->isDefaultValueAvailable()) {
1113 1113
                         $value   = $parameter->getDefaultValue();
1114
-                        $default = ' = ' . var_export($value, true);
1114
+                        $default = ' = '.var_export($value, true);
1115 1115
                     } elseif ($parameter->isOptional()) {
1116 1116
                         $default = ' = null';
1117 1117
                     }
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
                 $reference = '&';
1123 1123
             }
1124 1124
 
1125
-            $parameters[] = $nullable . $typeDeclaration . $reference . $name . $default;
1125
+            $parameters[] = $nullable.$typeDeclaration.$reference.$name.$default;
1126 1126
         }
1127 1127
 
1128 1128
         return implode(', ', $parameters);
@@ -1154,7 +1154,7 @@  discard block
 block discarded – undo
1154 1154
      */
1155 1155
     private function getTemplate($template)
1156 1156
     {
1157
-        $filename = __DIR__ . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR . $template;
1157
+        $filename = __DIR__.DIRECTORY_SEPARATOR.'Generator'.DIRECTORY_SEPARATOR.$template;
1158 1158
 
1159 1159
         if (!isset(self::$templates[$filename])) {
1160 1160
             self::$templates[$filename] = new Text_Template($filename);
Please login to merge, or discard this patch.
vendor/phpunit/phpunit-mock-objects/src/Verifiable.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@
 block discarded – undo
15 15
  */
16 16
 interface PHPUnit_Framework_MockObject_Verifiable
17 17
 {
18
-    /**
19
-     * Verifies that the current expectation is valid. If everything is OK the
20
-     * code should just return, if not it must throw an exception.
21
-     *
22
-     * @throws ExpectationFailedException
23
-     */
24
-    public function verify();
18
+	/**
19
+	 * Verifies that the current expectation is valid. If everything is OK the
20
+	 * code should just return, if not it must throw an exception.
21
+	 *
22
+	 * @throws ExpectationFailedException
23
+	 */
24
+	public function verify();
25 25
 }
Please login to merge, or discard this patch.
vendor/phpunit/phpunit-mock-objects/src/Invokable.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -16,22 +16,22 @@
 block discarded – undo
16 16
  */
17 17
 interface PHPUnit_Framework_MockObject_Invokable extends PHPUnit_Framework_MockObject_Verifiable
18 18
 {
19
-    /**
20
-     * Invokes the invocation object $invocation so that it can be checked for
21
-     * expectations or matched against stubs.
22
-     *
23
-     * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation object passed from mock object
24
-     *
25
-     * @return object
26
-     */
27
-    public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation);
19
+	/**
20
+	 * Invokes the invocation object $invocation so that it can be checked for
21
+	 * expectations or matched against stubs.
22
+	 *
23
+	 * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation object passed from mock object
24
+	 *
25
+	 * @return object
26
+	 */
27
+	public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation);
28 28
 
29
-    /**
30
-     * Checks if the invocation matches.
31
-     *
32
-     * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation object passed from mock object
33
-     *
34
-     * @return bool
35
-     */
36
-    public function matches(PHPUnit_Framework_MockObject_Invocation $invocation);
29
+	/**
30
+	 * Checks if the invocation matches.
31
+	 *
32
+	 * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation object passed from mock object
33
+	 *
34
+	 * @return bool
35
+	 */
36
+	public function matches(PHPUnit_Framework_MockObject_Invocation $invocation);
37 37
 }
Please login to merge, or discard this patch.
vendor/phpunit/phpunit-mock-objects/src/MockBuilder.php 1 patch
Indentation   +370 added lines, -370 removed lines patch added patch discarded remove patch
@@ -15,374 +15,374 @@
 block discarded – undo
15 15
  */
16 16
 class PHPUnit_Framework_MockObject_MockBuilder
17 17
 {
18
-    /**
19
-     * @var TestCase
20
-     */
21
-    private $testCase;
22
-
23
-    /**
24
-     * @var string
25
-     */
26
-    private $type;
27
-
28
-    /**
29
-     * @var array
30
-     */
31
-    private $methods = [];
32
-
33
-    /**
34
-     * @var array
35
-     */
36
-    private $methodsExcept = [];
37
-
38
-    /**
39
-     * @var string
40
-     */
41
-    private $mockClassName = '';
42
-
43
-    /**
44
-     * @var array
45
-     */
46
-    private $constructorArgs = [];
47
-
48
-    /**
49
-     * @var bool
50
-     */
51
-    private $originalConstructor = true;
52
-
53
-    /**
54
-     * @var bool
55
-     */
56
-    private $originalClone = true;
57
-
58
-    /**
59
-     * @var bool
60
-     */
61
-    private $autoload = true;
62
-
63
-    /**
64
-     * @var bool
65
-     */
66
-    private $cloneArguments = false;
67
-
68
-    /**
69
-     * @var bool
70
-     */
71
-    private $callOriginalMethods = false;
72
-
73
-    /**
74
-     * @var object
75
-     */
76
-    private $proxyTarget = null;
77
-
78
-    /**
79
-     * @var bool
80
-     */
81
-    private $allowMockingUnknownTypes = true;
82
-
83
-    /**
84
-     * @var PHPUnit_Framework_MockObject_Generator
85
-     */
86
-    private $generator;
87
-
88
-    /**
89
-     * @param TestCase     $testCase
90
-     * @param array|string $type
91
-     */
92
-    public function __construct(TestCase $testCase, $type)
93
-    {
94
-        $this->testCase  = $testCase;
95
-        $this->type      = $type;
96
-        $this->generator = new PHPUnit_Framework_MockObject_Generator;
97
-    }
98
-
99
-    /**
100
-     * Creates a mock object using a fluent interface.
101
-     *
102
-     * @return PHPUnit_Framework_MockObject_MockObject
103
-     */
104
-    public function getMock()
105
-    {
106
-        $object = $this->generator->getMock(
107
-            $this->type,
108
-            $this->methods,
109
-            $this->constructorArgs,
110
-            $this->mockClassName,
111
-            $this->originalConstructor,
112
-            $this->originalClone,
113
-            $this->autoload,
114
-            $this->cloneArguments,
115
-            $this->callOriginalMethods,
116
-            $this->proxyTarget,
117
-            $this->allowMockingUnknownTypes
118
-        );
119
-
120
-        $this->testCase->registerMockObject($object);
121
-
122
-        return $object;
123
-    }
124
-
125
-    /**
126
-     * Creates a mock object for an abstract class using a fluent interface.
127
-     *
128
-     * @return PHPUnit_Framework_MockObject_MockObject
129
-     */
130
-    public function getMockForAbstractClass()
131
-    {
132
-        $object = $this->generator->getMockForAbstractClass(
133
-            $this->type,
134
-            $this->constructorArgs,
135
-            $this->mockClassName,
136
-            $this->originalConstructor,
137
-            $this->originalClone,
138
-            $this->autoload,
139
-            $this->methods,
140
-            $this->cloneArguments
141
-        );
142
-
143
-        $this->testCase->registerMockObject($object);
144
-
145
-        return $object;
146
-    }
147
-
148
-    /**
149
-     * Creates a mock object for a trait using a fluent interface.
150
-     *
151
-     * @return PHPUnit_Framework_MockObject_MockObject
152
-     */
153
-    public function getMockForTrait()
154
-    {
155
-        $object = $this->generator->getMockForTrait(
156
-            $this->type,
157
-            $this->constructorArgs,
158
-            $this->mockClassName,
159
-            $this->originalConstructor,
160
-            $this->originalClone,
161
-            $this->autoload,
162
-            $this->methods,
163
-            $this->cloneArguments
164
-        );
165
-
166
-        $this->testCase->registerMockObject($object);
167
-
168
-        return $object;
169
-    }
170
-
171
-    /**
172
-     * Specifies the subset of methods to mock. Default is to mock all of them.
173
-     *
174
-     * @param array|null $methods
175
-     *
176
-     * @return PHPUnit_Framework_MockObject_MockBuilder
177
-     */
178
-    public function setMethods(array $methods = null)
179
-    {
180
-        $this->methods = $methods;
181
-
182
-        return $this;
183
-    }
184
-
185
-    /**
186
-     * Specifies the subset of methods to not mock. Default is to mock all of them.
187
-     *
188
-     * @param array $methods
189
-     *
190
-     * @return PHPUnit_Framework_MockObject_MockBuilder
191
-     */
192
-    public function setMethodsExcept(array $methods = [])
193
-    {
194
-        $this->methodsExcept = $methods;
195
-
196
-        $this->setMethods(
197
-            array_diff(
198
-                $this->generator->getClassMethods($this->type),
199
-                $this->methodsExcept
200
-            )
201
-        );
202
-
203
-        return $this;
204
-    }
205
-
206
-    /**
207
-     * Specifies the arguments for the constructor.
208
-     *
209
-     * @param array $args
210
-     *
211
-     * @return PHPUnit_Framework_MockObject_MockBuilder
212
-     */
213
-    public function setConstructorArgs(array $args)
214
-    {
215
-        $this->constructorArgs = $args;
216
-
217
-        return $this;
218
-    }
219
-
220
-    /**
221
-     * Specifies the name for the mock class.
222
-     *
223
-     * @param string $name
224
-     *
225
-     * @return PHPUnit_Framework_MockObject_MockBuilder
226
-     */
227
-    public function setMockClassName($name)
228
-    {
229
-        $this->mockClassName = $name;
230
-
231
-        return $this;
232
-    }
233
-
234
-    /**
235
-     * Disables the invocation of the original constructor.
236
-     *
237
-     * @return PHPUnit_Framework_MockObject_MockBuilder
238
-     */
239
-    public function disableOriginalConstructor()
240
-    {
241
-        $this->originalConstructor = false;
242
-
243
-        return $this;
244
-    }
245
-
246
-    /**
247
-     * Enables the invocation of the original constructor.
248
-     *
249
-     * @return PHPUnit_Framework_MockObject_MockBuilder
250
-     */
251
-    public function enableOriginalConstructor()
252
-    {
253
-        $this->originalConstructor = true;
254
-
255
-        return $this;
256
-    }
257
-
258
-    /**
259
-     * Disables the invocation of the original clone constructor.
260
-     *
261
-     * @return PHPUnit_Framework_MockObject_MockBuilder
262
-     */
263
-    public function disableOriginalClone()
264
-    {
265
-        $this->originalClone = false;
266
-
267
-        return $this;
268
-    }
269
-
270
-    /**
271
-     * Enables the invocation of the original clone constructor.
272
-     *
273
-     * @return PHPUnit_Framework_MockObject_MockBuilder
274
-     */
275
-    public function enableOriginalClone()
276
-    {
277
-        $this->originalClone = true;
278
-
279
-        return $this;
280
-    }
281
-
282
-    /**
283
-     * Disables the use of class autoloading while creating the mock object.
284
-     *
285
-     * @return PHPUnit_Framework_MockObject_MockBuilder
286
-     */
287
-    public function disableAutoload()
288
-    {
289
-        $this->autoload = false;
290
-
291
-        return $this;
292
-    }
293
-
294
-    /**
295
-     * Enables the use of class autoloading while creating the mock object.
296
-     *
297
-     * @return PHPUnit_Framework_MockObject_MockBuilder
298
-     */
299
-    public function enableAutoload()
300
-    {
301
-        $this->autoload = true;
302
-
303
-        return $this;
304
-    }
305
-
306
-    /**
307
-     * Disables the cloning of arguments passed to mocked methods.
308
-     *
309
-     * @return PHPUnit_Framework_MockObject_MockBuilder
310
-     */
311
-    public function disableArgumentCloning()
312
-    {
313
-        $this->cloneArguments = false;
314
-
315
-        return $this;
316
-    }
317
-
318
-    /**
319
-     * Enables the cloning of arguments passed to mocked methods.
320
-     *
321
-     * @return PHPUnit_Framework_MockObject_MockBuilder
322
-     */
323
-    public function enableArgumentCloning()
324
-    {
325
-        $this->cloneArguments = true;
326
-
327
-        return $this;
328
-    }
329
-
330
-    /**
331
-     * Enables the invocation of the original methods.
332
-     *
333
-     * @return PHPUnit_Framework_MockObject_MockBuilder
334
-     */
335
-    public function enableProxyingToOriginalMethods()
336
-    {
337
-        $this->callOriginalMethods = true;
338
-
339
-        return $this;
340
-    }
341
-
342
-    /**
343
-     * Disables the invocation of the original methods.
344
-     *
345
-     * @return PHPUnit_Framework_MockObject_MockBuilder
346
-     */
347
-    public function disableProxyingToOriginalMethods()
348
-    {
349
-        $this->callOriginalMethods = false;
350
-        $this->proxyTarget         = null;
351
-
352
-        return $this;
353
-    }
354
-
355
-    /**
356
-     * Sets the proxy target.
357
-     *
358
-     * @param object $object
359
-     *
360
-     * @return PHPUnit_Framework_MockObject_MockBuilder
361
-     */
362
-    public function setProxyTarget($object)
363
-    {
364
-        $this->proxyTarget = $object;
365
-
366
-        return $this;
367
-    }
368
-
369
-    /**
370
-     * @return PHPUnit_Framework_MockObject_MockBuilder
371
-     */
372
-    public function allowMockingUnknownTypes()
373
-    {
374
-        $this->allowMockingUnknownTypes = true;
375
-
376
-        return $this;
377
-    }
378
-
379
-    /**
380
-     * @return PHPUnit_Framework_MockObject_MockBuilder
381
-     */
382
-    public function disallowMockingUnknownTypes()
383
-    {
384
-        $this->allowMockingUnknownTypes = false;
385
-
386
-        return $this;
387
-    }
18
+	/**
19
+	 * @var TestCase
20
+	 */
21
+	private $testCase;
22
+
23
+	/**
24
+	 * @var string
25
+	 */
26
+	private $type;
27
+
28
+	/**
29
+	 * @var array
30
+	 */
31
+	private $methods = [];
32
+
33
+	/**
34
+	 * @var array
35
+	 */
36
+	private $methodsExcept = [];
37
+
38
+	/**
39
+	 * @var string
40
+	 */
41
+	private $mockClassName = '';
42
+
43
+	/**
44
+	 * @var array
45
+	 */
46
+	private $constructorArgs = [];
47
+
48
+	/**
49
+	 * @var bool
50
+	 */
51
+	private $originalConstructor = true;
52
+
53
+	/**
54
+	 * @var bool
55
+	 */
56
+	private $originalClone = true;
57
+
58
+	/**
59
+	 * @var bool
60
+	 */
61
+	private $autoload = true;
62
+
63
+	/**
64
+	 * @var bool
65
+	 */
66
+	private $cloneArguments = false;
67
+
68
+	/**
69
+	 * @var bool
70
+	 */
71
+	private $callOriginalMethods = false;
72
+
73
+	/**
74
+	 * @var object
75
+	 */
76
+	private $proxyTarget = null;
77
+
78
+	/**
79
+	 * @var bool
80
+	 */
81
+	private $allowMockingUnknownTypes = true;
82
+
83
+	/**
84
+	 * @var PHPUnit_Framework_MockObject_Generator
85
+	 */
86
+	private $generator;
87
+
88
+	/**
89
+	 * @param TestCase     $testCase
90
+	 * @param array|string $type
91
+	 */
92
+	public function __construct(TestCase $testCase, $type)
93
+	{
94
+		$this->testCase  = $testCase;
95
+		$this->type      = $type;
96
+		$this->generator = new PHPUnit_Framework_MockObject_Generator;
97
+	}
98
+
99
+	/**
100
+	 * Creates a mock object using a fluent interface.
101
+	 *
102
+	 * @return PHPUnit_Framework_MockObject_MockObject
103
+	 */
104
+	public function getMock()
105
+	{
106
+		$object = $this->generator->getMock(
107
+			$this->type,
108
+			$this->methods,
109
+			$this->constructorArgs,
110
+			$this->mockClassName,
111
+			$this->originalConstructor,
112
+			$this->originalClone,
113
+			$this->autoload,
114
+			$this->cloneArguments,
115
+			$this->callOriginalMethods,
116
+			$this->proxyTarget,
117
+			$this->allowMockingUnknownTypes
118
+		);
119
+
120
+		$this->testCase->registerMockObject($object);
121
+
122
+		return $object;
123
+	}
124
+
125
+	/**
126
+	 * Creates a mock object for an abstract class using a fluent interface.
127
+	 *
128
+	 * @return PHPUnit_Framework_MockObject_MockObject
129
+	 */
130
+	public function getMockForAbstractClass()
131
+	{
132
+		$object = $this->generator->getMockForAbstractClass(
133
+			$this->type,
134
+			$this->constructorArgs,
135
+			$this->mockClassName,
136
+			$this->originalConstructor,
137
+			$this->originalClone,
138
+			$this->autoload,
139
+			$this->methods,
140
+			$this->cloneArguments
141
+		);
142
+
143
+		$this->testCase->registerMockObject($object);
144
+
145
+		return $object;
146
+	}
147
+
148
+	/**
149
+	 * Creates a mock object for a trait using a fluent interface.
150
+	 *
151
+	 * @return PHPUnit_Framework_MockObject_MockObject
152
+	 */
153
+	public function getMockForTrait()
154
+	{
155
+		$object = $this->generator->getMockForTrait(
156
+			$this->type,
157
+			$this->constructorArgs,
158
+			$this->mockClassName,
159
+			$this->originalConstructor,
160
+			$this->originalClone,
161
+			$this->autoload,
162
+			$this->methods,
163
+			$this->cloneArguments
164
+		);
165
+
166
+		$this->testCase->registerMockObject($object);
167
+
168
+		return $object;
169
+	}
170
+
171
+	/**
172
+	 * Specifies the subset of methods to mock. Default is to mock all of them.
173
+	 *
174
+	 * @param array|null $methods
175
+	 *
176
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
177
+	 */
178
+	public function setMethods(array $methods = null)
179
+	{
180
+		$this->methods = $methods;
181
+
182
+		return $this;
183
+	}
184
+
185
+	/**
186
+	 * Specifies the subset of methods to not mock. Default is to mock all of them.
187
+	 *
188
+	 * @param array $methods
189
+	 *
190
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
191
+	 */
192
+	public function setMethodsExcept(array $methods = [])
193
+	{
194
+		$this->methodsExcept = $methods;
195
+
196
+		$this->setMethods(
197
+			array_diff(
198
+				$this->generator->getClassMethods($this->type),
199
+				$this->methodsExcept
200
+			)
201
+		);
202
+
203
+		return $this;
204
+	}
205
+
206
+	/**
207
+	 * Specifies the arguments for the constructor.
208
+	 *
209
+	 * @param array $args
210
+	 *
211
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
212
+	 */
213
+	public function setConstructorArgs(array $args)
214
+	{
215
+		$this->constructorArgs = $args;
216
+
217
+		return $this;
218
+	}
219
+
220
+	/**
221
+	 * Specifies the name for the mock class.
222
+	 *
223
+	 * @param string $name
224
+	 *
225
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
226
+	 */
227
+	public function setMockClassName($name)
228
+	{
229
+		$this->mockClassName = $name;
230
+
231
+		return $this;
232
+	}
233
+
234
+	/**
235
+	 * Disables the invocation of the original constructor.
236
+	 *
237
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
238
+	 */
239
+	public function disableOriginalConstructor()
240
+	{
241
+		$this->originalConstructor = false;
242
+
243
+		return $this;
244
+	}
245
+
246
+	/**
247
+	 * Enables the invocation of the original constructor.
248
+	 *
249
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
250
+	 */
251
+	public function enableOriginalConstructor()
252
+	{
253
+		$this->originalConstructor = true;
254
+
255
+		return $this;
256
+	}
257
+
258
+	/**
259
+	 * Disables the invocation of the original clone constructor.
260
+	 *
261
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
262
+	 */
263
+	public function disableOriginalClone()
264
+	{
265
+		$this->originalClone = false;
266
+
267
+		return $this;
268
+	}
269
+
270
+	/**
271
+	 * Enables the invocation of the original clone constructor.
272
+	 *
273
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
274
+	 */
275
+	public function enableOriginalClone()
276
+	{
277
+		$this->originalClone = true;
278
+
279
+		return $this;
280
+	}
281
+
282
+	/**
283
+	 * Disables the use of class autoloading while creating the mock object.
284
+	 *
285
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
286
+	 */
287
+	public function disableAutoload()
288
+	{
289
+		$this->autoload = false;
290
+
291
+		return $this;
292
+	}
293
+
294
+	/**
295
+	 * Enables the use of class autoloading while creating the mock object.
296
+	 *
297
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
298
+	 */
299
+	public function enableAutoload()
300
+	{
301
+		$this->autoload = true;
302
+
303
+		return $this;
304
+	}
305
+
306
+	/**
307
+	 * Disables the cloning of arguments passed to mocked methods.
308
+	 *
309
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
310
+	 */
311
+	public function disableArgumentCloning()
312
+	{
313
+		$this->cloneArguments = false;
314
+
315
+		return $this;
316
+	}
317
+
318
+	/**
319
+	 * Enables the cloning of arguments passed to mocked methods.
320
+	 *
321
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
322
+	 */
323
+	public function enableArgumentCloning()
324
+	{
325
+		$this->cloneArguments = true;
326
+
327
+		return $this;
328
+	}
329
+
330
+	/**
331
+	 * Enables the invocation of the original methods.
332
+	 *
333
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
334
+	 */
335
+	public function enableProxyingToOriginalMethods()
336
+	{
337
+		$this->callOriginalMethods = true;
338
+
339
+		return $this;
340
+	}
341
+
342
+	/**
343
+	 * Disables the invocation of the original methods.
344
+	 *
345
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
346
+	 */
347
+	public function disableProxyingToOriginalMethods()
348
+	{
349
+		$this->callOriginalMethods = false;
350
+		$this->proxyTarget         = null;
351
+
352
+		return $this;
353
+	}
354
+
355
+	/**
356
+	 * Sets the proxy target.
357
+	 *
358
+	 * @param object $object
359
+	 *
360
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
361
+	 */
362
+	public function setProxyTarget($object)
363
+	{
364
+		$this->proxyTarget = $object;
365
+
366
+		return $this;
367
+	}
368
+
369
+	/**
370
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
371
+	 */
372
+	public function allowMockingUnknownTypes()
373
+	{
374
+		$this->allowMockingUnknownTypes = true;
375
+
376
+		return $this;
377
+	}
378
+
379
+	/**
380
+	 * @return PHPUnit_Framework_MockObject_MockBuilder
381
+	 */
382
+	public function disallowMockingUnknownTypes()
383
+	{
384
+		$this->allowMockingUnknownTypes = false;
385
+
386
+		return $this;
387
+	}
388 388
 }
Please login to merge, or discard this patch.
vendor/phpunit/phpunit-mock-objects/src/Builder/Stub.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@
 block discarded – undo
13 13
  */
14 14
 interface PHPUnit_Framework_MockObject_Builder_Stub extends PHPUnit_Framework_MockObject_Builder_Identity
15 15
 {
16
-    /**
17
-     * Stubs the matching method with the stub object $stub. Any invocations of
18
-     * the matched method will now be handled by the stub instead.
19
-     *
20
-     * @param PHPUnit_Framework_MockObject_Stub $stub
21
-     *
22
-     * @return PHPUnit_Framework_MockObject_Builder_Identity
23
-     */
24
-    public function will(PHPUnit_Framework_MockObject_Stub $stub);
16
+	/**
17
+	 * Stubs the matching method with the stub object $stub. Any invocations of
18
+	 * the matched method will now be handled by the stub instead.
19
+	 *
20
+	 * @param PHPUnit_Framework_MockObject_Stub $stub
21
+	 *
22
+	 * @return PHPUnit_Framework_MockObject_Builder_Identity
23
+	 */
24
+	public function will(PHPUnit_Framework_MockObject_Stub $stub);
25 25
 }
Please login to merge, or discard this patch.
vendor/phpunit/phpunit-mock-objects/src/Builder/InvocationMocker.php 2 patches
Indentation   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -18,272 +18,272 @@
 block discarded – undo
18 18
  */
19 19
 class PHPUnit_Framework_MockObject_Builder_InvocationMocker implements PHPUnit_Framework_MockObject_Builder_MethodNameMatch
20 20
 {
21
-    /**
22
-     * @var PHPUnit_Framework_MockObject_Stub_MatcherCollection
23
-     */
24
-    protected $collection;
25
-
26
-    /**
27
-     * @var PHPUnit_Framework_MockObject_Matcher
28
-     */
29
-    protected $matcher;
30
-
31
-    /**
32
-     * @var string[]
33
-     */
34
-    private $configurableMethods = [];
35
-
36
-    /**
37
-     * @param PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection
38
-     * @param PHPUnit_Framework_MockObject_Matcher_Invocation     $invocationMatcher
39
-     * @param array                                               $configurableMethods
40
-     */
41
-    public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher, array $configurableMethods)
42
-    {
43
-        $this->collection = $collection;
44
-        $this->matcher    = new PHPUnit_Framework_MockObject_Matcher(
45
-            $invocationMatcher
46
-        );
47
-
48
-        $this->collection->addMatcher($this->matcher);
49
-
50
-        $this->configurableMethods = $configurableMethods;
51
-    }
52
-
53
-    /**
54
-     * @return PHPUnit_Framework_MockObject_Matcher
55
-     */
56
-    public function getMatcher()
57
-    {
58
-        return $this->matcher;
59
-    }
60
-
61
-    /**
62
-     * @param mixed $id
63
-     *
64
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
65
-     */
66
-    public function id($id)
67
-    {
68
-        $this->collection->registerId($id, $this);
69
-
70
-        return $this;
71
-    }
72
-
73
-    /**
74
-     * @param PHPUnit_Framework_MockObject_Stub $stub
75
-     *
76
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
77
-     */
78
-    public function will(PHPUnit_Framework_MockObject_Stub $stub)
79
-    {
80
-        $this->matcher->stub = $stub;
81
-
82
-        return $this;
83
-    }
84
-
85
-    /**
86
-     * @param mixed $value
87
-     * @param mixed $nextValues, ...
88
-     *
89
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
90
-     */
91
-    public function willReturn($value, ...$nextValues)
92
-    {
93
-        $stub = count($nextValues) === 0 ?
94
-            new PHPUnit_Framework_MockObject_Stub_Return($value) :
95
-            new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls(
96
-               array_merge([$value], $nextValues)
97
-            );
98
-
99
-        return $this->will($stub);
100
-    }
101
-
102
-    /**
103
-     * @param mixed $reference
104
-     *
105
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
106
-     */
107
-    public function willReturnReference(&$reference)
108
-    {
109
-        $stub = new PHPUnit_Framework_MockObject_Stub_ReturnReference($reference);
110
-
111
-        return $this->will($stub);
112
-    }
113
-
114
-    /**
115
-     * @param array $valueMap
116
-     *
117
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
118
-     */
119
-    public function willReturnMap(array $valueMap)
120
-    {
121
-        $stub = new PHPUnit_Framework_MockObject_Stub_ReturnValueMap(
122
-            $valueMap
123
-        );
124
-
125
-        return $this->will($stub);
126
-    }
127
-
128
-    /**
129
-     * @param mixed $argumentIndex
130
-     *
131
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
132
-     */
133
-    public function willReturnArgument($argumentIndex)
134
-    {
135
-        $stub = new PHPUnit_Framework_MockObject_Stub_ReturnArgument(
136
-            $argumentIndex
137
-        );
138
-
139
-        return $this->will($stub);
140
-    }
141
-
142
-    /**
143
-     * @param callable $callback
144
-     *
145
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
146
-     */
147
-    public function willReturnCallback($callback)
148
-    {
149
-        $stub = new PHPUnit_Framework_MockObject_Stub_ReturnCallback(
150
-            $callback
151
-        );
152
-
153
-        return $this->will($stub);
154
-    }
155
-
156
-    /**
157
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
158
-     */
159
-    public function willReturnSelf()
160
-    {
161
-        $stub = new PHPUnit_Framework_MockObject_Stub_ReturnSelf;
162
-
163
-        return $this->will($stub);
164
-    }
165
-
166
-    /**
167
-     * @param mixed $values, ...
168
-     *
169
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
170
-     */
171
-    public function willReturnOnConsecutiveCalls(...$values)
172
-    {
173
-        $stub = new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($values);
174
-
175
-        return $this->will($stub);
176
-    }
177
-
178
-    /**
179
-     * @param Exception $exception
180
-     *
181
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
182
-     */
183
-    public function willThrowException(Exception $exception)
184
-    {
185
-        $stub = new PHPUnit_Framework_MockObject_Stub_Exception($exception);
186
-
187
-        return $this->will($stub);
188
-    }
189
-
190
-    /**
191
-     * @param mixed $id
192
-     *
193
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
194
-     */
195
-    public function after($id)
196
-    {
197
-        $this->matcher->afterMatchBuilderId = $id;
198
-
199
-        return $this;
200
-    }
201
-
202
-    /**
203
-     * Validate that a parameters matcher can be defined, throw exceptions otherwise.
204
-     *
205
-     * @throws PHPUnit_Framework_MockObject_RuntimeException
206
-     */
207
-    private function canDefineParameters()
208
-    {
209
-        if ($this->matcher->methodNameMatcher === null) {
210
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
211
-                'Method name matcher is not defined, cannot define parameter ' .
212
-                'matcher without one'
213
-            );
214
-        }
215
-
216
-        if ($this->matcher->parametersMatcher !== null) {
217
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
218
-                'Parameter matcher is already defined, cannot redefine'
219
-            );
220
-        }
221
-    }
222
-
223
-    /**
224
-     * @param array ...$arguments
225
-     *
226
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
227
-     */
228
-    public function with(...$arguments)
229
-    {
230
-        $this->canDefineParameters();
231
-
232
-        $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($arguments);
233
-
234
-        return $this;
235
-    }
236
-
237
-    /**
238
-     * @param array ...$arguments
239
-     *
240
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
241
-     */
242
-    public function withConsecutive(...$arguments)
243
-    {
244
-        $this->canDefineParameters();
245
-
246
-        $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters($arguments);
247
-
248
-        return $this;
249
-    }
250
-
251
-    /**
252
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
253
-     */
254
-    public function withAnyParameters()
255
-    {
256
-        $this->canDefineParameters();
257
-
258
-        $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters;
259
-
260
-        return $this;
261
-    }
262
-
263
-    /**
264
-     * @param PHPUnit_Framework_Constraint|string $constraint
265
-     *
266
-     * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
267
-     */
268
-    public function method($constraint)
269
-    {
270
-        if ($this->matcher->methodNameMatcher !== null) {
271
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
272
-                'Method name matcher is already defined, cannot redefine'
273
-            );
274
-        }
275
-
276
-        if (is_string($constraint) && !in_array(strtolower($constraint), $this->configurableMethods)) {
277
-            throw new PHPUnit_Framework_MockObject_RuntimeException(
278
-                sprintf(
279
-                    'Trying to configure method "%s" which cannot be configured because it does not exist, has not been specified, is final, or is static',
280
-                    $constraint
281
-                )
282
-            );
283
-        }
284
-
285
-        $this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint);
286
-
287
-        return $this;
288
-    }
21
+	/**
22
+	 * @var PHPUnit_Framework_MockObject_Stub_MatcherCollection
23
+	 */
24
+	protected $collection;
25
+
26
+	/**
27
+	 * @var PHPUnit_Framework_MockObject_Matcher
28
+	 */
29
+	protected $matcher;
30
+
31
+	/**
32
+	 * @var string[]
33
+	 */
34
+	private $configurableMethods = [];
35
+
36
+	/**
37
+	 * @param PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection
38
+	 * @param PHPUnit_Framework_MockObject_Matcher_Invocation     $invocationMatcher
39
+	 * @param array                                               $configurableMethods
40
+	 */
41
+	public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher, array $configurableMethods)
42
+	{
43
+		$this->collection = $collection;
44
+		$this->matcher    = new PHPUnit_Framework_MockObject_Matcher(
45
+			$invocationMatcher
46
+		);
47
+
48
+		$this->collection->addMatcher($this->matcher);
49
+
50
+		$this->configurableMethods = $configurableMethods;
51
+	}
52
+
53
+	/**
54
+	 * @return PHPUnit_Framework_MockObject_Matcher
55
+	 */
56
+	public function getMatcher()
57
+	{
58
+		return $this->matcher;
59
+	}
60
+
61
+	/**
62
+	 * @param mixed $id
63
+	 *
64
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
65
+	 */
66
+	public function id($id)
67
+	{
68
+		$this->collection->registerId($id, $this);
69
+
70
+		return $this;
71
+	}
72
+
73
+	/**
74
+	 * @param PHPUnit_Framework_MockObject_Stub $stub
75
+	 *
76
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
77
+	 */
78
+	public function will(PHPUnit_Framework_MockObject_Stub $stub)
79
+	{
80
+		$this->matcher->stub = $stub;
81
+
82
+		return $this;
83
+	}
84
+
85
+	/**
86
+	 * @param mixed $value
87
+	 * @param mixed $nextValues, ...
88
+	 *
89
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
90
+	 */
91
+	public function willReturn($value, ...$nextValues)
92
+	{
93
+		$stub = count($nextValues) === 0 ?
94
+			new PHPUnit_Framework_MockObject_Stub_Return($value) :
95
+			new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls(
96
+			   array_merge([$value], $nextValues)
97
+			);
98
+
99
+		return $this->will($stub);
100
+	}
101
+
102
+	/**
103
+	 * @param mixed $reference
104
+	 *
105
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
106
+	 */
107
+	public function willReturnReference(&$reference)
108
+	{
109
+		$stub = new PHPUnit_Framework_MockObject_Stub_ReturnReference($reference);
110
+
111
+		return $this->will($stub);
112
+	}
113
+
114
+	/**
115
+	 * @param array $valueMap
116
+	 *
117
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
118
+	 */
119
+	public function willReturnMap(array $valueMap)
120
+	{
121
+		$stub = new PHPUnit_Framework_MockObject_Stub_ReturnValueMap(
122
+			$valueMap
123
+		);
124
+
125
+		return $this->will($stub);
126
+	}
127
+
128
+	/**
129
+	 * @param mixed $argumentIndex
130
+	 *
131
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
132
+	 */
133
+	public function willReturnArgument($argumentIndex)
134
+	{
135
+		$stub = new PHPUnit_Framework_MockObject_Stub_ReturnArgument(
136
+			$argumentIndex
137
+		);
138
+
139
+		return $this->will($stub);
140
+	}
141
+
142
+	/**
143
+	 * @param callable $callback
144
+	 *
145
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
146
+	 */
147
+	public function willReturnCallback($callback)
148
+	{
149
+		$stub = new PHPUnit_Framework_MockObject_Stub_ReturnCallback(
150
+			$callback
151
+		);
152
+
153
+		return $this->will($stub);
154
+	}
155
+
156
+	/**
157
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
158
+	 */
159
+	public function willReturnSelf()
160
+	{
161
+		$stub = new PHPUnit_Framework_MockObject_Stub_ReturnSelf;
162
+
163
+		return $this->will($stub);
164
+	}
165
+
166
+	/**
167
+	 * @param mixed $values, ...
168
+	 *
169
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
170
+	 */
171
+	public function willReturnOnConsecutiveCalls(...$values)
172
+	{
173
+		$stub = new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($values);
174
+
175
+		return $this->will($stub);
176
+	}
177
+
178
+	/**
179
+	 * @param Exception $exception
180
+	 *
181
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
182
+	 */
183
+	public function willThrowException(Exception $exception)
184
+	{
185
+		$stub = new PHPUnit_Framework_MockObject_Stub_Exception($exception);
186
+
187
+		return $this->will($stub);
188
+	}
189
+
190
+	/**
191
+	 * @param mixed $id
192
+	 *
193
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
194
+	 */
195
+	public function after($id)
196
+	{
197
+		$this->matcher->afterMatchBuilderId = $id;
198
+
199
+		return $this;
200
+	}
201
+
202
+	/**
203
+	 * Validate that a parameters matcher can be defined, throw exceptions otherwise.
204
+	 *
205
+	 * @throws PHPUnit_Framework_MockObject_RuntimeException
206
+	 */
207
+	private function canDefineParameters()
208
+	{
209
+		if ($this->matcher->methodNameMatcher === null) {
210
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
211
+				'Method name matcher is not defined, cannot define parameter ' .
212
+				'matcher without one'
213
+			);
214
+		}
215
+
216
+		if ($this->matcher->parametersMatcher !== null) {
217
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
218
+				'Parameter matcher is already defined, cannot redefine'
219
+			);
220
+		}
221
+	}
222
+
223
+	/**
224
+	 * @param array ...$arguments
225
+	 *
226
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
227
+	 */
228
+	public function with(...$arguments)
229
+	{
230
+		$this->canDefineParameters();
231
+
232
+		$this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($arguments);
233
+
234
+		return $this;
235
+	}
236
+
237
+	/**
238
+	 * @param array ...$arguments
239
+	 *
240
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
241
+	 */
242
+	public function withConsecutive(...$arguments)
243
+	{
244
+		$this->canDefineParameters();
245
+
246
+		$this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters($arguments);
247
+
248
+		return $this;
249
+	}
250
+
251
+	/**
252
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
253
+	 */
254
+	public function withAnyParameters()
255
+	{
256
+		$this->canDefineParameters();
257
+
258
+		$this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters;
259
+
260
+		return $this;
261
+	}
262
+
263
+	/**
264
+	 * @param PHPUnit_Framework_Constraint|string $constraint
265
+	 *
266
+	 * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
267
+	 */
268
+	public function method($constraint)
269
+	{
270
+		if ($this->matcher->methodNameMatcher !== null) {
271
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
272
+				'Method name matcher is already defined, cannot redefine'
273
+			);
274
+		}
275
+
276
+		if (is_string($constraint) && !in_array(strtolower($constraint), $this->configurableMethods)) {
277
+			throw new PHPUnit_Framework_MockObject_RuntimeException(
278
+				sprintf(
279
+					'Trying to configure method "%s" which cannot be configured because it does not exist, has not been specified, is final, or is static',
280
+					$constraint
281
+				)
282
+			);
283
+		}
284
+
285
+		$this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint);
286
+
287
+		return $this;
288
+	}
289 289
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -91,8 +91,7 @@  discard block
 block discarded – undo
91 91
     public function willReturn($value, ...$nextValues)
92 92
     {
93 93
         $stub = count($nextValues) === 0 ?
94
-            new PHPUnit_Framework_MockObject_Stub_Return($value) :
95
-            new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls(
94
+            new PHPUnit_Framework_MockObject_Stub_Return($value) : new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls(
96 95
                array_merge([$value], $nextValues)
97 96
             );
98 97
 
@@ -208,7 +207,7 @@  discard block
 block discarded – undo
208 207
     {
209 208
         if ($this->matcher->methodNameMatcher === null) {
210 209
             throw new PHPUnit_Framework_MockObject_RuntimeException(
211
-                'Method name matcher is not defined, cannot define parameter ' .
210
+                'Method name matcher is not defined, cannot define parameter '.
212 211
                 'matcher without one'
213 212
             );
214 213
         }
Please login to merge, or discard this patch.
vendor/phpunit/phpunit-mock-objects/src/Builder/ParametersMatch.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -13,35 +13,35 @@
 block discarded – undo
13 13
  */
14 14
 interface PHPUnit_Framework_MockObject_Builder_ParametersMatch extends PHPUnit_Framework_MockObject_Builder_Match
15 15
 {
16
-    /**
17
-     * Sets the parameters to match for, each parameter to this function will
18
-     * be part of match. To perform specific matches or constraints create a
19
-     * new PHPUnit_Framework_Constraint and use it for the parameter.
20
-     * If the parameter value is not a constraint it will use the
21
-     * PHPUnit_Framework_Constraint_IsEqual for the value.
22
-     *
23
-     * Some examples:
24
-     * <code>
25
-     * // match first parameter with value 2
26
-     * $b->with(2);
27
-     * // match first parameter with value 'smock' and second identical to 42
28
-     * $b->with('smock', new PHPUnit_Framework_Constraint_IsEqual(42));
29
-     * </code>
30
-     *
31
-     * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch
32
-     */
33
-    public function with(...$arguments);
16
+	/**
17
+	 * Sets the parameters to match for, each parameter to this function will
18
+	 * be part of match. To perform specific matches or constraints create a
19
+	 * new PHPUnit_Framework_Constraint and use it for the parameter.
20
+	 * If the parameter value is not a constraint it will use the
21
+	 * PHPUnit_Framework_Constraint_IsEqual for the value.
22
+	 *
23
+	 * Some examples:
24
+	 * <code>
25
+	 * // match first parameter with value 2
26
+	 * $b->with(2);
27
+	 * // match first parameter with value 'smock' and second identical to 42
28
+	 * $b->with('smock', new PHPUnit_Framework_Constraint_IsEqual(42));
29
+	 * </code>
30
+	 *
31
+	 * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch
32
+	 */
33
+	public function with(...$arguments);
34 34
 
35
-    /**
36
-     * Sets a matcher which allows any kind of parameters.
37
-     *
38
-     * Some examples:
39
-     * <code>
40
-     * // match any number of parameters
41
-     * $b->withAnyParameters();
42
-     * </code>
43
-     *
44
-     * @return PHPUnit_Framework_MockObject_Matcher_AnyParameters
45
-     */
46
-    public function withAnyParameters();
35
+	/**
36
+	 * Sets a matcher which allows any kind of parameters.
37
+	 *
38
+	 * Some examples:
39
+	 * <code>
40
+	 * // match any number of parameters
41
+	 * $b->withAnyParameters();
42
+	 * </code>
43
+	 *
44
+	 * @return PHPUnit_Framework_MockObject_Matcher_AnyParameters
45
+	 */
46
+	public function withAnyParameters();
47 47
 }
Please login to merge, or discard this patch.