Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Bootstrap created unexpected folder structure #4

Closed
Laykou opened this issue Feb 14, 2015 · 10 comments · Fixed by #5
Closed

Bootstrap created unexpected folder structure #4

Laykou opened this issue Feb 14, 2015 · 10 comments · Fixed by #5
Labels

Comments

@Laykou
Copy link
Contributor

Laykou commented Feb 14, 2015

The bootstrap command created this folder structure for me
image
which is different from what stated in the README file. Using Windows 7, PHP 5.6

My composer.json:

    "autoload": {
        "psr-4": {
            "App\\": "src",
            "App\\Test\\": "tests"
        }
    },
    "scripts": {
        "post-install-cmd": "App\\Console\\Installer::postInstall",
        "post-autoload-dump": [
            "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump",
            "Cake\\Codeception\\Console\\Installer::postAutoloadDump"
        ]
    }
@jadb
Copy link
Contributor

jadb commented Feb 14, 2015

@Laykou - can you paste the content of the codecept binary please? Or just confirm if it uses some Cake\ classes or not.

I don't have Windows and haven't tested it on that (yet) but have a feeling it is not over-writing the binary.

@Laykou
Copy link
Contributor Author

Laykou commented Feb 14, 2015

Yes, I looked at it and this is my

\vendor\bin\codecept

#!/usr/bin/env sh
SRC_DIR="`pwd`"
cd "`dirname "$0"`"
cd "../codeception/codeception"
BIN_TARGET="`pwd`/codecept"
cd "$SRC_DIR"
"$BIN_TARGET" "$@"

\vendor\bin\codecept.bat

@ECHO OFF
SET BIN_TARGET=%~dp0/../codeception/codeception/codecept
php "%BIN_TARGET%" %*

They look like original bin files from codeception. I saw that the file vendor\cakephp\codeception\src\Command\Bootstrap.php should update the codecept file, but even the content is wrong.....

Let me know if there is anything I can test for you on the windows. I tried it several times with the fresh composer update and always ended upt like thi.s

@jadb
Copy link
Contributor

jadb commented Feb 14, 2015

Ok. Thanks, this confirms what I had suspected. Looks like I have some work to do on Windows.

I am curious to know why your files are different from the ones in Codeception repo:

The Cake\Codeception\Console\Installer::postAutoloadDump() script will only edit codecept and only if it is in a format like the one I linked to on the Codeception repo.

Here's how the codecept file looks like on *NIX platforms (after being edited by the installer):

#!/usr/bin/env php
<?php
/**
 * Codeception CLI
 */

require_once dirname(__FILE__).'/autoload.php';

use Symfony\Component\Console\Application;

$app = new Application('Codeception', Codeception\Codecept::VERSION);
$app->add(new Cake\Codeception\Command\Build('build'));
$app->add(new Codeception\Command\Run('run'));
$app->add(new Codeception\Command\Console('console'));
$app->add(new Cake\Codeception\Command\Bootstrap('bootstrap'));
$app->add(new Codeception\Command\GenerateCept('generate:cept'));
$app->add(new Codeception\Command\GenerateCest('generate:cest'));
$app->add(new Codeception\Command\GenerateTest('generate:test'));
$app->add(new Codeception\Command\GeneratePhpUnit('generate:phpunit'));
$app->add(new Codeception\Command\GenerateSuite('generate:suite'));
$app->add(new Codeception\Command\GenerateHelper('generate:helper'));
$app->add(new Codeception\Command\GenerateScenarios('generate:scenarios'));
$app->add(new Codeception\Command\Clean('clean'));
$app->add(new Cake\Codeception\Command\GenerateGroup('generate:group'));
$app->add(new Codeception\Command\GeneratePageObject('generate:pageobject'));
$app->add(new Codeception\Command\GenerateStepObject('generate:stepobject'));
$app->run();

It won't work no matter how many times you will try since it just doesn't seem to autoload the same way on both platforms.

Maybe if we identify why it has a different codecept file, we'll get to the solution?

@Laykou
Copy link
Contributor Author

Laykou commented Feb 14, 2015

What line of script (what file) is responsible for copying the file into vendor\bin folder? I'm not that skilled with composer and how it works, but I learn quickly and I will do my best to find the solution :)

@jadb
Copy link
Contributor

jadb commented Feb 14, 2015

@Laykou - in the case of Codeception, I believe this part of Composer's code:

https://github.com/composer/composer/blob/master/src/Composer/Installer/LibraryInstaller.php#L186-L252

@Laykou
Copy link
Contributor Author

Laykou commented Feb 14, 2015

@jadb You got it! So that's how composer works: for windows it doesn't copy the file but only creates the proxy link to the real file:

// From the composer/LibraryInstaller.php
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
 file_put_contents($link, $this->generateUnixyProxyCode($binPath, $link));
} else {
  symlink($relativeBin, $link)
}

// The proxy code function
 protected function generateUnixyProxyCode($bin, $link)
{
    $binPath = $this->filesystem->findShortestPath($link, $bin);
    return "#!/usr/bin/env sh\n".
        'SRC_DIR="`pwd`"'."\n".
        'cd "`dirname "$0"`"'."\n".
        'cd '.ProcessExecutor::escape(dirname($binPath))."\n".
        'BIN_TARGET="`pwd`/'.basename($binPath)."\"\n".
        'cd "$SRC_DIR"'."\n".
        '"$BIN_TARGET" "$@"'."\n";
}

Thats because on unix systems the symlink is created which is not available in the Windows. But then is the concept of ovewriting the file good? Because even in the Linux the original file codeception\codeception\codecept will be overwritten (because of the symlink). Am I wrong?

@jadb
Copy link
Contributor

jadb commented Feb 14, 2015

While it's not what I would have preferred, overwriting is the only solution for now.

Codeception, even though object-oriented, gives no other way but to either:

a- overwrite the codecept binary
b- create our own to instantiate the right classes for templates and folder structure

For now, I am content with this solution as when using codecept in a CakePHP application environment, rarely (if ever), will one need the original Codeception behavior.

@Laykou
Copy link
Contributor Author

Laykou commented Feb 14, 2015

What if the Installer.php would create the new content of the codecept file instead of just overwritting the namespaces?

@jadb
Copy link
Contributor

jadb commented Feb 14, 2015

@Laykou if that's the only way to resolve it for Windows, then yes. The original reasons I prefer modifying it instead of re-writing it was that maybe codeception upgrades, adds a new command but we don't need to customize that command, why have to update our code? If that makes any sense. So again, if it's the only solution, then it can be considered, otherwise, sticking to the way it is now is better IMO.

Also, it's good to add, that this is a temporary solution. I do have plans for this library to have a TestShell ala MigrationShell (for phinx) but no time yet. I'll be happy to help anyone who wants to do it though.

@Laykou
Copy link
Contributor Author

Laykou commented Feb 15, 2015

What if the codecept file was edited directly in the vendor/codeception/codeception? Technically there is no change on the Linux machine while making the Windows to do the same work.

Closing as there is a pull request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants