1<?php
2/*
3 * This file is part of the PHPUnit_MockObject 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
11use SebastianBergmann\Exporter\Exporter;
12
13/**
14 * Stubs a method by returning a user-defined stack of values.
15 *
16 * @since Class available since Release 1.0.0
17 */
18class PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls implements PHPUnit_Framework_MockObject_Stub
19{
20    protected $stack;
21    protected $value;
22
23    public function __construct($stack)
24    {
25        $this->stack = $stack;
26    }
27
28    public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
29    {
30        $this->value = array_shift($this->stack);
31
32        if ($this->value instanceof PHPUnit_Framework_MockObject_Stub) {
33            $this->value = $this->value->invoke($invocation);
34        }
35
36        return $this->value;
37    }
38
39    public function toString()
40    {
41        $exporter = new Exporter;
42
43        return sprintf(
44            'return user-specified value %s',
45            $exporter->export($this->value)
46        );
47    }
48}
49