From be23926bf8fec30be5ef593a410d06cf6ebede26 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 14 Feb 2019 13:21:09 +0100 Subject: [PATCH] allow to skip tests based on the supported version Writing tests for Form related features in the Doctrine and Twig bridges as well as the FrameworkBundle is a pain as soon as these tests are run with more recent versions of the Form component. This is due to the fact that our tests in the bridges and bundle extend test cases from the component. The tests in the component are expanded with every feature that gets added there. However, these new features are not present in the other packages in older version and we thus need to be able to skip them somehow. --- .../Form/Type/EntityTypePerformanceTest.php | 2 ++ .../Tests/Form/Type/EntityTypeTest.php | 2 ++ .../AbstractBootstrap3LayoutTest.php | 2 ++ .../Extension/FormExtensionDivLayoutTest.php | 2 ++ .../FormExtensionTableLayoutTest.php | 2 ++ .../Helper/FormHelperDivLayoutTest.php | 2 ++ .../Helper/FormHelperTableLayoutTest.php | 2 ++ .../Form/Test/FormPerformanceTestCase.php | 4 +++ .../Form/Tests/AbstractLayoutTest.php | 2 ++ .../Extension/Core/Type/BaseTypeTest.php | 3 +++ .../Component/Form/Tests/VersionAwareTest.php | 27 +++++++++++++++++++ 11 files changed, 50 insertions(+) create mode 100644 src/Symfony/Component/Form/Tests/VersionAwareTest.php diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php index afdeb5f720..5012171542 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php @@ -30,6 +30,8 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase */ private $em; + protected static $supportedFeatureSetVersion = 304; + protected function getExtensions() { $manager = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index 2869c2b804..1cb59c3843 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -57,6 +57,8 @@ class EntityTypeTest extends BaseTypeTest */ private $emRegistry; + protected static $supportedFeatureSetVersion = 304; + protected function setUp() { $this->em = DoctrineTestHelper::createTestEntityManager(); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php index 353611a4eb..e50076da73 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php @@ -16,6 +16,8 @@ use Symfony\Component\Form\Tests\AbstractLayoutTest; abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest { + protected static $supportedFeatureSetVersion = 304; + public function testLabelOnForm() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType'); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index 456e6730fa..214df3c7f6 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -31,6 +31,8 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest */ private $renderer; + protected static $supportedFeatureSetVersion = 304; + protected function setUp() { parent::setUp(); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php index 7811a41eb6..f956767363 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php @@ -30,6 +30,8 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest */ private $renderer; + protected static $supportedFeatureSetVersion = 304; + protected function setUp() { parent::setUp(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php index 7e8d8f0972..03b2ed6961 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php @@ -27,6 +27,8 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest */ protected $engine; + protected static $supportedFeatureSetVersion = 304; + protected function getExtensions() { // should be moved to the Form component once absolute file paths are supported diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php index fc5e7d17f3..bd088078c3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php @@ -27,6 +27,8 @@ class FormHelperTableLayoutTest extends AbstractTableLayoutTest */ protected $engine; + protected static $supportedFeatureSetVersion = 304; + public function testStartTagHasNoActionAttributeWhenActionIsEmpty() { $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, [ diff --git a/src/Symfony/Component/Form/Test/FormPerformanceTestCase.php b/src/Symfony/Component/Form/Test/FormPerformanceTestCase.php index 01440575a1..e11ce03357 100644 --- a/src/Symfony/Component/Form/Test/FormPerformanceTestCase.php +++ b/src/Symfony/Component/Form/Test/FormPerformanceTestCase.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Form\Test; +use Symfony\Component\Form\Tests\VersionAwareTest; + /** * Base class for performance tests. * @@ -21,6 +23,8 @@ namespace Symfony\Component\Form\Test; */ abstract class FormPerformanceTestCase extends FormIntegrationTestCase { + use VersionAwareTest; + /** * @var int */ diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index a1e8e4f460..4e01253e2e 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -18,6 +18,8 @@ use Symfony\Component\Form\Test\FormIntegrationTestCase; abstract class AbstractLayoutTest extends FormIntegrationTestCase { + use VersionAwareTest; + protected $csrfTokenManager; protected $testableFeatures = []; diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php index 92eff38669..62654fc618 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php @@ -12,12 +12,15 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; use Symfony\Component\Form\Test\TypeTestCase; +use Symfony\Component\Form\Tests\VersionAwareTest; /** * @author Bernhard Schussek */ abstract class BaseTypeTest extends TypeTestCase { + use VersionAwareTest; + const TESTED_TYPE = ''; public function testPassDisabledAsOption() diff --git a/src/Symfony/Component/Form/Tests/VersionAwareTest.php b/src/Symfony/Component/Form/Tests/VersionAwareTest.php new file mode 100644 index 0000000000..2b8489a6a2 --- /dev/null +++ b/src/Symfony/Component/Form/Tests/VersionAwareTest.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests; + +trait VersionAwareTest +{ + protected static $supportedFeatureSetVersion = 304; + + /** + * @param int $requiredFeatureSetVersion + */ + protected function requiresFeatureSet($requiredFeatureSetVersion) + { + if ($requiredFeatureSetVersion > static::$supportedFeatureSetVersion) { + $this->markTestSkipped(sprintf('Test requires features from symfony/form %.2f but only version %.2f is supported.', $requiredFeatureSetVersion / 100, static::$supportedFeatureSetVersion / 100)); + } + } +}