Skip to content
Browse files

Adjust dump command, add another test, update docs, refs #1344

  • Loading branch information...
1 parent 023ff13 commit 790a25c348fcb4b937f7c35c2b61dc82905252ac @Seldaek Seldaek committed Mar 1, 2014
View
4 .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
View
1 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
View
15 doc/04-schema.md
@@ -518,22 +518,23 @@ Example:
### autoload-dev <span>(root-only)</span>
-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/" }
}
}
View
4 src/Composer/Command/DumpAutoloadCommand.php
@@ -31,7 +31,7 @@ protected function configure()
->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(<<<EOT
<info>php composer.phar dump-autoload</info>
@@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$generator = $composer->getAutoloadGenerator();
- $generator->setDevMode($input->getOption('dev'));
+ $generator->setDevMode(!$input->getOption('no-dev'));
$generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
}
}
View
13 tests/Composer/Test/Autoload/AutoloadGeneratorTest.php
@@ -170,7 +170,7 @@ public function testMainPackageAutoloading()
// 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 @@ public function testMainPackageDevAutoloading()
));
$package->setDevAutoload(array(
'files' => array('devfiles/foo.php'),
+ 'psr-0' => array(
+ 'Main' => 'tests/'
+ ),
));
$this->repository->expects($this->once())
@@ -197,11 +200,11 @@ public function testMainPackageDevAutoloading()
// 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 @@ public function testMainPackageDevAutoloadingDisabledByDefault()
// 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;
View
10 tests/Composer/Test/Autoload/Fixtures/autoload_main5.php
@@ -0,0 +1,10 @@
+<?php
+
+// autoload_namespaces.php @generated by Composer
+
+$vendorDir = dirname(dirname(__FILE__));
+$baseDir = dirname($vendorDir);
+
+return array(
+ 'Main' => array($baseDir . '/src', $baseDir . '/tests'),
+);
View
6 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';

0 comments on commit 790a25c

Please sign in to comment.
Something went wrong with that request. Please try again.