worksome / pest-plugin-silence
Prevent unwanted output in tests.
Installs: 258 503
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 13
Forks: 1
Open Issues: 0
Requires
- php: ^8.0
- pestphp/pest: ^1.0
- pestphp/pest-plugin: ^1.0
Requires (Dev)
- pestphp/pest-dev-tools: dev-master
This package is auto-updated.
Last update: 2023-11-04 14:44:48 UTC
README
This repository has been archived and is no longer maintained.
Pest Plugin Silence
Often, when writing tests, we echo
and dump
test code to debug and check everything is working correctly.
It can be easy to forget to remove those statements when you've finished, which can lead to a lot of messy output
in your test results. Yuk!
Silence is a lightweight plugin for Pest that will cause any test that echo
s or dump
s to the console
to fail, meaning that you'll never forget to remove those statements from your codebase.
Before:
After:
Installation
Install the plugin via composer.
composer require worksome/pest-plugin-silence --dev
Usage
Silence isn't enabled out of the box. However, it's simple to enable it for your project using one of two methods.
Enable with an environment variable
You can enable Silence using the PREVENT_OUTPUT
environment variable whilst running your tests. You may add this to your
phpunit.xml
.
<phpunit> <php> <env name="PREVENT_OUTPUT" value="true"/> </php> </phpunit>
Enable manually in your test or TestCase
Alternatively, for a more selective approach, you may enable Silence in your test or TestCase
using the Silence::preventOutput()
method.
use Worksome\PestPluginSilence\Silence; it('just works', function () { Silence::preventOutput(); echo "Uh-oh!" expect(true)->toBeTrue(); });
If you want to manually enable Silence for every test, place it in the setUp
method of your TestCase
.
class TestCase extends BaseTestCase { public function setUp(): void { parent::setUp(); Silence::preventOutput(); } }
Testing
Silence is fully tested, and also implements strict static analysis. You can run the test suite using our test script:
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.