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
11/**
12 * Stubs a method by returning a value from a map.
13 *
14 * @since Class available since Release 1.1.0
15 */
16class PHPUnit_Framework_MockObject_Stub_ReturnValueMap implements PHPUnit_Framework_MockObject_Stub
17{
18    protected $valueMap;
19
20    public function __construct(array $valueMap)
21    {
22        $this->valueMap = $valueMap;
23    }
24
25    public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
26    {
27        $parameterCount = count($invocation->parameters);
28
29        foreach ($this->valueMap as $map) {
30            if (!is_array($map) || $parameterCount != count($map) - 1) {
31                continue;
32            }
33
34            $return = array_pop($map);
35            if ($invocation->parameters === $map) {
36                return $return;
37            }
38        }
39
40        return;
41    }
42
43    public function toString()
44    {
45        return 'return value from a map';
46    }
47}
48