public function echoArg($arg_num = 1)
    {
        $arg_num = $this->assertValidArgNum($arg_num);

        $fqn = $this->function_name->fullyQualifiedName();

        \Patchwork\redefine($fqn, function (...$args) use ($fqn, $arg_num) {

            if ( ! array_key_exists($arg_num - 1, $args)) {
                $count = count($args);
                throw new \RuntimeException(
                    "{$fqn} was called with {$count} params, can't return argument \"{$arg_num}\"."
                );
            }

            $arg = $args[$arg_num - 1];

            $this->assertPrintable($arg, "passed as argument {$arg_num} to {$fqn}");

            echo (string) $arg;
        });

        $this->assertRedefined($fqn);
    }
public function echoArg($arg_num = 1)
    {
        $arg_num = $this->assertValidArgNum($arg_num);

        $fqn = $this->function_name->fullyQualifiedName();

        \Patchwork\redefine($fqn, function (...$args) use ($fqn, $arg_num) {

            if ( ! array_key_exists($arg_num - 1, $args)) {
                $count = count($args);
                throw new \RuntimeException(
                    "{$fqn} was called with {$count} params, can't return argument \"{$arg_num}\"."
                );
            }

            $arg = $args[$arg_num - 1];

            $this->assertPrintable($arg, "passed as argument {$arg_num} to {$fqn}");

            echo (string) $arg;
        });

        $this->assertRedefined($fqn);
    }
public function echoArg ( $ arg_num = 1 ) { $ arg_num = $ this -> assertValidArgNum ( $ arg_num ) ; $ fqn = $ this -> function_name -> fullyQualifiedName ( ) ; \ Patchwork \ redefine ( $ fqn , function ( ... $ args ) use ( $ fqn , $ arg_num ) { if ( ! array_key_exists ( $ arg_num - 1 , $ args ) ) { $ count = count ( $ args ) ; throw new \ RuntimeException ( "{$fqn} was called with {$count} params, can't return argument \"{$arg_num}\"." ) ; } $ arg = $ args [ $ arg_num - 1 ] ; $ this -> assertPrintable ( $ arg , "passed as argument {$arg_num} to {$fqn}" ) ; echo ( string ) $ arg ; } ) ; $ this -> assertRedefined ( $ fqn ) ; }
Redefine target function making it echo one of the received arguments, the first by default.
Redefined function will throw an exception if the function does not receive desired argument.

@param int $arg_num The position (1-based) of the argument to echo
@throws \Brain\Monkey\Expectation\Exception\InvalidArgumentForStub
Redefine target function making it echo one of the received arguments the first by default . Redefined function will throw an exception if the function does not receive desired argument .