2017 © Pedro Peláez
 

library phpunit-immediate-exception-printer

Immediately prints exception and assertion failures during testing.

image

scriptfusion/phpunit-immediate-exception-printer

Immediately prints exception and assertion failures during testing.

  • Thursday, February 22, 2018
  • by Bilge
  • Repository
  • 2 Watchers
  • 36 Stars
  • 34,855 Installations
  • PHP
  • 15 Dependents
  • 1 Suggesters
  • 4 Forks
  • 6 Open issues
  • 9 Versions
  • 12 % Grown

The README.md

Pip, (*1)

[![Latest version][Version image]][Releases] [![Total downloads][Downloads image]][Downloads] [![Build status][Build image]][Build] [![Test coverage][Coverage image]][Coverage]

PHPUnit Immediate Printer

Pip is a PHPUnit extension that immediately prints exceptions and assertion failures during a test run. Normally PHPUnit keeps failure details secret until the end of the test run, but sometimes we don't want to wait that long. With Pip, all secrets are immediately revealed, with a few extra benefits, too., (*2)

Benefits

  • Display the name of each test case as it is executed.
  • Display the execution time of each test in configurable, tiered colour bands.
  • Immediately print exceptions, assertion failures, warnings, notice and deprecation messages as they occur.
  • Flawless test suite indicator: success dot turns to red exclamation mark if any prior tests failed. Useful for CI consoles without a scrollback buffer.

Preview

The following preview is somewhat atypical but shows all supported output cases at once. Of course, we expect all your tests to be mostly green!, (*3)

Preview image, (*4)

Pip makes no attempt to modify the test summary; only runtime output is changed., (*5)

Usage

  1. Add the dependency to your Composer file's require-dev section., (*6)

    composer require --dev scriptfusion/pip
    
  2. Declare the printer extension in your phpunit.xml configuration file., (*7)

    <extensions>
        <bootstrap class="ScriptFUSION\Pip\PipExtension"/>
    </extensions>
    
  3. Run the tests!, (*8)

    vendor/bin/phpunit
    
  4. Enjoy immediate test execution feedback., (*9)

Configuration

Pip's behaviour can be customized by adding <parameter> nodes as children of the <bootstrap> node in phpunit.xml, with name and value attributes corresponding to the table below., (*10)

Parameter name Default value Description
perf.slow 200 (ms) Sets the performance threshold for _slow_ (yellow) tests.
perf.vslow 1000 (ms) Sets the performance threshold for _very slow_ (red) tests.
test.dp.args true True to show the arguments passed by the data provider, false to hide.
test.name.strip '' Strips the specified matching portion of the test name.

Requirements

Pip version PHPUnit versions Minimum PHP version
3 10 / 11 8.1 / 8.2
2 yanked -
1 5 / 6 5.6 / 7.0

Testing Pip

To run the full test suite, use the following command., (*11)

composer test

Pip's capabilities are exploited via CapabilitiesTest. However, this test file isn't run directly because many of these tests are designed to fail. Instead, we write tests that run PHPUnit internally, each of which invokes one of the capability test cases and verifies its output. To run CapabilitiesTest, specify the following command, (*12)

composer test test/CapabilitiesTest.php

The real tests, also known as functional tests, are located in test/functional, written in PHPT format. PHPT is a scarcely documented format designed to support testing PHP itself. An undocumented feature of PHPUnit is its limited support for a subset of the PHPT test specification, which we exploit to test PHPUnit itself with our printer implementation loaded., (*13)

Writing functional tests

To test the output of a particular capability we run CapabilitiesTest with the --filter option to target a specific test case. Each functional test contains the arguments passed to PHPUnit in the --ARGS-- section of the file. These arguments can be pasted directly after the PHPUnit command to see the resulting output from that test case. We verify the output in the --EXPECTF-- section of the file., (*14)

One challenge we must overcome is verifying coloured output including ANSI escape sequences. To see these escape sequences we can pipe the output of a specific capability test to cat -v as shown in the following example., (*15)

vendor/bin/phpunit -c test --colors=always test/CapabilitiesTest.php --filter ::testSuccess$ | cat -v

The output from cat will print the "escape" character as ^[. We must replace each occurrence of this character sequence with the literal escape character (ASCII character 27). The easiest way to obtain the real escape character is to just copy it from an existing functional test., (*16)

Create a new functional test by copying an existing test as a template, then modify the PHPUnit arguments and the expected output to match what we expect using the techniques just described. Don't forget to give the test a clear description in the --TEST-- section!, (*17)

Inspiration

Thanks to the following open source projects that inspired this project., (*18)

The Versions

22/02 2018

dev-master

9999999-dev

Immediately prints exception and assertion failures during testing.

  Sources   Download

The Requires

 

by Avatar Bilge

21/02 2018

dev-nochange

dev-nochange

Immediately prints exception and assertion failures during testing.

  Sources   Download

The Requires

 

by Avatar Bilge

17/08 2017

2.0.x-dev

2.0.9999999.9999999-dev

Immediately prints exception and assertion failures during testing.

  Sources   Download

The Requires

 

by Avatar Bilge

17/08 2017

2.0.0

2.0.0.0

Immediately prints exception and assertion failures during testing.

  Sources   Download

The Requires

 

by Avatar Bilge

29/07 2017

1.3.0

1.3.0.0

Immediately prints exception and assertion failures during testing.

  Sources   Download

The Requires

 

by Avatar Bilge

26/07 2017

1.2.0

1.2.0.0

Immediately prints exception and assertion failures during testing.

  Sources   Download

The Requires

 

by Avatar Bilge

11/03 2017

1.1.0

1.1.0.0

Immediately prints exception and assertion failures during testing.

  Sources   Download

The Requires

 

by Avatar Bilge

07/03 2017

1.0.1

1.0.1.0

Immediately prints exception and assertion failures during testing.

  Sources   Download

The Requires

 

by Avatar Bilge

06/03 2017

1.0.0

1.0.0.0

Immediately prints any exceptions or assertion failures that occur during testing.

  Sources   Download

The Requires

 

by Avatar Bilge