From a79ad894f920e2f78d1f09f25901e91a74430686 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 6 Jun 2010 10:35:20 +0200 Subject: [PATCH] added a way to run tests that depends on external libraries --- README | 22 +++++++++++++++ autoload.php.dist | 27 +++++++++++++++++++ phpunit.xml.dist | 10 ++----- .../DoctrineBundle/Tests/TestCase.php | 22 +++++++++++++++ .../ProfilerBundle/Tests/TestCase.php | 8 +++--- .../Framework/PropelBundle/Tests/TestCase.php | 24 +++++++++++++++++ .../SwiftmailerBundle/Tests/TestCase.php | 22 +++++++++++++++ .../Framework/TwigBundle/Tests/TestCase.php | 22 +++++++++++++++ .../Framework/WebBundle/Tests/TestCase.php | 16 +++++++++++ .../WebBundle/Tests}/Util/MustacheTest.php | 7 ++--- .../Tests/Util/fixtures}/foo/bar.txt | 0 .../Tests/Util/fixtures}/foo/bar/foo.txt | 0 .../Tests/Util/fixtures}/template.txt | 0 .../Framework/ZendBundle/Tests/TestCase.php | 22 +++++++++++++++ tests/bootstrap.php | 22 +++++++++++++++ 15 files changed, 209 insertions(+), 15 deletions(-) create mode 100644 autoload.php.dist create mode 100644 src/Symfony/Framework/DoctrineBundle/Tests/TestCase.php rename tests/Symfony/Tests/bootstrap.php => src/Symfony/Framework/ProfilerBundle/Tests/TestCase.php (53%) create mode 100644 src/Symfony/Framework/PropelBundle/Tests/TestCase.php create mode 100644 src/Symfony/Framework/SwiftmailerBundle/Tests/TestCase.php create mode 100644 src/Symfony/Framework/TwigBundle/Tests/TestCase.php create mode 100644 src/Symfony/Framework/WebBundle/Tests/TestCase.php rename {tests/Symfony/Tests/Framework/WebBundle => src/Symfony/Framework/WebBundle/Tests}/Util/MustacheTest.php (89%) rename {tests/fixtures/Symfony/Framework/WebBundle/Util => src/Symfony/Framework/WebBundle/Tests/Util/fixtures}/foo/bar.txt (100%) rename {tests/fixtures/Symfony/Framework/WebBundle/Util => src/Symfony/Framework/WebBundle/Tests/Util/fixtures}/foo/bar/foo.txt (100%) rename {tests/fixtures/Symfony/Framework/WebBundle/Util => src/Symfony/Framework/WebBundle/Tests/Util/fixtures}/template.txt (100%) create mode 100644 src/Symfony/Framework/ZendBundle/Tests/TestCase.php create mode 100644 tests/bootstrap.php diff --git a/README b/README index 452602f9b9..50fba1cdc1 100644 --- a/README +++ b/README @@ -23,6 +23,28 @@ Requirements Symfony is only supported on PHP 5.3.0 and up. +Tests +----- + +To run the Symfony test suite, you need PHPUnit 3.5 or later. + +If you want to run the tests that depend on external dependencies, the test +suite needs to be able to autoload them. By default, they are autoloaded from +a `vendor/` directory under the main root directory (see `autoload.php.dist`). +To put them in a different directory, create your own `autoload.php` file. + +A working `vendor/` directory looks like the following: + + * `doctrine/` + * `doctrine-migrations` + * `phing/` + * `propel/` + * `swiftmailer/` + * `twig/` + * `zend/` + +Note that the code coverage only works if you have all dependencies installed. + Documentation ------------- diff --git a/autoload.php.dist b/autoload.php.dist new file mode 100644 index 0000000000..570bf4dfe5 --- /dev/null +++ b/autoload.php.dist @@ -0,0 +1,27 @@ +registerNamespaces(array( + 'Doctrine\\Common' => __DIR__.'/vendor/doctrine/lib/vendor/doctrine-common/lib', + 'Doctrine\\DBAL\\Migrations' => __DIR__.'/vendor/doctrine-migrations/lib', + 'Doctrine\\DBAL' => __DIR__.'/vendor/doctrine/lib/vendor/doctrine-dbal/lib', + 'Doctrine' => __DIR__.'/vendor/doctrine/lib', +)); +$loader->registerPrefixes(array( + 'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes', + 'Zend_' => __DIR__.'/vendor/zend/library', + 'Twig_' => __DIR__.'/vendor/twig/lib', +)); +$loader->register(); + +// for Zend Framework & SwiftMailer +set_include_path( + __DIR__.'/vendor/zend/library'.PATH_SEPARATOR. + __DIR__.'/vendor/swiftmailer/lib'.PATH_SEPARATOR. + __DIR__.'/vendor/phing/classes'.PATH_SEPARATOR. + get_include_path() +); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e4e3fba3ca..06ddc70eb2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,12 +9,12 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="tests/Symfony/Tests/bootstrap.php" + bootstrap="tests/bootstrap.php" > ./tests/Symfony/ - ./src/Symfony/Framework/ + ./src/Symfony/Framework/*/Tests/ @@ -22,13 +22,7 @@ ./src/Symfony/ - ./src/Symfony/Framework/DoctrineBundle - ./src/Symfony/Framework/DoctrineMigrationsBundle - ./src/Symfony/Framework/TwigBundle - ./src/Symfony/Framework/ZendBundle - ./src/Symfony/Framework/*/Resources - ./src/Symfony/Foundation/bootstrap.php ./src/Symfony/Foundation/packager.php diff --git a/src/Symfony/Framework/DoctrineBundle/Tests/TestCase.php b/src/Symfony/Framework/DoctrineBundle/Tests/TestCase.php new file mode 100644 index 0000000000..1cce5f371e --- /dev/null +++ b/src/Symfony/Framework/DoctrineBundle/Tests/TestCase.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Framework\DoctrineBundle\Tests; + +class TestCase extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + if (!class_exists('Doctrine\\Common\\Version')) { + $this->markTestSkipped('Doctrine is not available.'); + } + } +} diff --git a/tests/Symfony/Tests/bootstrap.php b/src/Symfony/Framework/ProfilerBundle/Tests/TestCase.php similarity index 53% rename from tests/Symfony/Tests/bootstrap.php rename to src/Symfony/Framework/ProfilerBundle/Tests/TestCase.php index 9db675ed68..9c33135fbe 100644 --- a/tests/Symfony/Tests/bootstrap.php +++ b/src/Symfony/Framework/ProfilerBundle/Tests/TestCase.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -require_once __DIR__.'/../../../src/Symfony/Foundation/UniversalClassLoader.php'; +namespace Symfony\Framework\ProfilerBundle\Tests; -$loader = new Symfony\Foundation\UniversalClassLoader(); -$loader->registerNamespace('Symfony', __DIR__.'/../../../src'); -$loader->register(); +class TestCase extends \PHPUnit_Framework_TestCase +{ +} diff --git a/src/Symfony/Framework/PropelBundle/Tests/TestCase.php b/src/Symfony/Framework/PropelBundle/Tests/TestCase.php new file mode 100644 index 0000000000..ebbc1a8977 --- /dev/null +++ b/src/Symfony/Framework/PropelBundle/Tests/TestCase.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Framework\PropelBundle\Tests; + +class TestCase extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + if (!file_exists($file = __DIR__.'/../../../../../vendor/propel/runtime/lib/Propel.php')) { + $this->markTestSkipped('Propel is not available.'); + } + + require_once $file; + } +} diff --git a/src/Symfony/Framework/SwiftmailerBundle/Tests/TestCase.php b/src/Symfony/Framework/SwiftmailerBundle/Tests/TestCase.php new file mode 100644 index 0000000000..9e9de380db --- /dev/null +++ b/src/Symfony/Framework/SwiftmailerBundle/Tests/TestCase.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Framework\SwiftmailerBundle\Tests; + +class TestCase extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + if (!class_exists('Swift_Mailer')) { + $this->markTestSkipped('Swiftmailer is not available.'); + } + } +} diff --git a/src/Symfony/Framework/TwigBundle/Tests/TestCase.php b/src/Symfony/Framework/TwigBundle/Tests/TestCase.php new file mode 100644 index 0000000000..52e2094b53 --- /dev/null +++ b/src/Symfony/Framework/TwigBundle/Tests/TestCase.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Framework\TwigBundle\Tests; + +class TestCase extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + if (!class_exists('Twig_Environment')) { + $this->markTestSkipped('Twig is not available.'); + } + } +} diff --git a/src/Symfony/Framework/WebBundle/Tests/TestCase.php b/src/Symfony/Framework/WebBundle/Tests/TestCase.php new file mode 100644 index 0000000000..367e6d53e1 --- /dev/null +++ b/src/Symfony/Framework/WebBundle/Tests/TestCase.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Framework\WebBundle\Tests; + +class TestCase extends \PHPUnit_Framework_TestCase +{ +} diff --git a/tests/Symfony/Tests/Framework/WebBundle/Util/MustacheTest.php b/src/Symfony/Framework/WebBundle/Tests/Util/MustacheTest.php similarity index 89% rename from tests/Symfony/Tests/Framework/WebBundle/Util/MustacheTest.php rename to src/Symfony/Framework/WebBundle/Tests/Util/MustacheTest.php index 6324374687..6aafff8b19 100644 --- a/tests/Symfony/Tests/Framework/WebBundle/Util/MustacheTest.php +++ b/src/Symfony/Framework/WebBundle/Tests/Util/MustacheTest.php @@ -9,18 +9,19 @@ * file that was distributed with this source code. */ -namespace Symfony\Tests\Framework\WebBundle\Util; +namespace Symfony\Framework\WebBundle\Tests\Util; +use Symfony\Framework\WebBundle\Tests\TestCase; use Symfony\Framework\WebBundle\Util\Mustache; use Symfony\Framework\WebBundle\Util\Filesystem; -class MustacheTest extends \PHPUnit_Framework_TestCase +class MustacheTest extends TestCase { protected $dir; public function setUp() { - $dir = __DIR__.'/../../../../../fixtures/Symfony/Framework/WebBundle/Util'; + $dir = __DIR__.'/fixtures/'; $this->dir = sys_get_temp_dir().'/mustache'; $filesystem = new Filesystem(); diff --git a/tests/fixtures/Symfony/Framework/WebBundle/Util/foo/bar.txt b/src/Symfony/Framework/WebBundle/Tests/Util/fixtures/foo/bar.txt similarity index 100% rename from tests/fixtures/Symfony/Framework/WebBundle/Util/foo/bar.txt rename to src/Symfony/Framework/WebBundle/Tests/Util/fixtures/foo/bar.txt diff --git a/tests/fixtures/Symfony/Framework/WebBundle/Util/foo/bar/foo.txt b/src/Symfony/Framework/WebBundle/Tests/Util/fixtures/foo/bar/foo.txt similarity index 100% rename from tests/fixtures/Symfony/Framework/WebBundle/Util/foo/bar/foo.txt rename to src/Symfony/Framework/WebBundle/Tests/Util/fixtures/foo/bar/foo.txt diff --git a/tests/fixtures/Symfony/Framework/WebBundle/Util/template.txt b/src/Symfony/Framework/WebBundle/Tests/Util/fixtures/template.txt similarity index 100% rename from tests/fixtures/Symfony/Framework/WebBundle/Util/template.txt rename to src/Symfony/Framework/WebBundle/Tests/Util/fixtures/template.txt diff --git a/src/Symfony/Framework/ZendBundle/Tests/TestCase.php b/src/Symfony/Framework/ZendBundle/Tests/TestCase.php new file mode 100644 index 0000000000..727bca4f3c --- /dev/null +++ b/src/Symfony/Framework/ZendBundle/Tests/TestCase.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Framework\ZendBundle\Tests; + +class TestCase extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + if (!class_exists('Zend_Log')) { + $this->markTestSkipped('Zend Framework is not available.'); + } + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000000..df82c2f376 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require_once __DIR__.'/../src/Symfony/Foundation/UniversalClassLoader.php'; + +$loader = new Symfony\Foundation\UniversalClassLoader(); +$loader->registerNamespace('Symfony', __DIR__.'/../src'); +$loader->register(); + +if (file_exists($file = __DIR__.'/../autoload.php')) { + require_once $file; +} elseif (file_exists($file = __DIR__.'/../autoload.php.dist')) { + require_once $file; +}