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 skip a PHPUnit test?
- How to mock a method with different arguments in PHPUnit?
- How to run tests in parallel with PHPUnit?
- How to run all PHPUnit tests?
- How to run only certain methods in PHPUnit?
- How to mock a static method with PHPUnit?
- How to mock a query builder with PHPUnit?
- How to launch one test with PHPUnit?
- How to check if a JSON contains a value in PHPUnit?
- How to use hooks in PHPUnit?
See more codes...