elliotchance / concise

✅ Concise is test framework for using plain English and minimal code, built on PHPUnit.
MIT License
45 stars 3 forks source link

concise can only be run from vendor parent directory #334

Closed okdana closed 7 years ago

okdana commented 7 years ago

At the top of bin/concise is the following:

require_once('vendor/autoload.php');

Because unqualified include paths are relative to the current working directory, this means you can only run concise from the parent directory of the vendor folder. Attempting to run it from elsewhere will fail:

/tmp % composer require -q --dev 'elliotchance/concise'
/tmp % vendor/bin/concise 2>&1 | head -1
Concise v2.1.0 Photon by Elliot Chance.
/tmp % cd vendor
vendor % bin/concise 2>&1 | head -1
PHP Warning:  require_once(vendor/autoload.php): failed to open stream: No such file or directory in /private/tmp/vendor/elliotchance/concise/bin/concise on line 4

To fix this you could have it resolve like this, which is similar to how PHPUnit does it:

foreach ( [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'] as $file ) {
    if ( file_exists($file) ) {
        require $file;
        break;
    }
}

This way you can run it no matter what the current working directory is.

I would just submit a PR for this but it requires adding the same code to both concise and concise-init, so i wanted to get your thoughts on how you'd want to address that in a DRY way. I think the typical thing would be to add a src/bootstrap.php that handles auto-loader resolution.

elliotchance commented 7 years ago

Thanks @okdana, I had not considered this. I have marked it as a bug since it may effect users in the scenario you provide.

I am a big fan of DRY code so it makes sense that the common logic would be moved to an even higher precedence bootstrap - but in this case I think either would be acceptable so I will leave the decision up to you.

If you have time it would be great to get a PR so I can do a patch release. :)

okdana commented 7 years ago

Submitted PR #335. I tried to match your existing code style and everything, let me know if there are any problems though