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.
This commit is contained in:
Christian Flothmann 2019-02-14 13:21:09 +01:00
parent 320c05f9f1
commit be23926bf8
11 changed files with 50 additions and 0 deletions

View File

@ -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();

View File

@ -57,6 +57,8 @@ class EntityTypeTest extends BaseTypeTest
*/
private $emRegistry;
protected static $supportedFeatureSetVersion = 304;
protected function setUp()
{
$this->em = DoctrineTestHelper::createTestEntityManager();

View File

@ -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');

View File

@ -31,6 +31,8 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
*/
private $renderer;
protected static $supportedFeatureSetVersion = 304;
protected function setUp()
{
parent::setUp();

View File

@ -30,6 +30,8 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
*/
private $renderer;
protected static $supportedFeatureSetVersion = 304;
protected function setUp()
{
parent::setUp();

View File

@ -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

View File

@ -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, [

View File

@ -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
*/

View File

@ -18,6 +18,8 @@ use Symfony\Component\Form\Test\FormIntegrationTestCase;
abstract class AbstractLayoutTest extends FormIntegrationTestCase
{
use VersionAwareTest;
protected $csrfTokenManager;
protected $testableFeatures = [];

View File

@ -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 <bschussek@gmail.com>
*/
abstract class BaseTypeTest extends TypeTestCase
{
use VersionAwareTest;
const TESTED_TYPE = '';
public function testPassDisabledAsOption()

View File

@ -0,0 +1,27 @@
<?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\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));
}
}
}