Fixed composer creation to account completely for cwd
Also added tests that fail if not.
This commit is contained in:
Generated
+389
-310
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,8 @@ namespace LotGD\Core;
|
|||||||
use Composer\{
|
use Composer\{
|
||||||
Composer,
|
Composer,
|
||||||
Factory,
|
Factory,
|
||||||
IO\NullIO
|
IO\NullIO,
|
||||||
|
Package\CompletePackageInterface
|
||||||
};
|
};
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
|
||||||
@@ -41,13 +42,13 @@ class ComposerManager
|
|||||||
{
|
{
|
||||||
if ($this->composer === null) {
|
if ($this->composer === null) {
|
||||||
// Verify location of composer.json.
|
// Verify location of composer.json.
|
||||||
$path = $this->cwd . DIRECTORY_SEPARATOR . "composer.json";
|
$composerConfigPath = $this->cwd . DIRECTORY_SEPARATOR . "composer.json";
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($composerConfigPath)) {
|
||||||
throw new InvalidConfigurationException("composer.json cannot be found at {$path}.");
|
throw new InvalidConfigurationException("composer.json cannot be found at {$composerConfigPath}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$io = new NullIO();
|
$factory = new Factory();
|
||||||
$this->composer = Factory::create($io, $path);
|
$this->composer = $factory->createComposer(new NullIO(), $composerConfigPath, false, $this->cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->composer;
|
return $this->composer;
|
||||||
@@ -58,7 +59,7 @@ class ComposerManager
|
|||||||
* @return PackageInterface Package corresponding to this library.
|
* @return PackageInterface Package corresponding to this library.
|
||||||
* @throws LibraryDoesNotExistException
|
* @throws LibraryDoesNotExistException
|
||||||
*/
|
*/
|
||||||
public function getPackageForLibrary(string $library): PackageInterface
|
public function getPackageForLibrary(string $library): CompletePackageInterface
|
||||||
{
|
{
|
||||||
// TODO: should probably do something better than O(n) here.
|
// TODO: should probably do something better than O(n) here.
|
||||||
$packages = $this->getComposer()->getRepositoryManager()->getLocalRepository()->getPackages();
|
$packages = $this->getComposer()->getRepositoryManager()->getLocalRepository()->getPackages();
|
||||||
|
|||||||
@@ -40,4 +40,50 @@ class ComposerManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$namespace = 'LotGD\\NotFound';
|
$namespace = 'LotGD\\NotFound';
|
||||||
$this->assertNull($manager->translateNamespaceToPath($namespace));
|
$this->assertNull($manager->translateNamespaceToPath($namespace));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testListPackageWithRootCwd()
|
||||||
|
{
|
||||||
|
$manager = new ComposerManager(implode(DIRECTORY_SEPARATOR, [__DIR__, '..']));
|
||||||
|
|
||||||
|
$packageCount = count($manager->getPackages());
|
||||||
|
|
||||||
|
$this->assertGreaterThan(1, $packageCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListPackageWithDifferentThanRootCwd()
|
||||||
|
{
|
||||||
|
$oldcwd = getcwd();
|
||||||
|
chdir($oldcwd . DIRECTORY_SEPARATOR . "tests");
|
||||||
|
|
||||||
|
$manager = new ComposerManager(implode(DIRECTORY_SEPARATOR, [__DIR__, '..']));
|
||||||
|
|
||||||
|
$packageCount = count($manager->getPackages());
|
||||||
|
|
||||||
|
$this->assertGreaterThan(1, $packageCount);
|
||||||
|
|
||||||
|
chdir($oldcwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPackageByLibraryNameWithRootCwd()
|
||||||
|
{
|
||||||
|
$manager = new ComposerManager(implode(DIRECTORY_SEPARATOR, [__DIR__, '..']));
|
||||||
|
|
||||||
|
$package = $manager->getPackageForLibrary("composer/composer");
|
||||||
|
|
||||||
|
$this->assertSame("composer/composer", $package->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPackageByLibraryNameWithDifferentThanRootCwd()
|
||||||
|
{
|
||||||
|
$oldcwd = getcwd();
|
||||||
|
chdir($oldcwd . DIRECTORY_SEPARATOR . "tests");
|
||||||
|
|
||||||
|
$manager = new ComposerManager(implode(DIRECTORY_SEPARATOR, [__DIR__, '..']));
|
||||||
|
|
||||||
|
$package = $manager->getPackageForLibrary("composer/composer");
|
||||||
|
|
||||||
|
$this->assertSame("composer/composer", $package->getName());
|
||||||
|
|
||||||
|
chdir($oldcwd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||||||
list($dsn, $user, $password) = $configuration->getDatabaseConnectionDetails("/home/web/sqlite");
|
list($dsn, $user, $password) = $configuration->getDatabaseConnectionDetails("/home/web/sqlite");
|
||||||
|
|
||||||
$this->assertNotSame($rawDSN, $dsn);
|
$this->assertNotSame($rawDSN, $dsn);
|
||||||
$this->assertSame("sqlite:/home/web/sqlite/db.db3", $dsn);
|
$this->assertSame("sqlite:/home/web/sqlite" . DIRECTORY_SEPARATOR . "db.db3", $dsn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIfInvalidConfigurationExceptionIsThrownIfDatabaseDSNIsMissing()
|
public function testIfInvalidConfigurationExceptionIsThrownIfDatabaseDSNIsMissing()
|
||||||
|
|||||||
Reference in New Issue
Block a user