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 b0a6956 commit c195957
Show file tree
Hide file tree
Showing 78 changed files with 255 additions and 267 deletions.
2 changes: 2 additions & 0 deletions src/Symfony/Component/BrowserKit/.gitignore
@@ -0,0 +1,2 @@
vendor/
composer.lock
8 changes: 3 additions & 5 deletions src/Symfony/Component/BrowserKit/README.md
Expand Up @@ -18,11 +18,9 @@ provided by the HttpKernel component.

You can run the unit tests with the following command:

phpunit -c src/Symfony/Component/BrowserKit/
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_PROCESS=../path/to/Process
export SYMFONY_DOM_CRAWLER=../path/to/DomCrawler
php composer.phar install --dev
16 changes: 4 additions & 12 deletions src/Symfony/Component/BrowserKit/Tests/bootstrap.php
Expand Up @@ -10,21 +10,13 @@
*/

spl_autoload_register(function ($class) {
foreach (array(
'SYMFONY_PROCESS' => 'Process',
'SYMFONY_DOM_CRAWLER' => 'DomCrawler',
'SYMFONY_CSS_SELECTOR' => 'CssSelector',
) 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\BrowserKit')) {
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\BrowserKit')).'.php')) {
require_once $file;
}
}
});

if (file_exists($loader = __DIR__.'/../vendor/autoload.php')) {
require_once $loader;
}
6 changes: 5 additions & 1 deletion src/Symfony/Component/BrowserKit/composer.json
Expand Up @@ -17,7 +17,11 @@
],
"require": {
"php": ">=5.3.2",
"symfony/dom-crawler": "self.version"
"symfony/dom-crawler": "2.1.*"
},
"require-dev": {
"symfony/process": "2.1.*",
"symfony/css-selector": "2.1.*"
},
"suggest": {
"symfony/process": "self.version"
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/BrowserKit/phpunit.xml.dist
Expand Up @@ -23,6 +23,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/ClassLoader/.gitignore
@@ -0,0 +1,2 @@
vendor/
composer.lock
7 changes: 3 additions & 4 deletions src/Symfony/Component/ClassLoader/README.md
Expand Up @@ -64,10 +64,9 @@ Resources

You can run the unit tests with the following command:

phpunit -c src/Symfony/Component/ClassLoader/
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_FINDER=../path/to/Finder
php composer.phar install --dev
14 changes: 4 additions & 10 deletions src/Symfony/Component/ClassLoader/Tests/bootstrap.php
Expand Up @@ -10,19 +10,13 @@
*/

spl_autoload_register(function ($class) {
foreach (array(
'SYMFONY_FINDER' => 'Finder',
) 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\ClassLoader')) {
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\ClassLoader')).'.php')) {
require_once $file;
}
}
});

if (file_exists($loader = __DIR__.'/../vendor/autoload.php')) {
require_once $loader;
}
3 changes: 3 additions & 0 deletions src/Symfony/Component/ClassLoader/composer.json
Expand Up @@ -18,6 +18,9 @@
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"symfony/finder": "2.1.*"
},
"autoload": {
"psr-0": { "Symfony\\Component\\ClassLoader": "" }
},
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/ClassLoader/phpunit.xml.dist
Expand Up @@ -23,6 +23,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/README.md
Expand Up @@ -11,4 +11,4 @@ Resources

You can run the unit tests with the following command:

phpunit -c src/Symfony/Component/Config/
phpunit
1 change: 1 addition & 0 deletions src/Symfony/Component/Config/phpunit.xml.dist
Expand Up @@ -23,6 +23,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/README.md
Expand Up @@ -45,10 +45,10 @@ Tests

You can run the unit tests with the following command:

phpunit -c src/Symfony/Component/Console
phpunit

Resources
---------
---------

