phpunitHow to log to the console with PHPUnit?
Logging to the console with PHPUnit is possible using the write
method of the PHPUnit_TextUI_ResultPrinter
class.
Example code
$printer = new PHPUnit_TextUI_ResultPrinter();
$printer->write("This is a log message");
Output example
This is a log message
The code consists of two parts:
- Creating an instance of the
PHPUnit_TextUI_ResultPrinter
class:
$printer = new PHPUnit_TextUI_ResultPrinter();
- Writing a log message to the console using the
write
method of thePHPUnit_TextUI_ResultPrinter
class:
$printer->write("This is a log message");
For more information, please refer to the PHPUnit documentation.
More of Phpunit
- How to order tests with PHPUnit?
- How to mock an interface in PHPUnit?
- How to install PHPUnit with a PHAR file?
- How to stop PHPUnit on failure?
- How to expect an error with PHPUnit?
- How to expect an exception in PHPUnit?
- How to use the PHPUnit Framework ExceptionWrapper?
- How to increase memory limit in PHPUnit?
- How to use an inline dataprovider in PHPUnit?
See more codes...