From 40e484ed38d8df1dd6b854e7ee6af9993f76d130 Mon Sep 17 00:00:00 2001 From: Olivier Laviale Date: Thu, 20 Feb 2014 23:18:48 +0100 Subject: [PATCH 1/6] Fixed an issue that would lead to scattered autoloading files --- src/Composer/Autoload/AutoloadGenerator.php | 42 ++++++++----------- .../Fixtures/autoload_files_functions.php | 2 +- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index c4c172898..ecb5a4c70 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -183,7 +183,6 @@ EOF; } } - $autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap'])); foreach ($autoloads['classmap'] as $dir) { foreach (ClassMapGenerator::createMap($dir) as $class => $path) { $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); @@ -360,7 +359,6 @@ EOF; protected function getIncludeFilesFile(array $files, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode) { $filesCode = ''; - $files = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($files)); foreach ($files as $functionFile) { $filesCode .= ' '.$this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile).",\n"; } @@ -580,33 +578,27 @@ FOOTER; foreach ($autoload[$type] as $namespace => $paths) { foreach ((array) $paths as $path) { - // remove target-dir from file paths of the root package - if ($type === 'files' && $package === $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) { - $targetDir = str_replace('\\', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '', $package->getTargetDir()))); - $path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/'); + if (($type === 'files' || $type === 'classmap') && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) + { + // remove target-dir from file paths of the root package + if ($package === $mainPackage) { + $targetDir = str_replace('\\', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '', $package->getTargetDir()))); + $path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/'); + } + // add target-dir from file paths that don't have it + else { + $path = $package->getTargetDir() . '/' . $path; + } } - // add target-dir from file paths that don't have it - if ($type === 'files' && $package !== $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) { - $path = $package->getTargetDir() . '/' . $path; + $relativePath = empty($installPath) ? (empty($path) ? '.' : $path) : $installPath.'/'.$path; + + if ($type === 'files' || $type === 'classmap') { + $autoloads[] = $relativePath; + continue; } - // remove target-dir from classmap entries of the root package - if ($type === 'classmap' && $package === $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) { - $targetDir = str_replace('\\', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '', $package->getTargetDir()))); - $path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/'); - } - - // add target-dir to classmap entries that don't have it - if ($type === 'classmap' && $package !== $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) { - $path = $package->getTargetDir() . '/' . $path; - } - - if (empty($installPath)) { - $autoloads[$namespace][] = empty($path) ? '.' : $path; - } else { - $autoloads[$namespace][] = $installPath.'/'.$path; - } + $autoloads[$namespace][] = $relativePath; } } } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_files_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_files_functions.php index 0af7f8686..6b6494b2c 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_files_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_files_functions.php @@ -9,6 +9,6 @@ return array( $vendorDir . '/a/a/test.php', $vendorDir . '/b/b/test2.php', $vendorDir . '/c/c/foo/bar/test3.php', - $baseDir . '/root.php', $vendorDir . '/c/c/foo/bar/test4.php', + $baseDir . '/root.php', ); From db91454a13928c8d7efde0caf3f899a3c1a775e7 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Thu, 27 Feb 2014 10:39:33 +0100 Subject: [PATCH 2/6] added an autoload-dev section --- composer.json | 3 + doc/04-schema.md | 21 ++++++ res/composer-schema.json | 24 +++++++ src/Composer/Autoload/AutoloadGenerator.php | 10 +++ src/Composer/Command/DumpAutoloadCommand.php | 5 +- src/Composer/Installer.php | 1 + src/Composer/Package/AliasPackage.php | 4 ++ src/Composer/Package/Dumper/ArrayDumper.php | 1 + src/Composer/Package/Loader/ArrayLoader.php | 4 ++ src/Composer/Package/Package.php | 19 ++++++ src/Composer/Package/PackageInterface.php | 16 ++++- .../Test/Autoload/AutoloadGeneratorTest.php | 68 +++++++++++++++++++ .../Autoload/Fixtures/autoload_classmap7.php | 10 +++ .../Autoload/Fixtures/autoload_files2.php | 10 +++ .../Test/Autoload/Fixtures/autoload_main4.php | 10 +++ tests/bootstrap.php | 2 + 16 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_classmap7.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_files2.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_main4.php diff --git a/composer.json b/composer.json index b72856837..ea526e9c7 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,9 @@ "autoload": { "psr-0": { "Composer": "src/" } }, + "autoload-dev": { + "psr-0": { "Composer\\Test": "tests/" } + }, "bin": ["bin/composer"], "extra": { "branch-alias": { diff --git a/doc/04-schema.md b/doc/04-schema.md index 6ebe378e4..ae6894f09 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -516,6 +516,27 @@ Example: } } +### autoload-dev (root-only) + +This section allows to define autoload rules for development purpose. + +If you're generating classmaps from your PSR-0 namespaces, you're probably concerned +about performance, if so, you'll also don't want your test classes to be mixed up +with your regular classes in those classmaps. + +Therefore, it is a good idea to rely on a dedicated path for your unit tests. + +Example: + + { + "autoload": { + "psr-0": { "MyLibrary": "src/" } + }, + "autoload-dev": { + "psr-0": { "MyLibrary\\Tests": "tests/" } + } + } + ### include-path > **DEPRECATED**: This is only present to support legacy projects, and all new code diff --git a/res/composer-schema.json b/res/composer-schema.json index 905199247..69d4dc5a1 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -226,6 +226,30 @@ } } }, + "autoload-dev": { + "type": "object", + "description": "Description of additional autoload rules for development purpose (eg. a test suite).", + "properties": { + "psr-0": { + "type": "object", + "description": "This is a hash of namespaces (keys) and the directories they can be found into (values, can be arrays of paths) by the autoloader.", + "additionalProperties": true + }, + "psr-4": { + "type": "object", + "description": "This is a hash of namespaces (keys) and the PSR-4 directories they can map to (values, can be arrays of paths) by the autoloader.", + "additionalProperties": true + }, + "classmap": { + "type": "array", + "description": "This is an array of directories that contain classes to be included in the class-map generation process." + }, + "files": { + "type": "array", + "description": "This is an array of files that are always required on every request." + } + } + }, "archive": { "type": ["object"], "description": "Options for creating package archives for distribution.", diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index c4c172898..8b4d0443f 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -32,11 +32,18 @@ class AutoloadGenerator */ private $eventDispatcher; + private $devMode = false; + public function __construct(EventDispatcher $eventDispatcher) { $this->eventDispatcher = $eventDispatcher; } + public function setDevMode($devMode = true) + { + $this->devMode = (boolean) $devMode; + } + public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '') { $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP); @@ -569,6 +576,9 @@ FOOTER; list($package, $installPath) = $item; $autoload = $package->getAutoload(); + if ($this->devMode && $package === $mainPackage) { + $autoload = array_merge_recursive($autoload, $package->getDevAutoload()); + } // skip misconfigured packages if (!isset($autoload[$type]) || !is_array($autoload[$type])) { diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index d228fb150..cd3f1b71d 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/src/Composer/Command/DumpAutoloadCommand.php @@ -31,6 +31,7 @@ class DumpAutoloadCommand extends Command ->setDescription('Dumps the autoloader') ->setDefinition(array( new InputOption('optimize', 'o', InputOption::VALUE_NONE, 'Optimizes PSR0 packages to be loaded with classmaps too, good for production.'), + new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables dev autoload.'), )) ->setHelp(<<php composer.phar dump-autoload @@ -59,6 +60,8 @@ EOT $output->writeln('Generating autoload files'); } - $composer->getAutoloadGenerator()->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize); + $generator = $composer->getAutoloadGenerator(); + $generator->setDevMode($input->getOption('dev')); + $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize); } } diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index d373beb43..839fc45e4 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -290,6 +290,7 @@ class Installer $this->io->write('Generating autoload files'); } + $this->autoloadGenerator->setDevMode($this->devMode); $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader); if ($this->runScripts) { diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php index 6f1fb5095..631b035a7 100644 --- a/src/Composer/Package/AliasPackage.php +++ b/src/Composer/Package/AliasPackage.php @@ -245,6 +245,10 @@ class AliasPackage extends BasePackage implements CompletePackageInterface { return $this->aliasOf->getAutoload(); } + public function getDevAutoload() + { + return $this->aliasOf->getDevAutoload(); + } public function getIncludePaths() { return $this->aliasOf->getIncludePaths(); diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index be94adec4..0a183742f 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -31,6 +31,7 @@ class ArrayDumper 'extra', 'installationSource' => 'installation-source', 'autoload', + 'devAutoload' => 'autoload-dev', 'notificationUrl' => 'notification-url', 'includePaths' => 'include-path', ); diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 3940bdeb0..6ef4e7c03 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -130,6 +130,10 @@ class ArrayLoader implements LoaderInterface $package->setAutoload($config['autoload']); } + if (isset($config['autoload-dev'])) { + $package->setDevAutoload($config['autoload-dev']); + } + if (isset($config['include-path'])) { $package->setIncludePaths($config['include-path']); } diff --git a/src/Composer/Package/Package.php b/src/Composer/Package/Package.php index ba3f611c1..8fab59a8a 100644 --- a/src/Composer/Package/Package.php +++ b/src/Composer/Package/Package.php @@ -47,6 +47,7 @@ class Package extends BasePackage protected $devRequires = array(); protected $suggests = array(); protected $autoload = array(); + protected $devAutoload = array(); protected $includePaths = array(); protected $archiveExcludes = array(); @@ -440,6 +441,24 @@ class Package extends BasePackage return $this->autoload; } + /** + * Set the dev autoload mapping + * + * @param array $autoload Mapping of dev autoloading rules + */ + public function setDevAutoload(array $devAutoload) + { + $this->devAutoload = $devAutoload; + } + + /** + * {@inheritDoc} + */ + public function getDevAutoload() + { + return $this->devAutoload; + } + /** * Sets the list of paths added to PHP's include path. * diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index a3c8a2793..fd7393992 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -231,13 +231,25 @@ interface PackageInterface * * {"": {""}} * - * Type is either "psr-0" or "pear". Namespaces are mapped to directories - * for autoloading using the type specified. + * Type is either "psr-4", "psr-0", "classmap" or "files". Namespaces are mapped to + * directories for autoloading using the type specified. * * @return array Mapping of autoloading rules */ public function getAutoload(); + /** + * Returns an associative array of dev autoloading rules + * + * {"": {""}} + * + * Type is either "psr-4", "psr-0", "classmap" or "files". Namespaces are mapped to + * directories for autoloading using the type specified. + * + * @return array Mapping of dev autoloading rules + */ + public function getDevAutoload(); + /** * Returns a list of directories which should get added to PHP's * include path. diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 9f1e2fb16..1bbf0b577 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -170,7 +170,75 @@ class AutoloadGeneratorTest extends TestCase // Assert that autoload_classmap.php was correctly generated. $this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap'); } + + public function testMainPackageDevAutoloading() + { + $package = new Package('a', '1.0', '1.0'); + $package->setAutoload(array( + 'psr-0' => array( + 'Main' => 'src/', + ), + )); + $package->setDevAutoload(array( + 'files' => array('devfiles/foo.php'), + )); + $this->repository->expects($this->once()) + ->method('getCanonicalPackages') + ->will($this->returnValue(array())); + + $this->fs->ensureDirectoryExists($this->workingDir.'/composer'); + $this->fs->ensureDirectoryExists($this->workingDir.'/src/Main'); + file_put_contents($this->workingDir.'/src/Main/ClassMain.php', 'fs->ensureDirectoryExists($this->workingDir.'/devfiles'); + file_put_contents($this->workingDir.'/devfiles/foo.php', 'generator->setDevMode(true); + $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1'); + + // check standard autoload + $this->assertAutoloadFiles('main4', $this->vendorDir.'/composer'); + $this->assertAutoloadFiles('classmap7', $this->vendorDir.'/composer', 'classmap'); + + // make sure dev autoload is correctly dumped + $this->assertAutoloadFiles('files2', $this->vendorDir.'/composer', 'files'); + } + + public function testMainPackageDevAutoloadingDisabledByDefault() + { + $package = new Package('a', '1.0', '1.0'); + $package->setAutoload(array( + 'psr-0' => array( + 'Main' => 'src/', + ), + )); + $package->setDevAutoload(array( + 'files' => array('devfiles/foo.php'), + )); + + $this->repository->expects($this->once()) + ->method('getCanonicalPackages') + ->will($this->returnValue(array())); + + $this->fs->ensureDirectoryExists($this->workingDir.'/composer'); + $this->fs->ensureDirectoryExists($this->workingDir.'/src/Main'); + file_put_contents($this->workingDir.'/src/Main/ClassMain.php', 'fs->ensureDirectoryExists($this->workingDir.'/devfiles'); + file_put_contents($this->workingDir.'/devfiles/foo.php', 'generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1'); + + // check standard autoload + $this->assertAutoloadFiles('main4', $this->vendorDir.'/composer'); + $this->assertAutoloadFiles('classmap7', $this->vendorDir.'/composer', 'classmap'); + + // make sure dev autoload is disabled when dev mode is set to false + $this->assertFalse(is_file($this->vendorDir.'/composer/autoload_files.php')); + } + public function testVendorDirSameAsWorkingDir() { $this->vendorDir = $this->workingDir; diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap7.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap7.php new file mode 100644 index 000000000..5768726d1 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap7.php @@ -0,0 +1,10 @@ + $baseDir . '/src/Main/ClassMain.php', +); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_files2.php b/tests/Composer/Test/Autoload/Fixtures/autoload_files2.php new file mode 100644 index 000000000..13cb9ecb3 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_files2.php @@ -0,0 +1,10 @@ + array($baseDir . '/src'), +); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index c5e16d625..12caaffac 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,6 +13,8 @@ error_reporting(E_ALL); $loader = require __DIR__.'/../src/bootstrap.php'; + +// to be removed $loader->add('Composer\Test', __DIR__); require __DIR__.'/Composer/TestCase.php'; From cea7c07cf272f3abea8e3aeb24dfe03b44714f2f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 1 Mar 2014 19:58:37 +0100 Subject: [PATCH 3/6] Fix CS --- src/Composer/Autoload/AutoloadGenerator.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index ecb5a4c70..4fc900187 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -578,15 +578,13 @@ FOOTER; foreach ($autoload[$type] as $namespace => $paths) { foreach ((array) $paths as $path) { - if (($type === 'files' || $type === 'classmap') && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) - { + if (($type === 'files' || $type === 'classmap') && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) { // remove target-dir from file paths of the root package if ($package === $mainPackage) { $targetDir = str_replace('\\', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '', $package->getTargetDir()))); $path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/'); - } - // add target-dir from file paths that don't have it - else { + } else { + // add target-dir from file paths that don't have it $path = $package->getTargetDir() . '/' . $path; } } From 790a25c348fcb4b937f7c35c2b61dc82905252ac Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 1 Mar 2014 20:39:06 +0100 Subject: [PATCH 4/6] Adjust dump command, add another test, update docs, refs #1344 --- .travis.yml | 4 ++-- doc/03-cli.md | 1 + doc/04-schema.md | 15 ++++++++------- src/Composer/Command/DumpAutoloadCommand.php | 4 ++-- .../Test/Autoload/AutoloadGeneratorTest.php | 13 ++++++++----- .../Test/Autoload/Fixtures/autoload_main5.php | 10 ++++++++++ tests/bootstrap.php | 6 +----- 7 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_main5.php diff --git a/.travis.yml b/.travis.yml index 576b2bcbd..a2803f0e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,8 @@ matrix: before_script: - sudo apt-get install parallel - rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini - - composer install --dev --prefer-source - - bin/composer install --dev --prefer-source + - composer install --prefer-source + - bin/composer install --prefer-source - git config --global user.name travis-ci - git config --global user.email travis@example.com diff --git a/doc/03-cli.md b/doc/03-cli.md index 3e9ae78e2..e885a7a9f 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -387,6 +387,7 @@ performance. * **--optimize (-o):** Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default. +* **--no-dev:** Disables autoload-dev rules. ## licenses diff --git a/doc/04-schema.md b/doc/04-schema.md index ad8b53623..071b3bd9f 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -518,22 +518,23 @@ Example: ### autoload-dev (root-only) -This section allows to define autoload rules for development purpose. +This section allows to define autoload rules for development purposes. -If you're generating classmaps from your PSR-0 namespaces, you're probably concerned -about performance, if so, you'll also don't want your test classes to be mixed up -with your regular classes in those classmaps. +Classes needed to run the test suite should not be included in the main autoload +rules to avoid polluting the autoloader in production and when other people use +your package as a dependency. -Therefore, it is a good idea to rely on a dedicated path for your unit tests. +Therefore, it is a good idea to rely on a dedicated path for your unit tests +and to add it within the autoload-dev section. Example: { "autoload": { - "psr-0": { "MyLibrary": "src/" } + "psr-4": { "MyLibrary\\": "src/" } }, "autoload-dev": { - "psr-0": { "MyLibrary\\Tests": "tests/" } + "psr-4": { "MyLibrary\\Tests": "tests/" } } } diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index cd3f1b71d..86d351505 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/src/Composer/Command/DumpAutoloadCommand.php @@ -31,7 +31,7 @@ class DumpAutoloadCommand extends Command ->setDescription('Dumps the autoloader') ->setDefinition(array( new InputOption('optimize', 'o', InputOption::VALUE_NONE, 'Optimizes PSR0 packages to be loaded with classmaps too, good for production.'), - new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables dev autoload.'), + new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables autoload-dev rules.'), )) ->setHelp(<<php composer.phar dump-autoload @@ -61,7 +61,7 @@ EOT } $generator = $composer->getAutoloadGenerator(); - $generator->setDevMode($input->getOption('dev')); + $generator->setDevMode(!$input->getOption('no-dev')); $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize); } } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 1bbf0b577..7c4ddccd9 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -170,7 +170,7 @@ class AutoloadGeneratorTest extends TestCase // Assert that autoload_classmap.php was correctly generated. $this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap'); } - + public function testMainPackageDevAutoloading() { $package = new Package('a', '1.0', '1.0'); @@ -181,6 +181,9 @@ class AutoloadGeneratorTest extends TestCase )); $package->setDevAutoload(array( 'files' => array('devfiles/foo.php'), + 'psr-0' => array( + 'Main' => 'tests/' + ), )); $this->repository->expects($this->once()) @@ -197,11 +200,11 @@ class AutoloadGeneratorTest extends TestCase // generate autoload files with the dev mode set to true $this->generator->setDevMode(true); $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1'); - + // check standard autoload - $this->assertAutoloadFiles('main4', $this->vendorDir.'/composer'); + $this->assertAutoloadFiles('main5', $this->vendorDir.'/composer'); $this->assertAutoloadFiles('classmap7', $this->vendorDir.'/composer', 'classmap'); - + // make sure dev autoload is correctly dumped $this->assertAutoloadFiles('files2', $this->vendorDir.'/composer', 'files'); } @@ -238,7 +241,7 @@ class AutoloadGeneratorTest extends TestCase // make sure dev autoload is disabled when dev mode is set to false $this->assertFalse(is_file($this->vendorDir.'/composer/autoload_files.php')); } - + public function testVendorDirSameAsWorkingDir() { $this->vendorDir = $this->workingDir; diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_main5.php b/tests/Composer/Test/Autoload/Fixtures/autoload_main5.php new file mode 100644 index 000000000..15cb2622b --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_main5.php @@ -0,0 +1,10 @@ + array($baseDir . '/src', $baseDir . '/tests'), +); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 12caaffac..9e59c65a7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -12,9 +12,5 @@ error_reporting(E_ALL); -$loader = require __DIR__.'/../src/bootstrap.php'; - -// to be removed -$loader->add('Composer\Test', __DIR__); - +require __DIR__.'/../src/bootstrap.php'; require __DIR__.'/Composer/TestCase.php'; From 5fb005631a7de07db83ae8af894b7a600fe6004e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 1 Mar 2014 21:22:01 +0100 Subject: [PATCH 5/6] Tweaking dispatchScript method to be in line with the rest, and add devMode to *_AUTOLOAD_DUMP events --- src/Composer/Autoload/AutoloadGenerator.php | 4 ++-- src/Composer/EventDispatcher/EventDispatcher.php | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index a0bf8c29f..3783bd22c 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -46,7 +46,7 @@ class AutoloadGenerator public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '') { - $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP); + $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode); $filesystem = new Filesystem(); $filesystem->ensureDirectoryExists($config->get('vendor-dir')); @@ -228,7 +228,7 @@ EOF; fclose($targetLoader); unset($sourceLoader, $targetLoader); - $this->eventDispatcher->dispatchScript(ScriptEvents::POST_AUTOLOAD_DUMP); + $this->eventDispatcher->dispatchScript(ScriptEvents::POST_AUTOLOAD_DUMP, $this->devMode); } public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages) diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index f1e94e6d5..fb607831d 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -75,13 +75,9 @@ class EventDispatcher * @param string $eventName The constant in ScriptEvents * @param Script\Event $event */ - public function dispatchScript($eventName, Script\Event $event = null) + public function dispatchScript($eventName, $devMode = false) { - if (null == $event) { - $event = new Script\Event($eventName, $this->composer, $this->io); - } - - $this->doDispatch($event); + $this->doDispatch(new Script\Event($eventName, $this->composer, $this->io, $devMode)); } /** From fff913d6de5ec8c4315f466cf203c3e0acc3218a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 1 Mar 2014 21:25:32 +0100 Subject: [PATCH 6/6] Update deps --- composer.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index 9e8b0b7ca..45ccf5710 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "78b771e9b9f3c0181350f1d6ed8fa3c7", + "hash": "e68bf60f228ca192b8b492cb95a80fa7", "packages": [ { "name": "justinrainbow/json-schema", @@ -277,16 +277,16 @@ "packages-dev": [ { "name": "phpunit/php-code-coverage", - "version": "1.2.15", + "version": "1.2.16", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "6ba4ed2895d538a039d5d5866edc4ec0424c7852" + "reference": "69e55e68481cf708a6db43aff0b504e31402fe27" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6ba4ed2895d538a039d5d5866edc4ec0424c7852", - "reference": "6ba4ed2895d538a039d5d5866edc4ec0424c7852", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/69e55e68481cf708a6db43aff0b504e31402fe27", + "reference": "69e55e68481cf708a6db43aff0b504e31402fe27", "shasum": "" }, "require": { @@ -334,7 +334,7 @@ "testing", "xunit" ], - "time": "2014-02-03 07:44:47" + "time": "2014-02-25 03:34:05" }, { "name": "phpunit/php-file-iterator", @@ -521,16 +521,16 @@ }, { "name": "phpunit/phpunit", - "version": "3.7.31", + "version": "3.7.32", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "d24e9877331039582497052cc3c4d9f465b88210" + "reference": "2752cbb9ea5bd84c2811b34b6953f76965ec7a2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d24e9877331039582497052cc3c4d9f465b88210", - "reference": "d24e9877331039582497052cc3c4d9f465b88210", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2752cbb9ea5bd84c2811b34b6953f76965ec7a2f", + "reference": "2752cbb9ea5bd84c2811b34b6953f76965ec7a2f", "shasum": "" }, "require": { @@ -547,7 +547,7 @@ "symfony/yaml": "~2.0" }, "require-dev": { - "pear-pear/pear": "1.9.4" + "pear-pear.php.net/pear": "1.9.4" }, "suggest": { "ext-json": "*", @@ -591,7 +591,7 @@ "testing", "xunit" ], - "time": "2014-02-03 07:46:27" + "time": "2014-02-25 03:47:29" }, { "name": "phpunit/phpunit-mock-objects",