Giter Site home page Giter Site logo

nunomaduro / collision Goto Github PK

View Code? Open in Web Editor NEW
4.4K 32.0 154.0 2.24 MB

๐Ÿ’ฅ Collision is a beautiful error reporting tool for command-line applications

Home Page: https://nunomaduro.com

License: MIT License

PHP 86.42% Blade 13.44% JavaScript 0.13%
collision laravel php console cli errors exceptions hacktoberfest

collision's Introduction

Collision logo
Collision code example

Build Status Quality Score Total Downloads 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 8.2+

Require Collision using Composer:

composer require nunomaduro/collision --dev

Version Compatibility

Laravel Collision PHPUnit Pest
6.x 3.x
7.x 4.x
8.x 5.x
9.x 6.x
10.x 6.x 9.x 1.x
10.x 7.x 10.x 2.x
11.x 8.x 10.x 2.x
11.x 8.x 11.x 3.x

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

composer require nunomaduro/collision:^5.0 --dev

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

License

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

Logo by Caneco.

collision's People

Contributors

alecrabbit avatar alexander-schranz avatar alexmartinfr avatar andrey-helldar avatar crynobone avatar fabio-ivona avatar freekmurze avatar fridzema avatar grahamcampbell avatar ianrodrigues avatar joaorobertopb avatar jubeki avatar karinarastsinskagia avatar kitbs avatar krisell avatar kudashevs avatar lukeraymonddowning avatar mvdnbrk avatar nicolascarpi avatar nobuf avatar nshiro avatar nunomaduro avatar owenvoke avatar paupenin avatar riley19280 avatar saeedhosseiinii avatar simonhamp avatar synchro avatar taylorotwell avatar yamadashy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

collision's Issues

bug in writer

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to NunoMaduro\Collision\Writer::__construct() must implement interface Symfony\Component\Console\Output\OutputInterface or be null, instance of NunoMaduro\Collision\SolutionsRepositories\NullSolutionsRepository

in laravel-zero ( new project ) errors are missed up

A couple issues with the PHPUnit printer

So there are two main issues I have with the PHPUnit printer:

  1. If you pass --coverage-text into phpunit, it doesn't give the coverage information.
  2. If you dump() inside your tests, the last couple lines of the dump get stripped out, because of how you are replacing output in the console.
Images!

image

image

I'll submit a PR for these if I have the time, but I wanted to record these here in case someone else wants to tackle them.

Hide exception trace and code block if not in debug mode

Using Collission with Laravel 5.6 I have the following environment variables

APP_ENV=production
APP_DEBUG=false

