How to output in CLI during execution of PHP Unit tests?

后端 未结 18 1647
旧时难觅i
旧时难觅i 2020-11-30 18:01

When running a PHPUnit test, I would like to be able to dump output so I can debug one or two things.

I have tried the following (similar to the PHPUnit Manual examp

18条回答
  •  既然无缘
    2020-11-30 18:16

    I had to modify source code for this code to work so you need to add URL for this forked repos to composer for this will work

    class TestCase extends \PHPUnit_Framework_TestCase
    {
        /**
         *  Save last response
         * @var Response|null A Response instance
         */
        static $lastResponse;
        /**
         *  Modify to save response
         *
         * @param  string $method
         * @param  string $uri
         * @param  array $parameters
         * @param  array $files
         * @param  array $server
         * @param  string $content
         * @param  bool $changeHistory
         * @return \Illuminate\Http\Response
         */
        final public function call(
            $method,
            $uri,
            $parameters = [],
            $files = [],
            $server = [],
            $content = null,
            $changeHistory = true
        ) {
    
            $response = parent::call($method, $uri, $parameters, $files, $server, $content, $changeHistory);
            static::$lastResponse = $this->client->getResponse();
            return $response;
        }
    
    
        /**
         * Modify message to add response text
         *
         * @param mixed $value
         * @param PHPUnit_Framework_Constraint $constraint
         * @param string $message
         * @since  Method available since Release 3.0.0
         */
        final public static function assertThat($value, PHPUnit_Framework_Constraint $constraint, $message = '')
        {
            $message .= PHP_EOL . static::$lastResponse . PHP_EOL;
            parent::assertThat($value, $constraint, $message);
        }
    }
    

提交回复
热议问题