Prevent none-test output in your Pest tests.

Overview

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.

You might also like...
PHPUnit to Pest Converter

PestConverter PestConverter is a PHP library for converting PHPUnit tests to Pest tests. Before use Before using this converter, make sure your files

Pest is an elegant PHP Testing Framework with a focus on simplicity
Pest is an elegant PHP Testing Framework with a focus on simplicity

Pest is an elegant PHP Testing Framework with a focus on simplicity. It was carefully crafted to bring the joy of testing to PHP. Explore the docs: pe

Given When Then (GWT) Plugin for Pest

Given When Then (GWT) Plugin for Pest A simple API allows you to structure your tests focused on the behaviour. Given-When-Then separation makes the t

Mock HTTP requests on the server side in your PHP unit tests

HTTP Mock for PHP Mock HTTP requests on the server side in your PHP unit tests. HTTP Mock for PHP mocks the server side of an HTTP request to allow in

TestDummy makes the process of preparing factories (dummy data) for your integration tests as easy as possible

TestDummy TestDummy makes the process of preparing factories (dummy data) for your integration tests as easy as possible. As easy as... Build a Post m

Some shorthand functions for skipping and focusing tests.

Pest Plugin: Shorthands This repository contains the Pest Plugin Shorthands. If you want to start testing your application with Pest, visit the main P

A PHP library for mocking date and time in tests

ClockMock Slope s.r.l. ClockMock provides a way for mocking the current timestamp used by PHP for \DateTime(Immutable) objects and date/time related f

To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

A tool to run migrations prior to running tests

cakephp-test-migrator A tool to run migrations prior to running tests The Migrator For CakePHP 3.x composer require --dev vierge-noire/cakephp-test-mi

Owner
Worksome
Building a future platform for flexible employment.
Worksome
Enforce consistent styling for your Pest PHP tests

A set of PHP CS rules for formatting Pest PHP tests.

Worksome 2 Mar 15, 2022
This plugin adds basic HTTP requests functionality to Pest tests, using minicli/curly

Curly Pest Plugin This plugin adds basic HTTP requests functionality to Pest tests, using minicli/curly. Installation composer require minicli/pest-pl

minicli 16 Mar 24, 2022
⛽ Pest plugin to test Laravel applications powered by Octane.

⛽ Laravel Octane (Pest Plugin) Pest plugin to test Laravel applications powered by Octane. Install Via Composer composer require --dev cerbero/pest-pl

Andrea Marco Sartori 21 Apr 5, 2022
vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with any unit test framework, like PHPUnit or SimpleTest.

vfsStream vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with

null 1.4k Dec 23, 2022
Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slowness of constantly restarting the testing environment.

Magic Test for Laravel Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slownes

null 400 Jan 5, 2023
PHP Test Generator - A CLI tool which generates unit tests

This project make usages of PHPStan and PHPParser to generate test cases for a given PHP File.

Alexander Schranz 7 Dec 3, 2022
Add mocking capabilities to Pest or PHPUnit

This repository contains the Pest Plugin Mock. The Mocking API can be used in regular PHPUnit projects. For that, you just have to run the following c

PEST 16 Dec 3, 2022
A Pest plugin to control the flow of time

This Pest plugin offers a function testTime that allows you to freeze and manipulate the current time in your tests.

Spatie 34 Nov 16, 2022
Integrates Pest with PHP-VCR using plugins.

Pest plugin for PHP-VCR Integrates Pest with PHP-VCR using plugins. Installation You can install the package via composer: composer require phpjuice/p

PHPJuice 4 Sep 1, 2021
The Pest Parallel Plugin

This repository contains the Pest Plugin Parallel. If you want to start testing your application with Pest, visit the main Pest Repository. Explore th

PEST 28 Dec 5, 2022