Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: namespace PHPUnit\Framework\MockObject\Stub; Chris@14: Chris@14: use PHPUnit\Framework\MockObject\Invocation; Chris@14: use PHPUnit\Framework\MockObject\Stub; Chris@14: use SebastianBergmann\Exporter\Exporter; Chris@14: Chris@14: /** Chris@14: * Stubs a method by returning a user-defined stack of values. Chris@14: */ Chris@14: class ConsecutiveCalls implements Stub Chris@14: { Chris@14: /** Chris@14: * @var array Chris@14: */ Chris@14: private $stack; Chris@14: Chris@14: /** Chris@14: * @var mixed Chris@14: */ Chris@14: private $value; Chris@14: Chris@14: public function __construct(array $stack) Chris@14: { Chris@14: $this->stack = $stack; Chris@14: } Chris@14: Chris@14: public function invoke(Invocation $invocation) Chris@14: { Chris@14: $this->value = \array_shift($this->stack); Chris@14: Chris@14: if ($this->value instanceof Stub) { Chris@14: $this->value = $this->value->invoke($invocation); Chris@14: } Chris@14: Chris@14: return $this->value; Chris@14: } Chris@14: Chris@14: public function toString() Chris@14: { Chris@14: $exporter = new Exporter; Chris@14: Chris@14: return \sprintf( Chris@14: 'return user-specified value %s', Chris@14: $exporter->export($this->value) Chris@14: ); Chris@14: } Chris@14: }