Add working directory search path for composer

Added a needed search path for composer.json and a test testing exactly this.
This commit is contained in:
Vassyli
2016-07-27 08:00:17 +02:00
parent f136711884
commit 396e174fb5
2 changed files with 43 additions and 3 deletions
+24 -3
View File
@@ -3,10 +3,17 @@ declare(strict_types=1);
namespace LotGD\Core;
use Composer\Composer;
use Composer\{
Composer,
Factory,
IO\NullIO
};
use Monolog\Logger;
use LotGD\Core\Exceptions\LibraryDoesNotExistException;
use LotGD\Core\{
Exceptions\InvalidConfigurationException,
Exceptions\LibraryDoesNotExistException
};
/**
* Helps perform tasks with the composer configuration.
@@ -32,8 +39,22 @@ class ComposerManager
public function getComposer(): Composer
{
if ($this->composer === null) {
$this->composer = \Composer\Factory::create(new \Composer\IO\NullIO());
// Search "true" working directory
if (file_exists(getcwd() . "/composer.json")) {
$cwd = getcwd() . "/";
}
elseif (file_exists(getcwd() . "/../composer.json")) {
$cwd = getcwd() . "/../";
}
else {
$cwd = getcwd();
throw new InvalidConfigurationException("composer.json has neither been found in {$cwd} nor in it's parent directory.");
}
$io = new NullIO();
$this->composer = Factory::create($io, $cwd . "composer.json");
}
return $this->composer;
}
+19
View File
@@ -29,6 +29,25 @@ class BootstrapTest extends \PHPUnit_Framework_TestCase
$this->assertNotNull($g->getEventManager());
$this->assertNotNull($g->getLogger());
}
public function testWorkingFromChildWorkingDirectory()
{
$cwd = getcwd();
$oldconf = getenv("LOTGD_CONFIG");
chdir($cwd . "/tests/");
putenv("LOTGD_CONFIG=../".$oldconf);
$this->assertStringEndsWith("/tests", getcwd());
$this->assertStringStartsWith(".././", getenv("LOTGD_CONFIG"));
$game = Bootstrap::createGame();
chdir($cwd);
putenv("LOTGD_CONFIG=" . $oldconf);
$this->assertStringEndsNotWith("/tests", getcwd());
$this->assertStringStartsNotWith(".././", getenv("LOTGD_CONFIG"));
}
public function testGenerateAnnotationDirectories()
{