Przeglądaj źródła

added a way to run tests that depends on external libraries

Fabien Potencier 15 lat temu
rodzic
commit
a79ad894f9

+ 22 - 0
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
 -------------
 

+ 27 - 0
autoload.php.dist

@@ -0,0 +1,27 @@
+<?php
+
+require_once __DIR__.'/src/Symfony/Foundation/UniversalClassLoader.php';
+
+use Symfony\Foundation\UniversalClassLoader;
+
+$loader = new UniversalClassLoader();
+$loader->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()
+);

+ 2 - 8
phpunit.xml.dist

@@ -9,12 +9,12 @@
          processIsolation="false"
          stopOnFailure="false"
          syntaxCheck="false"
-         bootstrap="tests/Symfony/Tests/bootstrap.php"
+         bootstrap="tests/bootstrap.php"
 >
   <testsuites>
     <testsuite name="Symfony Test Suite">
       <directory>./tests/Symfony/</directory>
-      <directory>./src/Symfony/Framework/</directory>
+      <directory>./src/Symfony/Framework/*/Tests/</directory>
     </testsuite>
   </testsuites>
 
@@ -22,13 +22,7 @@
     <whitelist>
       <directory>./src/Symfony/</directory>
       <exclude>
-        <directory>./src/Symfony/Framework/DoctrineBundle</directory>
-        <directory>./src/Symfony/Framework/DoctrineMigrationsBundle</directory>
-        <directory>./src/Symfony/Framework/TwigBundle</directory>
-        <directory>./src/Symfony/Framework/ZendBundle</directory>
-
         <directory>./src/Symfony/Framework/*/Resources</directory>
-
         <file>./src/Symfony/Foundation/bootstrap.php</file>
         <file>./src/Symfony/Foundation/packager.php</file>
       </exclude>

+ 22 - 0
src/Symfony/Framework/DoctrineBundle/Tests/TestCase.php

@@ -0,0 +1,22 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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.');
+        }
+    }
+}

+ 4 - 4
tests/Symfony/Tests/bootstrap.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
+{
+}

+ 24 - 0
src/Symfony/Framework/PropelBundle/Tests/TestCase.php

@@ -0,0 +1,24 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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;
+    }
+}

+ 22 - 0
src/Symfony/Framework/SwiftmailerBundle/Tests/TestCase.php

@@ -0,0 +1,22 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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.');
+        }
+    }
+}

+ 22 - 0
src/Symfony/Framework/TwigBundle/Tests/TestCase.php

@@ -0,0 +1,22 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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.');
+        }
+    }
+}

+ 16 - 0
src/Symfony/Framework/WebBundle/Tests/TestCase.php

@@ -0,0 +1,16 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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
+{
+}

+ 4 - 3
tests/Symfony/Tests/Framework/WebBundle/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();

tests/fixtures/Symfony/Framework/WebBundle/Util/foo/bar.txt → src/Symfony/Framework/WebBundle/Tests/Util/fixtures/foo/bar.txt


tests/fixtures/Symfony/Framework/WebBundle/Util/foo/bar/foo.txt → src/Symfony/Framework/WebBundle/Tests/Util/fixtures/foo/bar/foo.txt


tests/fixtures/Symfony/Framework/WebBundle/Util/template.txt → src/Symfony/Framework/WebBundle/Tests/Util/fixtures/template.txt


+ 22 - 0
src/Symfony/Framework/ZendBundle/Tests/TestCase.php

@@ -0,0 +1,22 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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.');
+        }
+    }
+}

+ 22 - 0
tests/bootstrap.php

@@ -0,0 +1,22 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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;
+}