but Collission still shows the whole error on the exception I've just thrown

   Exception  : Cannot run this commands in production! ๐Ÿ˜ฑ

  at /Users/lloople/Code/project/app/Console/Commands/Refactor/RefactorClientCommand.php: 17
  13: 
  14:     public function handle()
  15:     {
  16:         if (app()->environment('production')) {
  17:             throw new \Exception("Cannot run this commands in production! ๐Ÿ˜ฑ");
  18:         }
  19: 
  20:         $this->getClients()->each(function (Client $client) {
  21:             try {
  22: 

  Exception trace:

  1   App\Console\Commands\Refactor\RefactorClientCommandContract::handle()
      /Users/lloople/Code/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 29

  2   call_user_func_array([])
      /Users/lloople/Code/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 29

  Please use the argument -v to see more details.

PHPUnit Adapter: PHPUnit expectException is not handled

Using the $this->expectException(Exception::class) method, when the exception didn't got throw, Collision got the following error:

PHPUnit\Framework\ExpectationFailedException : Failed asserting that exception of type "Respect\Validation\Exceptions\ValidationException" is thrown.
PHP Fatal error:  Uncaught TypeError: Argument 1 passed to NunoMaduro\Collision\Writer::renderEditor() must be an instance of Whoops\Exception\Frame, null given, called in /Users/nunomaduro/Work/af-talent/af-event-builder/vendor/nunomaduro/collision/src/Writer.php on line 93 and defined in /Users/nunomaduro/Work/af-talent/af-event-builder/vendor/nunomaduro/collision/src/Writer.php:201

ExceptionHandler::report() mu st be an instance of Exception

Hi,

In seeding process by console, I got this message error:

"Symfony\Component\Debug\Exception\FatalThrowableError : Type error: Argument
1 passed to NunoMaduro\Collision\Adapters\Laravel\ExceptionHandler::report() mu
st be an instance of Exception, instance of Error given, called in C:\proyectos
laravel\onyx\vendor\nwidart\laravel-modules\src\Commands\SeedCommand.php on line
179"

I don't understand this issue, because I can't read the real error message and I don't know what happens!

I'm using Laravel 5.6 and nwidart/laravel-modules v3.0

Thanks for your help!

Improve output formatting

As discussed on Twitter, I think it would be useful to display diff results returned by the php artisan test command more in line with those from phpunit, i.e. improved formatting with line breaks and indentation.

A particular example is the assertDatabaseHas helper which produces the following sample output when it fails to locate a record:

2020-03-12-phpunit-assert-database-has

In contrast, php artisan test shows:

2020-03-12-collision-assert-database-has

Adding collision to a package laravel package

I have a simple package that I'm adding tests to for the first time, I enjoy working with collision in laravel so I was hoping I could also add it to a laravel package.

So far I've installed collision:

composer require nunomaduro/collision --dev

I've edited the I also have phpunit 9.0.1, I actually meant to install 8.5.1 so I could run tests from inside phpstorm.
if I run tests from the command line now, I end up with the following:
Screen Shot 2020-03-05 at 3 50 54 PM

Once I add collision to phpunit.xml I get the following error:

Screen Shot 2020-03-05 at 3 53 03 PM

I've attempted to register collision in the boot and boot methods of the service provider, however neither seem to remove this. Can you let me how a package should be configured to allow collision?

Thanks

Tests stop without any information

Hi @nunomaduro, I have started using your repo php artisan test, but I am facing a problem after some while tests stop without any error...

I have around 700 tests. And I am using PHPUnit and it takes roughly Time: 7.57 minutes, Memory: 317.00 MB.

My actual command: php -d memory_limit=512M vendor/bin/phpunit --bootstrap vendor/autoload.php --testdox tests

With your: PHP artisan test I got an error:

Screenshot 2020-03-21 at 16 46 27

Overriding Laravel's App\Exceptions\Handler::renderForConsole() is no longer possible

I wanted to try creating a nicer output for ValidationException so I could see which validation fields and messages were detected. It looked like overriding renderForConsole would do what I wanted. However, the code I put in there never got called.

The code I was writing looked something like this:

image

I eventually found someone had already brought this up as an issue on laravel/framework#23515. I thought @thomasfw had a reasonable point and I am hoping to find a way around this. :)

We should be able to handle specific Exceptions when required, with all others being passed on to Collision's ExceptionHandler to be rendered nicely.

That is more or less what I expected to happen. It took me quite some time to figure out why it wasn't working like this. I tracked it down to this part of the code:

https://github.com/nunomaduro/collision/blob/stable/src/Adapters/Laravel/ExceptionHandler.php#L74-L88

Honestly, I think it will be technically difficult to solve. But I'm happy to help however I can as I'm sure it can be solved. :)

The only easy way I found to do this without hacking framework or collision itself was the following, which I'm not super happy with, but better than nothing?

namespace App\Console;

class Kernel extends ConsoleKernel
{
    protected function renderException($output, Exception $e)
    {
        if ($this->renderValidationException($output, $e)) {
            return;
        }

        parent::renderException($output, $e);
    }

    protected function renderValidationException($output, Exception $e): bool
    {
        if (! $e instanceof ValidationException) {
            return false;
        }

        // send validation messages to $output

        return true;
    }
}

What I think is more likely possible is to not break after a handler does its work. For example, the following would always execute collision even if a validation exception is thrown:

namespace App\Console;

class Kernel extends ConsoleKernel
{
    protected function renderException($output, Exception $e)
    {
        $this->renderValidationException($output, $e);

        parent::renderException($output, $e);
    }

    protected function renderValidationException($output, Exception $e): bool
    {
        if (! $e instanceof ValidationException) {
            return;
        }

        // send validation messages to $output
    }
}

... to implement that, I think it would look something like this:

    /**
     * {@inheritdoc}
     */
    public function renderForConsole($output, Exception $e)
    {
        if ($e instanceof SymfonyConsoleExceptionInterface) {
            $this->appExceptionHandler->renderForConsole($output, $e);
        } else {
            // always give the app exception handler a crack at it...
            $this->appExceptionHandler->renderForConsole($output, $e);

            $handler = $this->container->make(ProviderContract::class)
                ->register()
                ->getHandler()
                ->setOutput($output);
            $handler->setInspector((new Inspector($e)));
            $handler->handle();
        }
    }

Unfortunately, I'm not certain this wouldn't end up in some sort of infinite recursion.

Anyway, this is as far as I've come so far. :) If this is something I can help with, let me know! Would love to have an officially supported solution instead of what I have hacked together.

PHPUnit: Support assert diffs

I made an example repo:

https://github.com/luispabon/collision-diff

Run tests without: vendor/bin/phpunit
Run tests with: vendor/bin/phpunit -c ./phpunit-with-collision.xml

I can see that collision is adding it's pretty output at the very end, but it's not showing the diff in the json string asserts on the test - that's still at the original phpunit output. In this particular case (typical for an end-to-end api functional test), you need to scroll all the way up to find the diffs.

This would be the case I imagine with any other asserts that produce diffs.

Suggestion: add the assert diff beneath the current Collision output, with colour coding.

Here's a screenshot - the terminal on the right shows what it could potentially be displayed beneath the current Collision output:

image

The output from the left is simply the original diff from phpunit in a file, displayed by pygmentize.

Missing branch aliases

Could you add branch aliases, so composer knows which branches are 2.x, 3.x, and 4.x please?

deprecated packes

getting this error in composer now...

jakub-onderka/php-console-color       v0.2    v0.2
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
jakub-onderka/php-console-highlighter v0.4    v0.4   Highlight PHP code in terminal
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.

Schermafbeelding 2020-04-03 om 20 11 27

PhpUnit 8 support

The listener needs to be modified to support PHPUnit 8:

if (class_exists(\PHPUnit\Runner\Version::class) && substr(\PHPUnit\Runner\Version::id(), 0, 2) === '7.') {

to

if (class_exists(\PHPUnit\Runner\Version::class) && substr(\PHPUnit\Runner\Version::id(), 0, 2) === '8.') {

Support PHPUnit 7

Just a head's up that PHPUnit 7 has changed the format of TestListener::addError, which is incompatible with the current version of this package. See https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-7.0.md#changed.

PHP Fatal error: Declaration of NunoMaduro\Collision\Adapters\Phpunit\Listener::addError(PHPUnit\Framework\Test $test, Exception $e, $time) must be compatible with PHPUnit\Framework\TestListener::addError(PHPUnit\Framework\Test $test, Throwable $t, float $time): void in /vagrant/vendor/nunomaduro/collision/src/Adapters/Phpunit/Listener.php on line 33

CollisionServiceProvider::register() should not try to instantiate ExceptionHandler

$appExceptionHandler = $this->app->make(ExceptionHandlerContract::class);

If the application's implementation of ExceptionHandler has dependencies (in its constructor) provided by another Service Provider, instantiation of ExceptionHandler may fail (depending on Service Provider load order). It's generally a very bad idea to do anything other than registering container bindings in a Provider's register() method. From the docs:

Within the register method, you should only bind things into the service container. You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method.

As mentioned previously, within the register method, you should only bind things into the service container. You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method. Otherwise, you may accidentally use a service that is provided by a service provider which has not loaded yet.

Upgrade nunomaduro/collision to latest version

This package is broken in laravel 6.1

Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method NunoMaduro\Collision\Adapters\Laravel\ExceptionHandler::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.

Ignore files in a directory

I would like to ignore specified directories from the output.

For example, in Laravel the TestResponse class may be extended to give more assertion methods - but I do not want to view this file in the output.

It looks as if the list in this method would fulfil the requirements:

($writer = $this->createWriter())->ignoreFilesIn(['*/FakeProgram/*'])

However, the list is hard-coded:

$writer->ignoreFilesIn([

Would it be possible to configure the directories which are ignored?

Does not work with Laravel 5.8

  • Had it installed on Laravel 5.7
  • Upgraded to 5.8
  • outcome:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 8 installs, 8 updates, 4 removals
  - Removing lcobucci/jwt (3.2.5)
  - Removing laravel/slack-notification-channel (v1.0.3)
  - Removing laravel/nexmo-notification-channel (v1.0.1)
  - Removing nexmo/client (1.6.2)
  - Installing phpoption/phpoption (1.5.0): Loading from cache
  - Updating vlucas/phpdotenv (v2.6.1 => v3.3.2): Loading from cache
  - Updating laravel/framework (v5.7.28 => v5.8.2): Loading from cache
  - Updating folklore/graphql (v1.1.0.1 => v1.1.0.1): Loading from cache
  - Installing psr/http-factory (1.0.0): Loading from cache
  - Updating zendframework/zend-diactoros (1.8.6 => 2.1.1): Loading from cache
  - Installing symfony/options-resolver (v4.2.3): Loading from cache
  - Installing clue/stream-filter (v1.4.0): Loading from cache
  - Installing php-http/message-factory (v1.0.2): Loading from cache
  - Installing php-http/message (1.7.2): Loading from cache
  - Installing php-http/discovery (1.6.1): Loading from cache
  - Installing php-http/client-common (1.9.1): Loading from cache
  - Updating sentry/sentry (1.10.0 => 2.0.0): Loading from cache
  - Downgrading sentry/sentry-laravel (0.11.0 => 0.8.0): Loading from cache
  - Updating spatie/laravel-csp (2.1.3 => 2.2.0): Loading from cache
php-http/message suggests installing slim/slim (Used with Slim Framework PSR-7 implementation)
php-http/discovery suggests installing puli/composer-plugin (Sets up Puli which is recommended for Discovery to work. Check http://docs.php-http.org/en/latest/discovery.html for more details.)
php-http/client-common suggests installing php-http/logger-plugin (PSR-3 Logger plugin)
php-http/client-common suggests installing php-http/cache-plugin (PSR-6 Cache plugin)
php-http/client-common suggests installing php-http/stopwatch-plugin (Symfony Stopwatch plugin)
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
PHP Fatal error:  Class NunoMaduro\Collision\Adapters\Laravel\ExceptionHandler contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Illuminate\Contracts\Debug\ExceptionHandler::shouldReport) in /vagrant/project/vendor/nunomaduro/collision/src/Adapters/Laravel/ExceptionHandler.php on line 27
PHP Fatal error:  Uncaught Error: Cannot instantiate abstract class NunoMaduro\Collision\Adapters\Laravel\ExceptionHandler in /vagrant/project/vendor/nunomaduro/collision/src/Adapters/Laravel/CollisionServiceProvider.php:44
Stack trace:
#0 /vagrant/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(791): NunoMaduro\Collision\Adapters\Laravel\CollisionServiceProvider->NunoMaduro\Collision\Adapters\Laravel\{closure}(Object(Illuminate\Foundation\Application), Array)
#1 /vagrant/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(671): Illuminate\Container\Container->build(Object(Closure))
#2 /vagrant/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(619): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array)
#3 /vagrant/project/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(757): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 /vagrant/project/vendor/laravel/framework/src/Illuminate/Foun in /vagrant/project/vendor/nunomaduro/collision/src/Adapters/Laravel/CollisionServiceProvider.php on line 44
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

Basically, artisan doens't work:

$ ./artisan --version
PHP Fatal error:  Class NunoMaduro\Collision\Adapters\Laravel\ExceptionHandler contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Illuminate\Contracts\Debug\ExceptionHandler::shouldReport) in /vagrant/project/vendor/nunomaduro/collision/src/Adapters/Laravel/ExceptionHandler.php on line 27
PHP Fatal error:  Uncaught Error: Cannot instantiate abstract class NunoMaduro\Collision\Adapters\Laravel\ExceptionHandler in /vagrant/project/vendor/nunomaduro/collision/src/Adapters/Laravel/CollisionServiceProvider.php:44
Stack trace:
#0 /vagrant/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(791): NunoMaduro\Collision\Adapters\Laravel\CollisionServiceProvider->NunoMaduro\Collision\Adapters\Laravel\{closure}(Object(Illuminate\Foundation\Application), Array)
#1 /vagrant/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(671): Illuminate\Container\Container->build(Object(Closure))
#2 /vagrant/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(619): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array)
#3 /vagrant/project/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(757): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 /vagrant/project/vendor/laravel/framework/src/Illuminate/Foun in /vagrant/project/vendor/nunomaduro/collision/src/Adapters/Laravel/CollisionServiceProvider.php on line 44

PHPUnit Adapter / Accessibility: low contrast on light terminal

Problem:
When using a terminal with light color preset*, some contrast issues appears.

  • The test suite run summary is using bright ANSI colors, which are hard / impossible to read on a white background:

Capture dโ€™eฬcran 2020-06-07 aฬ€ 14 42 41

Suggested solution:
Here is what it could look like with normal yellow & green ANSI colors, and black for the Tests & Time labels:

Capture dโ€™eฬcran 2020-06-07 aฬ€ 16 24 29


Problem:

  • The PASS label colors aren't contrasted enough on a terminal with light background. It makes them hard to read (WARN label's colors are almost OK according to the WCAG test, but still look wrong):

CollisionPestActual

The Jest framework use the terminal's background color as foreground color for its text label, which looks better at first sight. This actually increase contrast with a black background, however it lowers it with a white background, especially for the WARN label which becomes even harder to read. Here is what it would look like for Collision with PHPUnit / Pest:

CollisionPestJest-like

Suggested solution:
A more interesting all-around solution would be to use bright ANSI colors as label background everywhere. This is not the solution providing the better contrast in every situation, but it has the advantage of displaying a more unified contrast overall and improving both WARN & PASS :

CollisionPestHarmonized

Only drawback is that it lowers FAIL contrast, but it still hover around the WCAG 3 target for big text. (Plus, the actual shade of red will depend on the terminal theme).


* These examples use iTerm 2 with the default Light background color preset, and Snazzy as the dark color preset.

Some "lag" on v5-BETA

After upgrading to v5, just noticed some "lag" between test cases, what increases total time of tests. On previous version total time were very similar.

Without collision (2.5 seconds)

image

With collision (3.93)

image

Running with stderr causes exception

Description
Running with the --stderr arg causes this below exception:

> vendor/bin/phpunit --stderr

In PrinterContents.php line 56:
                                                                               
  Argument 1 passed to NunoMaduro\Collision\Adapters\Phpunit\Printer::__const  
  ruct() must be an instance of Symfony\Component\Console\Output\ConsoleOutpu  
  t or null, string given, called in /Users/<name>/PhpstormProjects/service  
  s/vendor/phpunit/phpunit/src/TextUI/TestRunner.php on line 1159   

Not sure if you want to do anything about it since I only encountered this after upgrading to v4 and using the new Printer class. I have removed the --stderr argument and it works like a charm ๐Ÿ˜„

Environment
PHP Version: 7.4
PHPUnit Version: 9.1.1
Package Version: 4.2.0

Problem with Telescope installed and enabled

  • Laravel Version: 7.0.2
  • PHP Version: 7.4.3 (but not relevant)
  • Database Driver & Version: not relevant
  • nunomaduro/collision: 4.1.2
  • laravel/telescope: 3.1.1
  • phpunit/phpunit: 8.5.2

Description:

As requested by @nunomaduro on Twitter I'm describing a strange behavior when running the php artisan test command if Telescope is installed and enabled (Telescope is enabled by default after a fresh installation). This behavior is only visible if you have query execution in your Tests. This behavior is not visible if you run the standard phpunit command

Steps To Reproduce:

  1. Fresh Laravel 7 installation:
laravel new laravel7app
  1. Install Laravel Telescope
2.1
composer require laravel/telescope --dev
2.2
php artisan telescope:install
2.3
php artisan migrate
  1. Create a test with query execution in tests/Feature/ExampleTest.php
<?php

namespace Tests\Feature;

use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class ExampleTest extends TestCase
{
    use RefreshDatabase;

    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $user = factory(User::class)->create();

        $this->assertDatabaseHas('users', $user->only('email'));
    }
}

Results

When running php artisan test

php artisan test

   PASS  Unit\ExampleTest
  โœ“ basic test

   FAIL  Feature\ExampleTest
  โœ• basic test

  Tests:  1 failed, 1 passed

   ErrorException 

  Trying to access array offset on value of type null

  at vendor/laravel/telescope/src/Watchers/QueryWatcher.php:46
    42|             'bindings' => [],
    43|             'sql' => $this->replaceBindings($event),
    44|             'time' => number_format($time, 2),
    45|             'slow' => isset($this->options['slow']) && $time >= $this->options['slow'],
  > 46|             'file' => $caller['file'],
    47|             'line' => $caller['line'],
    48|             'hash' => $this->familyHash($event),
    49|         ])->tags($this->tags($event)));
    50|     }