[The Console Component](http://symfony.com/doc/current/components/console.html)

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/phpunit.xml.dist
Expand Up @@ -23,6 +23,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/CssSelector/README.md
Expand Up @@ -20,4 +20,4 @@ Current code is a port of http://codespeak.net/svn/lxml/trunk/src/lxml/cssselect

You can run the unit tests with the following command:

phpunit -c src/Symfony/Component/CssSelector/
phpunit
1 change: 1 addition & 0 deletions src/Symfony/Component/CssSelector/phpunit.xml.dist
Expand Up @@ -23,6 +23,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/DependencyInjection/.gitignore
@@ -0,0 +1,2 @@
vendor/
composer.lock
12 changes: 5 additions & 7 deletions src/Symfony/Component/DependencyInjection/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 src/Symfony/Component/DependencyInjection/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 src/Symfony/Component/DependencyInjection/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 src/Symfony/Component/DependencyInjection/phpunit.xml.dist
Expand Up @@ -23,6 +23,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/DomCrawler/.gitignore
@@ -0,0 +1,2 @@
vendor/
composer.lock
7 changes: 3 additions & 4 deletions src/Symfony/Component/DomCrawler/README.md
Expand Up @@ -27,10 +27,9 @@ Resources

You can run the unit tests with the following command:

phpunit -c src/Symfony/Component/DomCrawler/
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_CSS_SELECTOR=../path/to/CssSelector
php composer.phar install --dev
14 changes: 4 additions & 10 deletions src/Symfony/Component/DomCrawler/Tests/bootstrap.php
Expand Up @@ -10,19 +10,13 @@
*/

spl_autoload_register(function ($class) {
foreach (array(
'SYMFONY_CSS_SELECTOR' => 'CssSelector',
) 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\DomCrawler')) {
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\DomCrawler')).'.php')) {
require_once $file;
}
}
});

if (file_exists($loader = __DIR__.'/../vendor/autoload.php')) {
require_once $loader;
}
3 changes: 3 additions & 0 deletions src/Symfony/Component/DomCrawler/composer.json
Expand Up @@ -18,6 +18,9 @@
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"symfony/css-selector": "2.1.*"
},
"suggest": {
"symfony/css-selector": "self.version"
},
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/DomCrawler/phpunit.xml.dist
Expand Up @@ -23,6 +23,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/EventDispatcher/.gitignore
@@ -0,0 +1,2 @@
vendor/
composer.lock
8 changes: 3 additions & 5 deletions src/Symfony/Component/EventDispatcher/README.md
Expand Up @@ -20,11 +20,9 @@ Resources

You can run the unit tests with the following command:

phpunit -c src/Symfony/Component/EventDispatcher/
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_DEPENDENCY_INJECTION=../path/to/DependencyInjection
export SYMFONY_HTTP_KERNEL=../path/to/HttpKernel
php composer.phar install --dev
15 changes: 4 additions & 11 deletions src/Symfony/Component/EventDispatcher/Tests/bootstrap.php
Expand Up @@ -10,20 +10,13 @@
*/

spl_autoload_register(function ($class) {
foreach (array(
'SYMFONY_DEPENDENCY_INJECTION' => 'DependencyInjection',
'SYMFONY_HTTP_KERNEL' => 'HttpKernel',
) 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\EventDispatcher')) {
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\EventDispatcher')).'.php')) {
require_once $file;
}
}
});

if (file_exists($loader = __DIR__.'/../vendor/autoload.php')) {
require_once $loader;
}
3 changes: 3 additions & 0 deletions src/Symfony/Component/EventDispatcher/composer.json
Expand Up @@ -18,6 +18,9 @@
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"symfony/dependency-injection": "2.1.*"
},
"suggest": {
"symfony/dependency-injection": "self.version",
"symfony/http-kernel": "self.version"
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/EventDispatcher/phpunit.xml.dist
Expand Up @@ -23,6 +23,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/Filesystem/README.md
Expand Up @@ -27,3 +27,9 @@ Filesystem provides basic utility to manipulate the file system:

$filesystem->isAbsolutePath($file);

Resources
---------

You can run the unit tests with the following command:

phpunit
18 changes: 18 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/bootstrap.php
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

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

0 comments on commit c195957

Please sign in to comment.