💥 Collision is a beautiful error reporting tool for command-line applications

Overview

Collision logo
Collision code example

Build Status Quality Score Total Downloads Latest Stable Version License


Collision was created by, and is maintained by Nuno Maduro, and is a package designed to give you beautiful error reporting when interacting with your app through the command line.

  • It's included on Laravel, the most popular free, open-source PHP framework in the world.
  • Built on top of the Whoops error handler.
  • Supports Laravel, Symfony, PHPUnit, and many other frameworks.

Installation & Usage

Requires PHP 7.3+

Require Collision using Composer:

composer require nunomaduro/collision --dev

Laravel Version Compatibility

Laravel Collision
6.x 3.x
7.x 4.x
8.x 5.x

As an example, here is how to require Collision on Laravel 6.x:

composer require nunomaduro/collision:^3.0 --dev

Phpunit adapter

Phpunit must be 9.0 or higher.

Add the Collision printerClass to your phpunit.xml in the phpunit section:

<phpunit
        printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer">

No adapter

You need to register the handler in your code:

(new \NunoMaduro\Collision\Provider)->register();

Contributing

Thank you for considering to contribute to Collision. All the contribution guidelines are mentioned here.

You can have a look at the CHANGELOG for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!: @enunomaduro

Support the development

Do you like this project? Support it by donating

License

Collision is an open-sourced software licensed under the MIT license.

Logo by Caneco.