When running phpunit

phpunit         
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.

..                                                                  2 / 2 (100%)

Time: 433 ms, Memory: 24.00 MB

OK (2 tests, 2 assertions)

Quick and easy steps to mitigate the issue

Add TELESCOPE_ENABLED=false in your phpunit.xml file.

<server name="TELESCOPE_ENABLED" value="false"/>

Screenshot 2020-03-04 at 11 34 30

Proposed solutions

  1. Add information note in the Laravel 7 upgrade guide:
    Add TELESCOPE_ENABLED=false in your phpunit.xml file.
<server name="TELESCOPE_ENABLED" value="false"/>
  1. Auto-disable telescope when executing php artisan test by default.
    Probably should be added somewhere here:
    File: collision/src/Adapters/Laravel/Commands/TestCommand.php
/**
     * Gets an array with phpunit envs detected on the phpunit.xml file.
     *
     * @return array
     */
    protected function phpunitEnvs()
    {
        $envs = [];

        if (! file_exists($file = base_path('phpunit.xml'))) {
            $file = base_path('phpunit.xml.dist');
        }

        if (file_exists($file)) {
            /** @var \SimpleXMLElement $xml */
            $xml = simplexml_load_string((string) file_get_contents($file));

            if (is_iterable($xml->php->server)) {
                foreach ($xml->php->server as $env) {
                    if (isset($env['name'])) {
                        $envs[$env['name']->__toString()] = false;
                    }
                }
            }

            if (is_iterable($xml->php->env)) {
                foreach ($xml->php->env as $env) {
                    if (isset($env['name'])) {
                        $envs[$env['name']->__toString()] = false;
                    }
                }
            }
        }

        return $envs;
    }

