瀏覽代碼

Skip tests if some vendor are not available (prevents fatal errors)

stloyd 14 年之前
父節點
當前提交
039292bb94

+ 1 - 1
src/Symfony/Bundle/MonologBundle/Tests/TestCase.php

@@ -15,7 +15,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
 {
     protected function setUp()
     {
-        if (!class_exists('Monolog\Logger')) {
+        if (!class_exists('Monolog\\Logger')) {
             $this->markTestSkipped('Monolog is not available.');
         }
     }

+ 5 - 1
src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ExceptionControllerTest.php

@@ -11,13 +11,15 @@
 
 namespace Symfony\Bundle\WebProfilerBundle\Tests\Controller;
 
+use Symfony\Bundle\WebProfilerBundle\Tests\TestCase;
+
 use Symfony\Bundle\WebProfilerBundle\Controller\ExceptionController;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\DependencyInjection\Reference;
 use Symfony\Component\DependencyInjection\Scope;
 use Symfony\Component\DependencyInjection\Definition;
 
-class ExceptionControllerTest extends \PHPUnit_Framework_TestCase
+class ExceptionControllerTest extends TestCase
 {
     protected $controller;
     protected $container;
@@ -26,6 +28,8 @@ class ExceptionControllerTest extends \PHPUnit_Framework_TestCase
 
     protected function setUp()
     {
+        parent::setUp();
+
         $this->flatten = $this->getMock('Symfony\Component\HttpKernel\Exception\FlattenException');
         $this->flatten->expects($this->once())->method('getStatusCode')->will($this->returnValue(404));
         $this->controller = new ExceptionController();

+ 4 - 1
src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php

@@ -11,6 +11,8 @@
 
 namespace Symfony\Bundle\WebProfilerBundle\Tests\DependencyInjection;
 
+use Symfony\Bundle\WebProfilerBundle\Tests\TestCase;
+
 use Symfony\Bundle\WebProfilerBundle\DependencyInjection\WebProfilerExtension;
 use Symfony\Component\Config\FileLocator;
 use Symfony\Component\DependencyInjection\Container;
@@ -25,7 +27,7 @@ use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
 use Symfony\Component\DependencyInjection\Scope;
 
-class WebProfilerExtensionTest extends \PHPUnit_Framework_TestCase
+class WebProfilerExtensionTest extends TestCase
 {
     private $kernel;
     /**
@@ -49,6 +51,7 @@ class WebProfilerExtensionTest extends \PHPUnit_Framework_TestCase
 
     protected function setUp()
     {
+        parent::setUp();
 
         $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
 

+ 22 - 0
src/Symfony/Bundle/WebProfilerBundle/Tests/TestCase.php

@@ -0,0 +1,22 @@
+<?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.
+ */
+
+namespace Symfony\Bundle\WebProfilerBundle\Tests;
+
+class TestCase extends \PHPUnit_Framework_TestCase
+{
+    protected function setUp()
+    {
+        if (!class_exists('Twig_Environment')) {
+            $this->markTestSkipped('Twig is not available.');
+        }
+    }
+}

+ 13 - 7
tests/Symfony/Tests/Bridge/Twig/Extension/Fixtures/StubFilesystemLoader.php

@@ -11,13 +11,19 @@
 
 namespace Symfony\Tests\Bridge\Twig\Extension\Fixtures;
 
-class StubFilesystemLoader extends \Twig_Loader_Filesystem
-{
-    protected function findTemplate($name)
+// Preventing autoloader throwing E_FATAL when Twig is now available
+if (!class_exists('Twig_Environment')) {
+    class StubFilesystemLoader {
+    }
+} else {
+    class StubFilesystemLoader extends \Twig_Loader_Filesystem
     {
-        // strip away bundle name
-        $parts = explode(':', $name);
-
-        return parent::findTemplate(end($parts));
+        protected function findTemplate($name)
+        {
+            // strip away bundle name
+            $parts = explode(':', $name);
+ 
+            return parent::findTemplate(end($parts));
+        }
     }
 }

+ 4 - 0
tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionDivLayoutTest.php

@@ -25,6 +25,10 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
 {
     protected function setUp()
     {
+        if (!class_exists('Twig_Environment')) {
+            $this->markTestSkipped('Twig is not available.');
+        }
+
         parent::setUp();
 
         $loader = new StubFilesystemLoader(array(

+ 4 - 0
tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionTableLayoutTest.php

@@ -25,6 +25,10 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
 {
     protected function setUp()
     {
+        if (!class_exists('Twig_Environment')) {
+            $this->markTestSkipped('Twig is not available.');
+        }
+
         parent::setUp();
 
         $loader = new StubFilesystemLoader(array(