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

后端 未结 18 1671
旧时难觅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条回答
  •  猫巷女王i
    2020-11-30 18:21

    This was taken from PHPUnit Docs about Fixtures.

    This should allow you to dump information at any point durring the phpunit test life cycle.

    Just replace __METHOD__ in the code below with whatever you want to output

    Example 4.2: Example showing all template methods available

    assertTrue(TRUE);
        }
    
        public function testTwo()
        {
            fwrite(STDOUT, __METHOD__ . "\n");
            $this->assertTrue(FALSE);
        }
    
        protected function assertPostConditions()
        {
            fwrite(STDOUT, __METHOD__ . "\n");
        }
    
        protected function tearDown()
        {
            fwrite(STDOUT, __METHOD__ . "\n");
        }
    
        public static function tearDownAfterClass()
        {
            fwrite(STDOUT, __METHOD__ . "\n");
        }
    
        protected function onNotSuccessfulTest(Exception $e)
        {
            fwrite(STDOUT, __METHOD__ . "\n");
            throw $e;
        }
    }
    ?>
    

提交回复
热议问题