public function return_value_map($mapOfArgsToValues)
    {
        if (count($mapOfArgsToValues) < 1) {
            throw new \InvalidArgumentException('Must specify at least one return value');
        };

        $limit = count($mapOfArgsToValues);

        $this->frequency = new CountOfTimes($limit, $this->methodName);

        /*
        * make the mapping a little more sane: if we received
        * [
        *   [1,2,3],
        *   [4,5,9]
        * ]
        * as a map, convert it to:
        * [
        *  [[1,2], 3],
        *  [[4,5], 9],
        * ]
        */
        $mapping = [];
        foreach ($mapOfArgsToValues as $paramsAndReturn) {
            $parameterSet = array_slice($paramsAndReturn, 0, count($paramsAndReturn) - 1);
            $returnVal = $paramsAndReturn[count($paramsAndReturn) - 1];
            $mapping[] = [$parameterSet, $returnVal];
        }

        foreach ($this->policies as $policy) {
            foreach ($mapping as $paramsWithReturn) {
                $policy->check_method_parameters($this->className, $this->methodName, $paramsWithReturn[0], $this->isStatic());
                $policy->check_method_return_value($this->className, $this->methodName, $paramsWithReturn[1], $this->isStatic());
            }
        }

        $this->will = function ($invocation) use ($mapping) {
            $args = $invocation->parameters;
            foreach ($mapping as $map) {
                list($possibleArgs, $possibleRet) = $map;
                if ($possibleArgs === $args) {
                    return $possibleRet;
                }
            }

            $differ = new \SebastianBergmann\Diff\Differ();
            $diffSoFar = null;
            foreach ($mapping as $map) {
                $possibleArgs = $map[0];
                $nextDiff = $differ->diff(print_r($possibleArgs, true), print_r($args, true));
                if ($diffSoFar === null || strlen($nextDiff) < strlen($diffSoFar)) {
                    $diffSoFar = $nextDiff;
                }
            }
            throw new \PHPUnit_Framework_AssertionFailedError(sprintf("Did not expect to be called with args %s, diff with closest match is\n%s", print_r($args, true), $diffSoFar));
        };

        return $this;
    }
public function return_value_map($mapOfArgsToValues)
    {
        if (count($mapOfArgsToValues) < 1) {
            throw new \InvalidArgumentException('Must specify at least one return value');
        };

        $limit = count($mapOfArgsToValues);

        $this->frequency = new CountOfTimes($limit, $this->methodName);

        /*
        * make the mapping a little more sane: if we received
        * [
        *   [1,2,3],
        *   [4,5,9]
        * ]
        * as a map, convert it to:
        * [
        *  [[1,2], 3],
        *  [[4,5], 9],
        * ]
        */
        $mapping = [];
        foreach ($mapOfArgsToValues as $paramsAndReturn) {
            $parameterSet = array_slice($paramsAndReturn, 0, count($paramsAndReturn) - 1);
            $returnVal = $paramsAndReturn[count($paramsAndReturn) - 1];
            $mapping[] = [$parameterSet, $returnVal];
        }

        foreach ($this->policies as $policy) {
            foreach ($mapping as $paramsWithReturn) {
                $policy->check_method_parameters($this->className, $this->methodName, $paramsWithReturn[0], $this->isStatic());
                $policy->check_method_return_value($this->className, $this->methodName, $paramsWithReturn[1], $this->isStatic());
            }
        }

        $this->will = function ($invocation) use ($mapping) {
            $args = $invocation->parameters;
            foreach ($mapping as $map) {
                list($possibleArgs, $possibleRet) = $map;
                if ($possibleArgs === $args) {
                    return $possibleRet;
                }
            }

            $differ = new \SebastianBergmann\Diff\Differ();
            $diffSoFar = null;
            foreach ($mapping as $map) {
                $possibleArgs = $map[0];
                $nextDiff = $differ->diff(print_r($possibleArgs, true), print_r($args, true));
                if ($diffSoFar === null || strlen($nextDiff) < strlen($diffSoFar)) {
                    $diffSoFar = $nextDiff;
                }
            }
            throw new \PHPUnit_Framework_AssertionFailedError(sprintf("Did not expect to be called with args %s, diff with closest match is\n%s", print_r($args, true), $diffSoFar));
        };

        return $this;
    }
public function return_value_map ( $ mapOfArgsToValues ) { if ( count ( $ mapOfArgsToValues ) < 1 ) { throw new \ InvalidArgumentException ( 'Must specify at least one return value' ) ; } ; $ limit = count ( $ mapOfArgsToValues ) ; $ this -> frequency = new CountOfTimes ( $ limit , $ this -> methodName ) ; /*
        * make the mapping a little more sane: if we received
        * [
        *   [1,2,3],
        *   [4,5,9]
        * ]
        * as a map, convert it to:
        * [
        *  [[1,2], 3],
        *  [[4,5], 9],
        * ]
        */ $ mapping = [ ] ; foreach ( $ mapOfArgsToValues as $ paramsAndReturn ) { $ parameterSet = array_slice ( $ paramsAndReturn , 0 , count ( $ paramsAndReturn ) - 1 ) ; $ returnVal = $ paramsAndReturn [ count ( $ paramsAndReturn ) - 1 ] ; $ mapping [ ] = [ $ parameterSet , $ returnVal ] ; } foreach ( $ this -> policies as $ policy ) { foreach ( $ mapping as $ paramsWithReturn ) { $ policy -> check_method_parameters ( $ this -> className , $ this -> methodName , $ paramsWithReturn [ 0 ] , $ this -> isStatic ( ) ) ; $ policy -> check_method_return_value ( $ this -> className , $ this -> methodName , $ paramsWithReturn [ 1 ] , $ this -> isStatic ( ) ) ; } } $ this -> will = function ( $ invocation ) use ( $ mapping ) { $ args = $ invocation -> parameters ; foreach ( $ mapping as $ map ) { list ( $ possibleArgs , $ possibleRet ) = $ map ; if ( $ possibleArgs === $ args ) { return $ possibleRet ; } } $ differ = new \ SebastianBergmann \ Diff \ Differ ( ) ; $ diffSoFar = null ; foreach ( $ mapping as $ map ) { $ possibleArgs = $ map [ 0 ] ; $ nextDiff = $ differ -> diff ( print_r ( $ possibleArgs , true ) , print_r ( $ args , true ) ) ; if ( $ diffSoFar === null || strlen ( $ nextDiff ) < strlen ( $ diffSoFar ) ) { $ diffSoFar = $ nextDiff ; } } throw new \ PHPUnit_Framework_AssertionFailedError ( sprintf ( "Did not expect to be called with args %s, diff with closest match is\n%s" , print_r ( $ args , true ) , $ diffSoFar ) ) ; } ; return $ this ; }
An order-agnostic set of return values given a set of inputs.

@param mixed[][] $map_of_args_to_values an array of arrays of arguments with the final value
of the array being the return value.
@return \Shmock\Spec
For example, if you were simulating addition:
<pre>
$shmock_calculator->add()->return_value_map([
[1, 2, 3], // 1 + 2 = 3
[10, 15, 25],
[11, 11, 22]
]);
</pre>
An order - agnostic set of return values given a set of inputs .