Comments
  • TestCommand not respecting output colors

    TestCommand not respecting output colors

    OS: Windows 10 Build 18363.657 Windows Terminal (beta): 0.9.433.0 Laravel Version: 7.0-dev

    How to reproduce:

    • Run php artisan test
    • The output doesn't include the highlighting from this package's printer class.
    • Note: when I tried using PHPUnit\TextUI\ResultPrinter in the printer parameter for the artisan command, the colors aren't respected either.
    • With the printer class from this package specified in phpunit.xml, the colors are respected when running via vendor\bin\phpunit
    opened by jrd-lewis 19
  • Replace abandoned packages in v3.x

    Replace abandoned packages in v3.x

    replace abandoned package jakub-onderka/php-console-highlighter with "php-parallel-lint/php-console-highlighter 0.5

    closes https://github.com/nunomaduro/collision/issues/172

    opened by oliworx 13
  • Warning about abandoned package

    Warning about abandoned package

    After composer update I get a warning about deprecated packages

    composer update
    Loading composer repositories with package information                                                                                                                                                                                                    Updating dependencies (including require-dev)         
    Package operations: 1 install, 6 updates, 0 removals
      - Updating league/commonmark (1.3.2 => 1.3.3): Downloading (100%)         
      - Updating psy/psysh (v0.10.2 => v0.10.3): Downloading (100%)         
      - Updating laravel/framework (v6.18.3 => v6.18.6): Downloading (100%)         
      - Updating laravel/tinker (v2.3.0 => v2.4.0): Downloading (100%)         
      - Installing sebastian/code-unit (1.0.0): Downloading (100%)         
      - Updating phpunit/phpunit (9.0.2 => 9.1.1): Downloading (100%)         
      - Updating composer/ca-bundle (1.2.6 => 1.2.7): Downloading (100%)         
    Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
    Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
    Writing lock file
    Generating optimized autoload files
    
    opened by emilas44 12
  • Any way to make collision respect phpunit --stop-on-error?

    Any way to make collision respect phpunit --stop-on-error?

    I think there was a closed issue related to this. I use this feature pretty often when running the complete test suite so I can walk away, get some coffee, come back and see what a mess I made during my refactor. Just wondering if it is possible to modify the PHPUnit listener to respect this flag.

    opened by alexciarlillo 12
  • Emit output with beStrictAboutOutputDuringTests=false in Phpunit/Printer

    Emit output with beStrictAboutOutputDuringTests=false in Phpunit/Printer

    Coming from pest https://github.com/pestphp/pest/issues/73

    While PHPUnit's DefaultResultPrinter emits output to stdout anyways if beStrictAboutOutputDuringTests sets false, collision might want to follow the same behavior.

    opened by nobuf 10
  • Fix loading APP_ENV specific .env files

    Fix loading APP_ENV specific .env files

    When running php artisan test environment specific .env files aren't loaded.

    Creating a fresh Laravel installation comes with a phpunit.xml file where APP_ENV=testing is defined. When running phpunit it would load a .env.testing file if it exists in the project root and include those variables when testing.

    This should fix and mimic the same way as Laravel loads environment specific .env files when running php artisan test

    help wanted 
    opened by Wyox 10
  • Update to laravel 6.0

    Update to laravel 6.0

    Hi I have problem to upgrade to laravel 6.0.

    When I run composer update I get: image

    If I put this package to dont-discover like this: image

    Every is OK.

    On Laravel 5.8 I don't have this problem.

    opened by michaloravec 10
  • Laravel Adapter: Don't render exception on partial artisan commands

    Laravel Adapter: Don't render exception on partial artisan commands

    Hey, love the package so far :) Very helpful!

    I have found one gripe which is annoying, and maybe a very edge case - but if you deem it fixable then I think it's definitely an improvement.

    So if you type something like

    php artisan migrates instead of php artisan migrate it throws a CommandNotFoundException

    However artisan already handles this and gives you suggestions - the suggestions get a bit battered due to the exception also rendering.

    Would it be possible to ignore that exception?

    1st-choice-spares_ _owen_batman

    opened by OwenMelbz 10
  • Dump output from tests is not fully displayed in console.

    Dump output from tests is not fully displayed in console.

    Example test:

    <?php
    
    namespace Tests\Feature;
    
    use Illuminate\Foundation\Testing\RefreshDatabase;
    use Tests\TestCase;
    
    class ExampleTest extends TestCase
    {
        /**
         * A basic test example.
         *
         * @return void
         */
        public function testBasicTest()
        {
            $response = $this->get('/')->dump();
    
            $response->assertStatus(200);
        }
    }
    

    Only a certain number of lines from the dump output are shown. While not a huge world shaking bug it makes switching from using PHPUnit directly a bit of a pain as something dumping the output is required for debugging a test.

    opened by peterfox 9
  • feat: add ignition features on collision

    feat: add ignition features on collision

    Hey @nunomaduro,

    Would it be possible to for the collision package to integrate with Flare, so one can share the public link with anybody they'll like to show their error with?

    enhancement 
    opened by webong 9
  • Switch every test case icons to semantic symbols

    Switch every test case icons to semantic symbols

    Every status icon is now using a semantic symbol to allow for quick scanning and visual cohesion:

    • RISKY & WARN both use ! (reasoning: PHPUnit provides an explanation of the error to understand what's going on.)
    • INCOMPLETE uses (reasoning: an ellipsis indicates an intentional omission of something. Here, a test.)
    • SKIPPED uses - (reasoning : run the suite, "minus" this test)
    enhancement 
    opened by AlexMartinFR 8
  • NunoMaduro\Collision\Adapters\Phpunit\Printer construct error

    NunoMaduro\Collision\Adapters\Phpunit\Printer construct error

    Php is dockerized in it's container:

    PHP 8.1.1 (cli) (built: Dec 18 2021 01:38:53) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.1.1, Copyright (c) Zend Technologies
        with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans
    

    Laravel Framework 8.83.26

    Phpunit:

    composer info phpunit/phpunit
    name     : phpunit/phpunit
    descrip. : The PHP Unit Testing framework.
    keywords : phpunit, testing, xunit
    versions : * 9.5.26
    type     : library
    license  : BSD 3-Clause "New" or "Revised" License (BSD-3-Clause) (OSI approved) https://spdx.org/licenses/BSD-3-Clause.html#licenseText
    homepage : https://phpunit.de/
    source   : [git] https://github.com/sebastianbergmann/phpunit.git 851867efcbb6a1b992ec515c71cdcf20d895e9d2
    dist     : [zip] https://api.github.com/repos/sebastianbergmann/phpunit/zipball/851867efcbb6a1b992ec515c71cdcf20d895e9d2 851867efcbb6a1b992ec515c71cdcf20d895e9d2
    path     : /app/vendor/phpunit/phpunit
    names    : phpunit/phpunit
    

    When running:

    $ docker-compose exec php_fpm bash
    $ php artisan test
    
    NunoMaduro\Collision\Adapters\Phpunit\Printer::__construct(): Argument #1 ($output) must be of type ?Symfony\Component\Console\Output\ConsoleOutputInterface, string given, called in /app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php on line 1230
    

    I traced it a bit a fallen back to:

    vendor/phpunit/phpunit/src/TextUI/TestRunner.php:1223

     private function createPrinter(string $class, array $arguments): ResultPrinter
        {
            $object = new $class(
                (isset($arguments['stderr']) && $arguments['stderr'] === true) ? 'php://stderr' : null,
                $arguments['verbose'],
                $arguments['colors'],
                $arguments['debug'],
                $arguments['columns'],
                $arguments['reverseList']
            );
    
            assert($object instanceof ResultPrinter);
    
            return $object;
        }
    

    Let me know if you need more details.

    FYI if I set that part (isset($arguments['stderr']) && $arguments['stderr'] === true) ? 'php://stderr' : null, to null only it works further.

    opened by mbaric 0
  • enable --no-ansi to work

    enable --no-ansi to work

    Before this

    ./artisan test --no-ansi
    PHPUnit 9.5.26 by Sebastian Bergmann and contributors.
    
    Unknown option "--no-ansi"
    

    But with this change I get uncolored output when wanted

    I have only tested by using this in my local Laravel project - but it works OK there

    NB./artisan test --help

    suggests

    --ansi|--no-ansi Force (or disable --no-ansi) ANSI output

    opened by seanburlington 1
  • PhpUnit test running in separate process can have confusing error output

    PhpUnit test running in separate process can have confusing error output

    Let me start by saying that this is kind of a weird corner case, and I am 100% to blame for ending up in this situation. And I don't know if Collision could (or should) display this type of error in a different way to avoid confusion, but I'll post this in case you want to.

    Here's a simple test that demonstrates the issue

    class ExampleTest extends TestCase
    {
        public function setUp(): void
        {
            parent::setUp();
            // Simulating a custom trait on the base TestCase printing a message to STDERR
            fwrite(STDERR, "\033[32mEnvironment validated.\033[0m\n");
        }
    
        /**
         * @runInSeparateProcess
         * @preserveGlobalState disabled
         */
        public function test_mocking_a_hard_dependency()
        {
            // Simulating a test that has to be run in a separate process in
            // order to allow mocking a static method call on a class that might already be loaded.
            $this->assertTrue(true);
        }
    }
    

    Normally PhpUnit doesn't care if you write to STDERR during tests, but if a test runs in a separate process, it will result in an exception getting thrown.

    Here's the output of from php artisan test: image

    Possibly because I'm an idiot, but looking at this output several times, I didn't realize that "Environment validated" was the exception. Especially because it's written in green, and also I'm used to seeing it every time I run my test suite. So in stead I focused on the highlighted code, which doesn't really provide any value in this case.

    Here's the output from vanilla PhpUnit: image

    Displayed like this, I instantly realized what the problem was.

    opened by mortenscheel 0
  • Exception stack trace is different between `phpunit` and `php artisan test` commands

    Exception stack trace is different between `phpunit` and `php artisan test` commands

    • Collision version: 6.3.1
    • PHPUnit version: 9.5.25
    • Laravel Version: 9.36.2
    • PHP Version: 8.0.22
    • Database Driver & Version: MySQL 5.7

    I'm noticing some large differences between the printed stack traces when running tests with the phpunit command and php artisan test, using the verbose flag.

    Most of the time i'm running php artisan test but the exception stack trace is not helpful at all. I'm not seeing application code in the stack lines, so I cannot figure out the origin of the exception in my code.

    When running php artisan test -v:

      • Tests\Feature\ExampleTest > example
       PHPUnit\Framework\ExceptionWrapper
    
      Attempted to lazy load [posts] on model [App\Models\User] but lazy loading is disabled.
    
      at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:559
        555▕         if (! $this->exists || $this->wasRecentlyCreated) {
        556▕             return;
        557▕         }
        558▕
      ➜ 559▕         throw new LazyLoadingViolationException($this, $key);
        560▕     }
        561▕
        562▕     /**
        563▕      * Get a relationship value from a method.
    
      1   vendor/phpunit/phpunit/src/Framework/TestCase.php:904
          PHPUnit\Framework\TestResult::run()
    
      2   vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
          PHPUnit\Framework\TestCase::run()
    
      3   vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
          PHPUnit\Framework\TestSuite::run()
    
      4   vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
          PHPUnit\Framework\TestSuite::run()
    
      5   vendor/phpunit/phpunit/src/TextUI/TestRunner.php:673
          PHPUnit\Framework\TestSuite::run()
    
      6   vendor/phpunit/phpunit/src/TextUI/Command.php:144
          PHPUnit\TextUI\TestRunner::run()
    
      7   vendor/phpunit/phpunit/src/TextUI/Command.php:97
          PHPUnit\TextUI\Command::run()
    
      8   vendor/phpunit/phpunit/phpunit:98
          PHPUnit\TextUI\Command::main()
    

    When running phpunit -v:

    Tests\Feature\ExampleTest::example
    Illuminate\Database\LazyLoadingViolationException: Attempted to lazy load [posts] on model [App\Models\User] but lazy loading is disabled.
    
    vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:559
    vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:518
    vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:453
    vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2172
    app/Actions/ExampleAction.php:122
    app/Actions/ExampleAction.php:61
    app/Jobs/ExampleJob.php:201
    app/Jobs/ExampleJob.php:117
    app/Jobs/ExampleJob.php:85
    vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
    vendor/laravel/framework/src/Illuminate/Container/Util.php:41
    vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
    vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
    vendor/laravel/framework/src/Illuminate/Container/Container.php:651
    vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:128
    vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:141
    vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:116
    vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:132
    vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:124
    vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:141
    vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:116
    vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:126
    vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:70
    vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:98
    vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php:43
    vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:253
    vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:229
    vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:77
    vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:338
    tests/Feature/ExampleTest.php:646
    

    Here the stack trace is much more evident, I can see which parts of my code caused the exception, so I can pinpoint my mistakes.

    opened by sebdesign 0
  • Printer: immediate feedback with unbuffered output

    Printer: immediate feedback with unbuffered output

    Unlike PHPUnit, and most PHPUnit printers, Pest does not emit output after each test in a test case, but rather, it buffers the entire collection of tests in a test case until the whole test file has completed. This is presumably because it wants to emit PASS/FAIL on the header line for the test case, which it can't know until all sub-tests have finished, but the upshot of this is there is no output for some time, especially for long-running tests, which is not a good user experience.

    We should like to know, as soon as the test runner knows, what the result of running each test is. If that means reformatting the output so it is less pretty, and the PASS/FAIL summary appears at the foot of each test case rather than in the head, then so be it: I strongly support functionality over form when the two are otherwise in conflict.

    The following is just a suggestion of an alternative layout that would permit immediate feedback for each test case.

    image

    opened by Bilge 0
Owner
Nuno Maduro
Software engineer at @laravel — working on Laravel, Forge, and Vapor. Created @pestphp, @laravel-zero, collision, larastan, php insights, termwind, and more.
Nuno Maduro
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!

CLIFramework CLIFramework is a command-line application framework, for building flexiable, simple command-line applications. Commands and Subcommands

Yo-An Lin 428 Dec 13, 2022
🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.

Termwind Termwind allows you to build unique and beautiful PHP command-line applications, using the Tailwind CSS API. In short, it's like Tailwind CSS

Nuno Maduro 1.8k Dec 30, 2022
BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.

BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.

Snicco 5 Oct 7, 2022
👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀

Alpine Day Schedule a command-line tool that gives you the Alpine Day 2021 schedule in your timezone. ?? Quick start Requires PHP 7.4+ # First, instal

Nuno Maduro 11 Jun 10, 2021
PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.

PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal. ??

Nuno Maduro 32 Dec 26, 2022
Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check. Installation / Usage Requires PHP 8.0+ First, install Patr

Nuno Maduro 237 Nov 14, 2022
A PHP command line tool used to install shlink

Shlink installer A PHP command line tool used to install shlink. Installation Install this tool using composer.

null 8 Nov 3, 2022
Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone.

Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone. ?? Quick start Requires PHP 7.4+ # First, install: c

Nuno Maduro 101 Sep 16, 2022
A simple command-line tool whose aim is to facilitate the continous delivery of PHP apps

Deployer Simple command-line tool that aims to facilitate the continous delivery of PHP apps, particularly Laravel apps. Imagine you want to update yo

Fernando Bevilacqua 4 Sep 8, 2021
A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies.

Front End Compiler A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies. The minif

Happy Medium 2 Nov 12, 2021
Simple command-line tool to access HiWeb account information

Simple command-line tool to access HiWeb account information.

Milad Nekofar 2 Dec 26, 2022
Lovely PHP wrapper for using the command-line

ShellWrap What is it? It's a beautiful way to use powerful Linux/Unix tools in PHP. Easily and logically pipe commands together, capture errors as PHP

James Hall 745 Dec 30, 2022
A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 5.4 and above. Releases For an overview of the releas

null 324 Dec 8, 2022
Command-Line Interface tools

Aura.Cli Provides the equivalent of request ( Context ) and response ( Stdio ) objects for the command line interface, including Getopt support, and a

Aura for PHP 102 Dec 31, 2022
Another Command Line Argument Parser

Optparse — Another Command Line Argument Parser Install 1. Get composer. 2. Put this into your local composer.json: { "require": { "chh/optparse

Christoph Hochstrasser 18 Nov 1, 2019
Twitter raffles in the command line, with PHP and minicli

Rafflebird Rafflebird is a highly experimental CLI application for giveaways / raffles on Twitter, built in PHP with Minicli. Disclaimer: The recent s

Erika Heidi 33 Nov 16, 2022
A command line code generator for Drupal.

Drupal Code Generator A command line code generator for Drupal. Installation Download the latest stable release of the code generator.

Ivan 227 Dec 14, 2022
Command-line control panel for Nginx Server to manage WordPress sites running on Nginx, PHP, MySQL, and Let's Encrypt

EasyEngine v4 EasyEngine makes it greatly easy to manage nginx, a fast web-server software that consumes little memory when handling increasing volume

EasyEngine 2k Jan 4, 2023
Generic PHP command line flags parse library

PHP Flag Generic PHP command line flags parse library Features Generic CLI options and arguments parser. Support set value data type(int,string,bool,a

PHP Toolkit 23 Nov 13, 2022