Collision printer class stoping on failure

Hello,

I just bumped my app to Laravel 7 and started using the PHPUnit 9. When I run my tests without the printer class they don't stop at first failure; however, when I try to set the printer class at phpunit.xml they stop at first failure.

Is there any way to configure this?

With printerClass:

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

image

Without printer class:
image

Which branch is v4?

laravel/laravel's develop branch depends on collision v4. Where is it? ;)

Exception thrown with Laravel 7 when running php artisan test

After following the installation guide, I was trying to run my tests with php artisan test. This triggered the following error:

> php artisan test

  RuntimeException 

  Running Collision ^5.0 artisan test command requires Laravel ^8.0.

  at vendor/nunomaduro/collision/src/Adapters/Laravel/Commands/TestCommand.php:71
     67โ–•         }
     68โ–• 
     69โ–•         // @phpstan-ignore-next-line
     70โ–•         if ((int) \Illuminate\Foundation\Application::VERSION[0] < 8) {
  โžœ  71โ–•             throw new RuntimeException('Running Collision ^5.0 artisan test command requires Laravel ^8.0.');
     72โ–•         }
     73โ–• 
     74โ–•         $options = array_slice($_SERVER['argv'], $this->option('without-tty') ? 3 : 2);
     75โ–• 

      +14 vendor frames 
  15  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

