c3 icon indicating copy to clipboard operation
c3 copied to clipboard

Why does the installer copy c3.php into the project root?

Open NerdyProjects opened this issue 8 years ago • 5 comments

I see no reason why it should not be included via composer autoloader or manually from within the vendor folder.

Is there any?

NerdyProjects avatar Nov 15 '17 13:11 NerdyProjects

Can we detect the Composer's folder from a PHP script? Especially if we inject c3 in the very first lines of index.php. Not sure, maybe it's technically possible, but there were reasons to drop file into the root...

DavertMik avatar Nov 15 '17 17:11 DavertMik

Is it not "common" and expected to have composer folder inside vendor? So I suggest

include __DIR__ . '/vendor/codeception/c3/c3.php';

To me, the copying approach fails as my test setup expects composer to not put anything outside the vendor/ folder. Also, it is not so nice having to add this to .gitignore.

I just feel that maybe changing the include path of c3.php when the vendor folder is relocated confirms much more to convenience & the general style of composer packages than this Installer approach.

Another possibility would be to use the composer autoloader by putting an empty class inside c3.php, so the file is executed when the class is referenced.

Can you point me to a discussion about the reasons to drop the file into the root? Maybe there are some usecases connected to frameworks etc. that I don't take into account now.

NerdyProjects avatar Nov 18 '17 10:11 NerdyProjects

Is it not "common" and expected to have composer folder inside vendor

No, it's not. Users can have a different location of composer's folder. Also it can work with codecept.phar which was a default setup 3-4 years ago.

Another possibility would be to use the composer autoloader by putting an empty class inside c3.php, so the file is executed when the class is referenced.

This can be an option...

Can you point me to a discussion about the reasons to drop the file into the root? Maybe there are some usecases connected to frameworks etc. that I don't take into account now.

That was so long ago (I think January 2013)... But here is the thing. c3 needs to know how to load codeception.yml:

https://github.com/Codeception/c3/blob/2.0/c3.php#L81

Looks like that's all...

So yeah, I think it can be refactored to load the config file by specifying it explicitly

DavertMik avatar Nov 18 '17 13:11 DavertMik

The c3.php setup is really messed up. It woud be much better like this:

<?php
// index.php
require dirname(__DIR__) . '/vendor/autoload.php';
Codeception\C3::init([
    'configFile' => dirname(__DIR__) . '/codeception.yml',
    'outputDir' => dirname(__DIR__) . '/temp/c3/'
]);

The init() argument is c3.php configuration -- the path to the config file, and the temp directory where c3 should place its outputs.

This way there is no need to put c3.php into application root directory. Composer's autoloader will do the trick. Moreover, it will work when only the dedicated directory is writable by the web server.

jkufner avatar Sep 26 '18 20:09 jkufner

See https://github.com/Codeception/c3/pull/72 for a first step in improving this.

marcovtwout avatar May 19 '21 11:05 marcovtwout