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:
+24
-3
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user