At the moment of writing this report, Laravel 8 is not yet released, so I cannot simply update Laravel.
I can run my tests with ./vendor/bin/pest but it would be great if I can just use the built-in artisan commands.

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

Exception thrown while installing collition 5.0 in laravel 6

composer require nunomaduro/collision:"^5.0" --dev --update-with-dependencies
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Conclusion: don't install nunomaduro/collision v5.0.0-BETA4
- Conclusion: don't install nunomaduro/collision v5.0.0-BETA3
- Conclusion: don't install nunomaduro/collision v5.0.0-BETA2
- Conclusion: remove symfony/console v4.4.10
- Installation request for nunomaduro/collision ^5.0 -> satisfiable by nunomaduro/collision[v5.0.0-BETA1, v5.0.0-BETA2, v5.0.0-BETA3, v5.0.0-BETA4].
- Conclusion: don't install symfony/console v4.4.10
- nunomaduro/collision v5.0.0-BETA1 requires symfony/console ^5.0 -> satisfiable by symfony/console[5.0.x-dev, 5.1.x-dev, 5.2.x-dev, v5.0.0, v5.0.0-BETA1, v5.0.0-BETA2, v5.0.0-RC1, v5.0.1, v5.0.10, v5.0.2, v5.0.3, v5.0.4, v5.0.5, v5.0.6, v5.0.7, v5.0.8, v5.0.9, v5.1.0, v5.1.0-BETA1, v5.1.0-RC1, v5.1.0-RC2, v5.1.1, v5.1.2].
- Can only install one of: symfony/console[5.0.x-dev, v4.4.10].
- Can only install one of: symfony/console[5.1.x-dev, v4.4.10].
- Can only install one of: symfony/console[5.2.x-dev, v4.4.10].
- Can only install one of: symfony/console[v5.0.0, v4.4.10].
- Can only install one of: symfony/console[v5.0.0-BETA1, v4.4.10].
- Can only install one of: symfony/console[v5.0.0-BETA2, v4.4.10].
- Can only install one of: symfony/console[v5.0.0-RC1, v4.4.10].
- Can only install one of: symfony/console[v5.0.1, v4.4.10].
- Can only install one of: symfony/console[v5.0.10, v4.4.10].
- Can only install one of: symfony/console[v5.0.2, v4.4.10].
- Can only install one of: symfony/console[v5.0.3, v4.4.10].
- Can only install one of: symfony/console[v5.0.4, v4.4.10].
- Can only install one of: symfony/console[v5.0.5, v4.4.10].
- Can only install one of: symfony/console[v5.0.6, v4.4.10].
- Can only install one of: symfony/console[v5.0.7, v4.4.10].
- Can only install one of: symfony/console[v5.0.8, v4.4.10].
- Can only install one of: symfony/console[v5.0.9, v4.4.10].
- Can only install one of: symfony/console[v5.1.0, v4.4.10].
- Can only install one of: symfony/console[v5.1.0-BETA1, v4.4.10].
- Can only install one of: symfony/console[v5.1.0-RC1, v4.4.10].
- Can only install one of: symfony/console[v5.1.0-RC2, v4.4.10].
- Can only install one of: symfony/console[v5.1.1, v4.4.10].
- Can only install one of: symfony/console[v5.1.2, v4.4.10].
- Installation request for symfony/console (locked at v4.4.10) -> satisfiable by symfony/console[v4.4.10].

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.

