Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with autoload paths not being found when creating a package. #71

Merged
merged 1 commit into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Autoload/ServiceContainer/AutoloadExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ public function configure(ArrayNodeDefinition $builder)
public function load(ContainerBuilder $container, array $config)
{
$workingDir = $container->getParameter(Application::PARAMETER_WORKING_DIR);
// Adjust path to vendor if within a package
if (is_dir($workingDir . '/' . PackageConstants::PATCH_DIR)) {
$workingDir .= '/' . PackageConstants::PATCH_DIR;
}

$classLoader = $container->get(self::SERVICE_CLASS_LOADER);

if (isset($config['composer'])) {
foreach ($config['composer'] as $packageName) {
$packagePath = $workingDir . '/' . PackageConstants::PATCH_DIR . '/vendor/' . $packageName;
$packagePath = $workingDir . '/vendor/' . $packageName;
$composerJsonPath = $packagePath . '/composer.json';
if (!file_exists($composerJsonPath)) {
throw new RuntimeException(sprintf('Unable to find "%s" to fetch autoload paths', $composerJsonPath));
Expand Down
36 changes: 36 additions & 0 deletions tests/Autoload/ServiceContainer/AutoloadExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@ public function testAddsComposerPackagesWithClassMap()
$this->assertArraySubset([vfsStream::url('root/to_patch/vendor/test/test/file.php')], $classMap);
}

public function testAddsComposerPackagesFromRootVendor()
{
$composerJson = <<<'JSON'
{
"name": "test/test",
"autoload": {
"psr-0": {
"Test_": "src/"
}
}
}
JSON;

vfsStream::setup('root', null, [
'vendor' => [
'test' => [
'test' => [
'composer.json' => $composerJson,
],
],
],
]);

$container = $this->loadContainer([
'autoload' => [
'composer' => ['test/test'],
],
], vfsStream::url('root'));

$prefixes = $container->get(AutoloadExtension::SERVICE_CLASS_LOADER)->getPrefixes();

$this->assertArraySubset([
'Test_' => [vfsStream::url('root/vendor/test/test/src/')],
], $prefixes);
}

/**
* @expectedException \RuntimeException
*/
Expand Down