coccoinomane / phpunit-log
Log from within your PHPUnit tests.
Installs: 1 123
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/coccoinomane/phpunit-log
Requires (Dev)
- phpstan/extension-installer: ^1.1
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-09-29 03:13:58 UTC
README
Defines the Loggable trait to log from within your PHPUnit tests.
Usage
- Install the package with
composer require --dev coccoinomane/phpunit-log. - Include the trait in your TestCase with
\use PHPUnitLog\Loggable;. - Start logging with
this->log( $message )orthis->print( $message ).
Features
- To log a message to screen, call
self::print( $message ). - To log a message to file, call
self::log( $message ). - The file will be named after the test class and placed in the subfolder tests/logs.
- Customize the log folder via the
logsPathenvironment variable. - To delete the log files before each run:
public static function setUpBeforeClass(): void { static::deleteLogFile(); }
- For further customizations, see the docs in
Loggableor the tests inLoggableTest.
The Loggable trait is used by WordPressTestCase.
Custom folder for the logs
By default, the log files will be placed in the tests/logs folder; set the logsPath environment variable to use a different folder.
You can use both relative and absolute paths.
To set logsPath in phpunit.xml:
<php> <env name="logsPath" value="./tests/logs"/> </php>