Writer not respecting --no-ansi when displaying the editor

When calling a Laravel Command passing --no-ansi flag, the method renderEditor(Frame $frame) in Writer class send the contents to the highlighter and outputs with color regardless of the flag.

Expected: When an Exception occurs inside a Command that has been called with --no-ansi, display everything in the terminal without any color.

Current: Everything but the editor is correctly displayed. The editor part has color.

How to use in lumen?

How to use in lumen?
What is console command (instead of php laravel-zero inspiring)?

Fatal error when phpunit test case has no methods

This is the error

PHPUnit 6.5.5 by Sebastian Bergmann and contributors.

Fatal error: Uncaught Error: Call to a member function stopOnFailure() on null in /vendor/nunomaduro/collision/src/Adapters/Phpunit/Listener.php:141
Stack trace:
#0 /vendor/phpunit/phpunit/src/Framework/TestResult.php(395): NunoMaduro\Collision\Adapters\Phpunit\Listener->startTest(Object(PHPUnit\Framework\WarningTestCase))
#1 /vendor/phpunit/phpunit/src/Framework/TestResult.php(637): PHPUnit\Framework\TestResult->startTest(Object(PHPUnit\Framework\WarningTestCase))
#2 /vendor/phpunit/phpunit/src/Framework/TestCase.php(894): PHPUnit\Framework\TestResult->run(Object(PHPUnit\Framework\WarningTestCase))
#3 /vendor/phpunit/phpunit/src/Framework/TestSuite.php(755): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult))
#4 /vendor/phpunit/phpunit/src/Framework/TestSuite.php(755): PHPUnit\Fr in /vendor/nunomaduro/collision/src/Adapters/Phpunit/Listener.php on line 141

