Adjust dump command, add another test, update docs, refs #1344
parent
023ff131aa
commit
790a25c348
|
@ -15,8 +15,8 @@ matrix:
|
||||||
before_script:
|
before_script:
|
||||||
- sudo apt-get install parallel
|
- sudo apt-get install parallel
|
||||||
- rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
|
- rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
|
||||||
- composer install --dev --prefer-source
|
- composer install --prefer-source
|
||||||
- bin/composer install --dev --prefer-source
|
- bin/composer install --prefer-source
|
||||||
- git config --global user.name travis-ci
|
- git config --global user.name travis-ci
|
||||||
- git config --global user.email travis@example.com
|
- git config --global user.email travis@example.com
|
||||||
|
|
||||||
|
|
|
@ -387,6 +387,7 @@ performance.
|
||||||
* **--optimize (-o):** Convert PSR-0/4 autoloading to classmap to get a faster
|
* **--optimize (-o):** Convert PSR-0/4 autoloading to classmap to get a faster
|
||||||
autoloader. This is recommended especially for production, but can take
|
autoloader. This is recommended especially for production, but can take
|
||||||
a bit of time to run so it is currently not done by default.
|
a bit of time to run so it is currently not done by default.
|
||||||
|
* **--no-dev:** Disables autoload-dev rules.
|
||||||
|
|
||||||
## licenses
|
## licenses
|
||||||
|
|
||||||
|
|
|
@ -518,22 +518,23 @@ Example:
|
||||||
|
|
||||||
### autoload-dev <span>(root-only)</span>
|
### 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
|
Classes needed to run the test suite should not be included in the main autoload
|
||||||
about performance, if so, you'll also don't want your test classes to be mixed up
|
rules to avoid polluting the autoloader in production and when other people use
|
||||||
with your regular classes in those classmaps.
|
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:
|
Example:
|
||||||
|
|
||||||
{
|
{
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": { "MyLibrary": "src/" }
|
"psr-4": { "MyLibrary\\": "src/" }
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-0": { "MyLibrary\\Tests": "tests/" }
|
"psr-4": { "MyLibrary\\Tests": "tests/" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class DumpAutoloadCommand extends Command
|
||||||
->setDescription('Dumps the autoloader')
|
->setDescription('Dumps the autoloader')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputOption('optimize', 'o', InputOption::VALUE_NONE, 'Optimizes PSR0 packages to be loaded with classmaps too, good for production.'),
|
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
|
->setHelp(<<<EOT
|
||||||
<info>php composer.phar dump-autoload</info>
|
<info>php composer.phar dump-autoload</info>
|
||||||
|
@ -61,7 +61,7 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
$generator = $composer->getAutoloadGenerator();
|
$generator = $composer->getAutoloadGenerator();
|
||||||
$generator->setDevMode($input->getOption('dev'));
|
$generator->setDevMode(!$input->getOption('no-dev'));
|
||||||
$generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
|
$generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
// Assert that autoload_classmap.php was correctly generated.
|
// Assert that autoload_classmap.php was correctly generated.
|
||||||
$this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
|
$this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMainPackageDevAutoloading()
|
public function testMainPackageDevAutoloading()
|
||||||
{
|
{
|
||||||
$package = new Package('a', '1.0', '1.0');
|
$package = new Package('a', '1.0', '1.0');
|
||||||
|
@ -181,6 +181,9 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
));
|
));
|
||||||
$package->setDevAutoload(array(
|
$package->setDevAutoload(array(
|
||||||
'files' => array('devfiles/foo.php'),
|
'files' => array('devfiles/foo.php'),
|
||||||
|
'psr-0' => array(
|
||||||
|
'Main' => 'tests/'
|
||||||
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->repository->expects($this->once())
|
$this->repository->expects($this->once())
|
||||||
|
@ -197,11 +200,11 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
// generate autoload files with the dev mode set to true
|
// generate autoload files with the dev mode set to true
|
||||||
$this->generator->setDevMode(true);
|
$this->generator->setDevMode(true);
|
||||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
|
||||||
|
|
||||||
// check standard autoload
|
// check standard autoload
|
||||||
$this->assertAutoloadFiles('main4', $this->vendorDir.'/composer');
|
$this->assertAutoloadFiles('main5', $this->vendorDir.'/composer');
|
||||||
$this->assertAutoloadFiles('classmap7', $this->vendorDir.'/composer', 'classmap');
|
$this->assertAutoloadFiles('classmap7', $this->vendorDir.'/composer', 'classmap');
|
||||||
|
|
||||||
// make sure dev autoload is correctly dumped
|
// make sure dev autoload is correctly dumped
|
||||||
$this->assertAutoloadFiles('files2', $this->vendorDir.'/composer', 'files');
|
$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
|
// make sure dev autoload is disabled when dev mode is set to false
|
||||||
$this->assertFalse(is_file($this->vendorDir.'/composer/autoload_files.php'));
|
$this->assertFalse(is_file($this->vendorDir.'/composer/autoload_files.php'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVendorDirSameAsWorkingDir()
|
public function testVendorDirSameAsWorkingDir()
|
||||||
{
|
{
|
||||||
$this->vendorDir = $this->workingDir;
|
$this->vendorDir = $this->workingDir;
|
||||||
|
|
|
@ -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'),
|
||||||
|
);
|
|
@ -12,9 +12,5 @@
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
$loader = require __DIR__.'/../src/bootstrap.php';
|
require __DIR__.'/../src/bootstrap.php';
|
||||||
|
|
||||||
// to be removed
|
|
||||||
$loader->add('Composer\Test', __DIR__);
|
|
||||||
|
|
||||||
require __DIR__.'/Composer/TestCase.php';
|
require __DIR__.'/Composer/TestCase.php';
|
||||||
|
|
Loading…
Reference in New Issue