Skip to content

Commit

Permalink
[Components] Tests/Autoloading fixes
Browse files Browse the repository at this point in the history
* Switched to Composer to manage "dev" dependencies
* Fixed READMEs
* Excluded vendor in phpunit.xml.dist files
* Fixed message in bootstrap.php files
* Added autoloader for the component itself
  • Loading branch information
willdurand committed May 1, 2012
1 parent 61e664a commit 82985ba
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
vendor/
composer.lock
12 changes: 5 additions & 7 deletions README.md
Expand Up @@ -48,8 +48,8 @@ If your service is retrieved by calling a static method:

File Include:

For some services, especially those that are difficult or impossible to
autoload, you may need the container to include a file before
For some services, especially those that are difficult or impossible to
autoload, you may need the container to include a file before
instantiating your class.

$sc = new ContainerBuilder();
Expand All @@ -68,11 +68,9 @@ Resources

You can run the unit tests with the following command:

phpunit -c src/Symfony/Component/DependencyInjection/
phpunit

If you also want to run the unit tests that depend on other Symfony
Components, declare the following environment variables before running
PHPUnit:
Components, install dev dependencies before running PHPUnit:

export SYMFONY_CONFIG=../path/to/Config
export SYMFONY_YAML=../path/to/Yaml
php composer.phar install --dev
15 changes: 4 additions & 11 deletions Tests/bootstrap.php
Expand Up @@ -10,20 +10,13 @@
*/

spl_autoload_register(function ($class) {
foreach (array(
'SYMFONY_CONFIG' => 'Config',
'SYMFONY_YAML' => 'Yaml',
) as $env => $name) {
if (isset($_SERVER[$env]) && 0 === strpos(ltrim($class, '/'), 'Symfony\Component\\'.$name)) {
if (file_exists($file = $_SERVER[$env].'/'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\\'.$name)).'.php')) {
require_once $file;
}
}
}

if (0 === strpos(ltrim($class, '/'), 'Symfony\Component\DependencyInjection')) {
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\DependencyInjection')).'.php')) {
require_once $file;
}
}
});

if (file_exists($loader = __DIR__.'/../vendor/autoload.php')) {
require_once $loader;
}
4 changes: 4 additions & 0 deletions composer.json
Expand Up @@ -18,6 +18,10 @@
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"symfony/yaml": "2.1.*",
"symfony/config": "2.1.*"
},
"suggest": {
"symfony/yaml": "self.version",
"symfony/config": "self.version"
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -23,6 +23,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down

0 comments on commit 82985ba

Please sign in to comment.