File tree Expand file tree Collapse file tree 3 files changed +49
-3
lines changed
tests/unit/Framework/MockObject Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+ /*
3+ * This file is part of PHPUnit.
4+ *
5+ * (c) Sebastian Bergmann <[email protected] > 6+ *
7+ * For the full copyright and license information, please view the LICENSE
8+ * file that was distributed with this source code.
9+ */
10+ namespace PHPUnit \Framework \MockObject ;
11+
12+ use function sprintf ;
13+
14+ /**
15+ * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
16+ *
17+ * @internal This class is not covered by the backward compatibility promise for PHPUnit
18+ */
19+ final class NoMoreReturnValuesConfiguredException extends \PHPUnit \Framework \Exception implements Exception
20+ {
21+ public function __construct (Invocation $ invocation , int $ numberOfConfiguredReturnValues )
22+ {
23+ parent ::__construct (
24+ sprintf (
25+ 'Only %d return values have been configured for %s::%s() ' ,
26+ $ numberOfConfiguredReturnValues ,
27+ $ invocation ->className (),
28+ $ invocation ->methodName (),
29+ ),
30+ );
31+ }
32+ }
Original file line number Diff line number Diff line change 1010namespace PHPUnit \Framework \MockObject \Stub ;
1111
1212use function array_shift ;
13+ use function count ;
1314use PHPUnit \Framework \MockObject \Invocation ;
15+ use PHPUnit \Framework \MockObject \NoMoreReturnValuesConfiguredException ;
1416
1517/**
1618 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
2022final class ConsecutiveCalls implements Stub
2123{
2224 private array $ stack ;
25+ private int $ numberOfConfiguredReturnValues ;
2326
2427 public function __construct (array $ stack )
2528 {
26- $ this ->stack = $ stack ;
29+ $ this ->stack = $ stack ;
30+ $ this ->numberOfConfiguredReturnValues = count ($ stack );
2731 }
2832
33+ /**
34+ * @throws NoMoreReturnValuesConfiguredException
35+ */
2936 public function invoke (Invocation $ invocation ): mixed
3037 {
38+ if (empty ($ this ->stack )) {
39+ throw new NoMoreReturnValuesConfiguredException (
40+ $ invocation ,
41+ $ this ->numberOfConfiguredReturnValues ,
42+ );
43+ }
44+
3145 $ value = array_shift ($ this ->stack );
3246
3347 if ($ value instanceof Stub) {
Original file line number Diff line number Diff line change 1818use PHPUnit \TestFixture \MockObject \InterfaceWithNeverReturningMethod ;
1919use PHPUnit \TestFixture \MockObject \InterfaceWithReturnTypeDeclaration ;
2020use stdClass ;
21- use TypeError ;
2221
2322abstract class TestDoubleTestCase extends TestCase
2423{
@@ -198,7 +197,8 @@ final public function testMethodConfiguredToReturnDifferentValuesOnConsecutiveCa
198197 $ this ->assertFalse ($ double ->doSomething ());
199198 $ this ->assertTrue ($ double ->doSomething ());
200199
201- $ this ->expectException (TypeError::class);
200+ $ this ->expectException (NoMoreReturnValuesConfiguredException::class);
201+ $ this ->expectExceptionMessage ('Only 2 return values have been configured for PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration::doSomething() ' );
202202
203203 $ double ->doSomething ();
204204 }
You can’t perform that action at this time.
0 commit comments