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 an argument that was passed to the mocked method. 13 * 14 * @since Class available since Release 1.0.0 15 */ 16class PHPUnit_Framework_MockObject_Stub_ReturnArgument extends PHPUnit_Framework_MockObject_Stub_Return 17{ 18 protected $argumentIndex; 19 20 public function __construct($argumentIndex) 21 { 22 $this->argumentIndex = $argumentIndex; 23 } 24 25 public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) 26 { 27 if (isset($invocation->parameters[$this->argumentIndex])) { 28 return $invocation->parameters[$this->argumentIndex]; 29 } else { 30 return; 31 } 32 } 33 34 public function toString() 35 { 36 return sprintf('return argument #%d', $this->argumentIndex); 37 } 38} 39