larapack / voyager-hooks

Hooks system integrated into Voyager.
MIT License
208 stars 22 forks source link

Trying to obtain code coverage on Laravel 5.5 fails if this package is used #16

Closed eithed closed 6 years ago

eithed commented 6 years ago

Description:

Following the change in https://laravel.com/docs/5.5/packages#package-discovery the VoyagerHooksServiceProvider included runs at the App intialisation, which means that by default xdebug will get disabled, and trying to run any functionality dependant on it (in my case - phpunit to obtain code coverage) will fail just because larapack/voyager-hooks is installed.

I've created a SO question for this issue: https://stackoverflow.com/questions/48118973/different-php-ini-file-loaded-dependant-upon-the-code-content/ as well as reported this on Laravel bugtracker: https://github.com/laravel/framework/issues/22782

Steps To Reproduce:

<?php

use Tests\TestCase;

class A extends TestCase
{
    public function testA()
    {
        echo( get_cfg_var('cfg_file_path')); exit;
    }
}

Output: C:\Users[user]\AppData\Local\Temp\F2A5.tmp Expected output: C:\server\php\php.ini

marktopper commented 6 years ago

That is no good. Thanks for reporting, I will look into this.

eithed commented 6 years ago

I've tried debugging it yesterday, but even when I removed the:

    "extra": {
        "laravel": {
            "providers": [
                "Larapack\\VoyagerHooks\\VoyagerHooksServiceProvider"
            ]
        }
    }

in package composer.json (per suggestion in Laravel's ticket) the service provider is still discovered. One way to get around the issue is per SO answer (putting <env name="COMPOSER_ALLOW_XDEBUG" value="1"/> in phpunit.xml), or preventing autodiscovery for the package by putting:

"extra": {
    "laravel": {
        "dont-discover": [
            "larapack/voyager-hooks"
        ]
    }
},

in the projects composer.json (although I don't know what that will do). Both of the solutions are not ideal, but debugging the issue further, and the why's/how's is currently beyond me. Thanks!

marktopper commented 6 years ago

Before we had auto discovering on, it was added to the VoyagerServiceProvider, you will have to remove it from there as well. However, if you do, please let me know if that resolves the issue.

eithed commented 6 years ago

I don't think it will - bear in mind that I was able to encounter the issue without even installing Voyager.

marktopper commented 6 years ago

I would test it - if it wasn't for the current issues with packagist.org... Will get back later once I have tested it.

marktopper commented 6 years ago

@eithed: Can you do me a favour and try to remove the line $xdebug->check(); from vendor/larapack/hooks/src/Hooks.php and see if that fixes the issue?

Cause then I will remake that and send in a PR.

eithed commented 6 years ago

Yup - that fixes the issue

marktopper commented 6 years ago

This has been fixed in larapack/hooks:v1.0.3 🎉