Expected output

PHPUnit 6.5.5 by Sebastian Bergmann and contributors.

W                                                                   1 / 1 (100%)

Time: 105 ms, Memory: 6.00MB

There was 1 warning:

1) Warning
No tests found in class "Tests\MyTest".

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.

On testing exceptions Collision should not render exceptions

In Laravel, we may want to test if an exception is throw correctly. Given the following routes/web.php:

Route::get('/', function () {
    throw new Exception("This is an exception");
});

And the following test:

$response = $this->get('/');
$response->assertStatus(500);

Our application exception handler should not render an exception.

Less verbose printer

It would be nice to have a less verbose option. Just that "dots", but keep the "beauty error handler".

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

PHPUnit listener doesn't plays well with Bugsnag

I'm not really sure if I should report this to the Bugsnag Laravel repository or this one. I get the following stack trace when I trigger a failing PHPUnit test with the Collision listener enabled. When I disable the listener I get the normal stack trace.

Might be related to this issue but unsure: bugsnag/bugsnag-laravel#263

Laravel 5.5.3
PHP 7.1.1
Collision 1.1.9
Bugsnag-Laravel 2.9.0

> phpunit --stop-on-failure 'tests/Functional/Accounts/AccountsTest.php'
PHPUnit 6.3.0 by Sebastian Bergmann and contributors.


  Laravel\BrowserKitTesting\HttpException : A request to [http://localhost/account/selec] failed. Received status code [404].

  at [internal]: 0
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Container/Container.php:918
Stack trace:
#0 /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Container/Container.php(758): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Container/Container.php(586): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array)
#3 /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(721): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 /var/www/development.promoter/current/ven in /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 918
PHP Fatal error:  Uncaught Error: Call to undefined method Bugsnag\BugsnagLaravel\Facades\Bugsnag::notifyException() in /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:221
Stack trace:
#0 /var/www/development.promoter/current/app/Exceptions/Handler.php(54): Illuminate\Support\Facades\Facade::__callStatic('notifyException', Array)
#1 /var/www/development.promoter/current/vendor/nunomaduro/collision/src/Adapters/Laravel/ExceptionHandler.php(70): BeatSwitch\Exceptions\Handler->report(Object(Symfony\Component\Debug\Exception\FatalErrorException))
#2 /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(81): NunoMaduro\Collision\Adapters\Laravel\ExceptionHandler->report(Object(Symfony\Component\Debug\Exception\FatalErrorException))
#3 /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(123): Illuminate\Foundation\Bootstrap\HandleExceptions->han in /var/www/development.promoter/current/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 221

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

No application encryption key has been specified.

  • v4.2.0 - when run php artisan test command crush with No application encryption key has been specified.
  • v4.1.3 - when run php artisan test command crush with No application encryption key has been specified.
  • v4.1.2 - all right

Test command refreshes all migrations

When I run php artisan test, this refreshes all database migrations. I set memory database in my phpunit.xml like below.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>

        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <php>
        <server name="APP_ENV" value="testing"/>
        <env name="TELESCOPE_ENABLED" value="false"/>
        <env name="LOG_CHANNEL" value="single"/>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>
        <env name="SCOUT_DRIVER" value="null"/>
        <server name="BCRYPT_ROUNDS" value="4"/>
        <server name="CACHE_DRIVER" value="array"/>
        <server name="MAIL_DRIVER" value="array"/>
        <server name="QUEUE_CONNECTION" value="sync"/>
        <server name="SESSION_DRIVER" value="array"/>
    </php>
</phpunit>

I also use RefreshDatabase trait in my TestCase.php

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
    use RefreshDatabase;

Is this a normal behavior? or Do I have an option for using memory database?

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.

How to use listener version

I used to use our own result-printer alongside listener for uber beautiful output.

However, just updated to Laravel 7 and the listener no longer works?

Is there still a way to use the Collision listener and not as printerClass?

Stop on failure gets ignored

Environment

Collision version: v4.1.3
Laravel version: v7.0.6
PHPUnit version: v8.5.1

Description

Running the command php artisan test stops on the first failure even when all stopOn settings are set to false.

This seems to be an issue with the Style::writeError() method which throws exit(1) at the end. Removing that line makes tests continue, however, the output behaves weirdly then as the status of the class is printed twice.

How to reproduce

  • Make two tests where one fails (must be declared as first) and the second one is successful
  • Run php artisan test

Support symfony/console ^5.0

Can you release a new tag with a change for allowing for symfony/console ~2.8|~3.3|~4.0|~5.0 in composer.json?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.