worksome/pest-plugin-silence

This package is abandoned and no longer maintained. No replacement package was suggested.

Prevent unwanted output in tests.

v0.1.2 2022-02-22 15:04 UTC

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

Tests PHPStan

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 echos or dumps to the console to fail, meaning that you'll never forget to remove those statements from your codebase.

Before:

CleanShot 2022-02-22 at 14 51 15@2x

After:

CleanShot 2022-02-22 at 14 53 35@2x

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.