Skip to content

Commit 8b46030

Browse files
Reorder methods
1 parent ccf560e commit 8b46030

File tree

2 files changed

+78
-78
lines changed

2 files changed

+78
-78
lines changed

src/Framework/MockObject/Runtime/Interface/InvocationStubber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
*/
1919
interface InvocationStubber
2020
{
21-
public function id(string $id): self;
22-
2321
/**
2422
* @return $this
2523
*/
2624
public function method(Constraint|string $constraint): self;
2725

26+
public function id(string $id): self;
27+
2828
/**
2929
* @return $this
3030
*/

src/Framework/MockObject/Runtime/InvocationStubberImplementation.php

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,41 @@ public function __construct(InvocationHandler $handler, Matcher $matcher, Config
6060
$this->configurableMethods = $configurableMethods;
6161
}
6262

63+
/**
64+
* @throws InvalidArgumentException
65+
* @throws MethodCannotBeConfiguredException
66+
* @throws MethodNameAlreadyConfiguredException
67+
*
68+
* @return $this
69+
*/
70+
public function method(Constraint|PropertyHook|string $constraint): InvocationStubber
71+
{
72+
if ($this->matcher->hasMethodNameRule()) {
73+
throw new MethodNameAlreadyConfiguredException;
74+
}
75+
76+
if ($constraint instanceof PropertyHook) {
77+
$constraint = $constraint->asString();
78+
}
79+
80+
if (is_string($constraint)) {
81+
$this->configurableMethodNames ??= array_flip(
82+
array_map(
83+
static fn (ConfigurableMethod $configurable) => strtolower($configurable->name()),
84+
$this->configurableMethods,
85+
),
86+
);
87+
88+
if (!array_key_exists(strtolower($constraint), $this->configurableMethodNames)) {
89+
throw new MethodCannotBeConfiguredException($constraint);
90+
}
91+
}
92+
93+
$this->matcher->setMethodNameRule(new Rule\MethodName($constraint));
94+
95+
return $this;
96+
}
97+
6398
/**
6499
* @throws MatcherAlreadyRegisteredException
65100
*
@@ -72,6 +107,47 @@ public function id(string $id): InvocationStubber
72107
return $this;
73108
}
74109

110+
/**
111+
* @return $this
112+
*/
113+
public function after(string $id): InvocationStubber
114+
{
115+
$this->matcher->setAfterMatchBuilderId($id);
116+
117+
return $this;
118+
}
119+
120+
/**
121+
* @throws \PHPUnit\Framework\Exception
122+
* @throws MethodNameNotConfiguredException
123+
* @throws MethodParametersAlreadyConfiguredException
124+
*
125+
* @return $this
126+
*/
127+
public function with(mixed ...$arguments): InvocationStubber
128+
{
129+
$this->ensureParametersCanBeConfigured();
130+
131+
$this->matcher->setParametersRule(new Rule\Parameters($arguments));
132+
133+
return $this;
134+
}
135+
136+
/**
137+
* @throws MethodNameNotConfiguredException
138+
* @throws MethodParametersAlreadyConfiguredException
139+
*
140+
* @return $this
141+
*/
142+
public function withAnyParameters(): InvocationStubber
143+
{
144+
$this->ensureParametersCanBeConfigured();
145+
146+
$this->matcher->setParametersRule(new Rule\AnyParameters);
147+
148+
return $this;
149+
}
150+
75151
/**
76152
* @return $this
77153
*/
@@ -191,82 +267,6 @@ public function willThrowException(Throwable $exception): InvocationStubber
191267
return $this->will($stub);
192268
}
193269

194-
/**
195-
* @return $this
196-
*/
197-
public function after(string $id): InvocationStubber
198-
{
199-
$this->matcher->setAfterMatchBuilderId($id);
200-
201-
return $this;
202-
}
203-
204-
/**
205-
* @throws \PHPUnit\Framework\Exception
206-
* @throws MethodNameNotConfiguredException
207-
* @throws MethodParametersAlreadyConfiguredException
208-
*
209-
* @return $this
210-
*/
211-
public function with(mixed ...$arguments): InvocationStubber
212-
{
213-
$this->ensureParametersCanBeConfigured();
214-
215-
$this->matcher->setParametersRule(new Rule\Parameters($arguments));
216-
217-
return $this;
218-
}
219-
220-
/**
221-
* @throws MethodNameNotConfiguredException
222-
* @throws MethodParametersAlreadyConfiguredException
223-
*
224-
* @return $this
225-
*/
226-
public function withAnyParameters(): InvocationStubber
227-
{
228-
$this->ensureParametersCanBeConfigured();
229-
230-
$this->matcher->setParametersRule(new Rule\AnyParameters);
231-
232-
return $this;
233-
}
234-
235-
/**
236-
* @throws InvalidArgumentException
237-
* @throws MethodCannotBeConfiguredException
238-
* @throws MethodNameAlreadyConfiguredException
239-
*
240-
* @return $this
241-
*/
242-
public function method(Constraint|PropertyHook|string $constraint): InvocationStubber
243-
{
244-
if ($this->matcher->hasMethodNameRule()) {
245-
throw new MethodNameAlreadyConfiguredException;
246-
}
247-
248-
if ($constraint instanceof PropertyHook) {
249-
$constraint = $constraint->asString();
250-
}
251-
252-
if (is_string($constraint)) {
253-
$this->configurableMethodNames ??= array_flip(
254-
array_map(
255-
static fn (ConfigurableMethod $configurable) => strtolower($configurable->name()),
256-
$this->configurableMethods,
257-
),
258-
);
259-
260-
if (!array_key_exists(strtolower($constraint), $this->configurableMethodNames)) {
261-
throw new MethodCannotBeConfiguredException($constraint);
262-
}
263-
}
264-
265-
$this->matcher->setMethodNameRule(new Rule\MethodName($constraint));
266-
267-
return $this;
268-
}
269-
270270
/**
271271
* @throws MethodNameNotConfiguredException
272272
* @throws MethodParametersAlreadyConfiguredException

0 commit comments

Comments
 (0)