comparison vendor/phpunit/phpunit-mock-objects/src/Stub/ConsecutiveCalls.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /*
3 * This file is part of the phpunit-mock-objects package.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
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\Stub;
11
12 use PHPUnit\Framework\MockObject\Invocation;
13 use PHPUnit\Framework\MockObject\Stub;
14 use SebastianBergmann\Exporter\Exporter;
15
16 /**
17 * Stubs a method by returning a user-defined stack of values.
18 */
19 class ConsecutiveCalls implements Stub
20 {
21 /**
22 * @var array
23 */
24 private $stack;
25
26 /**
27 * @var mixed
28 */
29 private $value;
30
31 public function __construct(array $stack)
32 {
33 $this->stack = $stack;
34 }
35
36 public function invoke(Invocation $invocation)
37 {
38 $this->value = \array_shift($this->stack);
39
40 if ($this->value instanceof Stub) {
41 $this->value = $this->value->invoke($invocation);
42 }
43
44 return $this->value;
45 }
46
47 public function toString()
48 {
49 $exporter = new Exporter;
50
51 return \sprintf(
52 'return user-specified value %s',
53 $exporter->export($this->value)
54 );
55 }
56 }