Download the PHP package bartlett/phpunit-loggertestlistener without Composer
On this page you can find all versions of the php package bartlett/phpunit-loggertestlistener. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bartlett/phpunit-loggertestlistener
More information about bartlett/phpunit-loggertestlistener
Files in bartlett/phpunit-loggertestlistener
Package phpunit-loggertestlistener
Short Description PHPUnit Test Suite listener for compatible PSR-3 logger
License BSD-3-Clause
Homepage https://github.com/llaville/phpunit-LoggerTestListener
Informations about the package phpunit-loggertestlistener
PHPUnit Test Suite listener for compatible PSR-3 logger
Goal is to provide a standard PHPUnit Listener that is capable to send unit test results to any PSR-3 compatible logger.
The listener implement the PHPUnit\Framework\TestListener
interface,
and used these log levels/events mapping.
ERROR
- `addError()`, when an error occurred
- `addFailure()`, when a failure occured
WARNING
- `addWarning()`, on warning test
- `addIncompleteTest()`, on incomplete test
- `addRiskyTest()`, on risky test
- `addSkippedTest()`, when a test was skipped
INFO
- `startTest()`, when a test started
- `endTest()`, when a test ended
NOTICE
- `startTestSuite()`, when a test suite started
- `endTestSuite()`, when a test suite ended
Installation
IMPORTANT: For demonstration purpose, a Growl Handler and an AdvancedFilter Handler were used but are not yet available as a GitHub or Packagist version.
Usage with basic PSR-3 Logger
We will use a very basic PSR-3 logger for our first steps. Suppose we have such following implementation.
Add in your phpunit.xml
configuration file the Bartlett\LoggerTestListener
test listener,
using our basic PSR-3 logger (YourLogger
).
Using default behavior of your logger
We can change name of the channel (from default YourLoggerChannel
to value YourPSR3Logger
) as follow :
Configure the channel name of your logger
If you want to have advanced logging strategies, I suggest you to have a look on famous Monolog PHP Library.
Usage with Monolog
Without handler (then default output will be send to STDERR), we could have such kind of configuration,
with logger channel name set to YourMonologChannel
.
Add some handlers, with basic logging Monolog Strategy (filter on level only).
WARNING: When we used desktop notification such as growl, or mobile notifications powered by Pushover, you probably don't want to receive all log records, but just the most important ones (errors, failures, testsuites ended).
Actually Monolog can't do this. So this is the reason of the Pull Request to add filter capability. It's now available as a standalone package. See Monolog Wiki page, and CallbackFilterHandler project's page
Now create a pre-defined logger with all handlers we wished on and the filter rules for each handlers.
And of course, declare our new listener like that :
We will get all PHPUnit log messages recorded via the StreamHandler
,
and only important notifications via GrowlHandler
(see filter rule with callback $filter1
).
Run the test suite example :
And you will get something like:
Test Suite results with Monolog Stream Handler
Test Suite results with Growl Handler
NOTE: Produced by Growl for Windows (2.0.9 and Smokestack display) with PHP GNTP library.
License
LoggerTestListener is licensed under the BSD-3 Clause License - see the LICENSE file for details