Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #30071
- Loading branch information
Showing
6 changed files
with
214 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/Symfony/Component/Form/Test/FormIntegrationTestCaseSetupTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?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\Test; | ||
|
||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Form\Forms; | ||
|
||
// Auto-adapt to PHPUnit 8 that added a `void` return-type to the setUp/tearDown methods | ||
|
||
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) { | ||
eval(' | ||
namespace Symfony\Component\Validator\Test; | ||
/** | ||
* @internal | ||
*/ | ||
trait FormIntegrationTestCaseSetupTrait | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->factory = Forms::createFormFactoryBuilder() | ||
->addExtensions($this->getExtensions()) | ||
->addTypeExtensions($this->getTypeExtensions()) | ||
->addTypes($this->getTypes()) | ||
->addTypeGuessers($this->getTypeGuessers()) | ||
->getFormFactory(); | ||
} | ||
} | ||
'); | ||
} else { | ||
/** | ||
* @internal | ||
*/ | ||
trait FormIntegrationTestCaseSetupTrait | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->factory = Forms::createFormFactoryBuilder() | ||
->addExtensions($this->getExtensions()) | ||
->addTypeExtensions($this->getTypeExtensions()) | ||
->addTypes($this->getTypes()) | ||
->addTypeGuessers($this->getTypeGuessers()) | ||
->getFormFactory(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/Symfony/Component/Form/Test/TypeTestCaseSetupTeardownTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?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\Test; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Form\FormBuilder; | ||
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait; | ||
|
||
// Auto-adapt to PHPUnit 8 that added a `void` return-type to the setUp/tearDown methods | ||
|
||
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) { | ||
eval(' | ||
namespace Symfony\Component\Validator\Test; | ||
/** | ||
* @internal | ||
*/ | ||
trait TypeTestCaseSetupTeardownTrait | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->dispatcher = $this->getMockBuilder(\'Symfony\Component\EventDispatcher\EventDispatcherInterface\')->getMock(); | ||
$this->builder = new FormBuilder(\'\', null, $this->dispatcher, $this->factory); | ||
} | ||
protected function tearDown(): void | ||
{ | ||
if (\in_array(ValidatorExtensionTrait::class, class_uses($this))) { | ||
$this->validator = null; | ||
} | ||
} | ||
} | ||
'); | ||
} else { | ||
/** | ||
* @internal | ||
*/ | ||
trait TypeTestCaseSetupTeardownTrait | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); | ||
$this->builder = new FormBuilder('', null, $this->dispatcher, $this->factory); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
if (\in_array(ValidatorExtensionTrait::class, class_uses($this))) { | ||
$this->validator = null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/Symfony/Component/Validator/Test/ConstraintValidatorTestCaseSetupTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?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\Validator\Test; | ||
|
||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Validator\Constraints\NotNull; | ||
|
||
// Auto-adapt to PHPUnit 8 that added a `void` return-type to the setUp method | ||
|
||
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) { | ||
eval(' | ||
namespace Symfony\Component\Validator\Test; | ||
/** | ||
* @internal | ||
*/ | ||
trait ConstraintValidatorTestCaseSetupTrait | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->group = \'MyGroup\'; | ||
$this->metadata = null; | ||
$this->object = null; | ||
$this->value = \'InvalidValue\'; | ||
$this->root = \'root\'; | ||
$this->propertyPath = \'property.path\'; | ||
$this->constraint = new NotNull(); | ||
$this->context = $this->createContext(); | ||
$this->validator = $this->createValidator(); | ||
$this->validator->initialize($this->context); | ||
\Locale::setDefault(\'en\'); | ||
$this->setDefaultTimezone(\'UTC\'); | ||
} | ||
} | ||
'); | ||
} else { | ||
/** | ||
* @internal | ||
*/ | ||
trait ConstraintValidatorTestCaseSetupTrait | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->group = 'MyGroup'; | ||
$this->metadata = null; | ||
$this->object = null; | ||
$this->value = 'InvalidValue'; | ||
$this->root = 'root'; | ||
$this->propertyPath = 'property.path'; | ||
|
||
// Initialize the context with some constraint so that we can | ||
// successfully build a violation. | ||
$this->constraint = new NotNull(); | ||
|
||
$this->context = $this->createContext(); | ||
$this->validator = $this->createValidator(); | ||
$this->validator->initialize($this->context); | ||
|
||
\Locale::setDefault('en'); | ||
|
||
$this->setDefaultTimezone('UTC'); | ||
} | ||
} | ||
} |