diff --git a/best_practices.rst b/best_practices.rst index 2c393cae9c6..6ec1cf60cd4 100644 --- a/best_practices.rst +++ b/best_practices.rst @@ -407,13 +407,12 @@ checks that all application URLs load successfully:: // tests/ApplicationAvailabilityFunctionalTest.php namespace App\Tests; + use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class ApplicationAvailabilityFunctionalTest extends WebTestCase { - /** - * @dataProvider urlProvider - */ + #[DataProvider('urlProvider')] public function testPageIsSuccessful($url): void { $client = self::createClient(); @@ -433,6 +432,11 @@ checks that all application URLs load successfully:: } } +.. note:: + + The ``#[DataProvider]`` attribute is available in PHPUnit 10 and later versions. + In previous versions, use the ``@dataProvider`` PHPDoc annotation. + Add this test while creating your application because it requires little effort and checks that none of your pages returns an error. Later, you'll add more specific tests for each page. diff --git a/validation/custom_constraint.rst b/validation/custom_constraint.rst index 435b976d1d3..22f6ad87372 100644 --- a/validation/custom_constraint.rst +++ b/validation/custom_constraint.rst @@ -513,6 +513,7 @@ class to simplify writing unit tests for your custom constraints:: use App\Validator\ContainsAlphanumeric; use App\Validator\ContainsAlphanumericValidator; + use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; @@ -530,9 +531,7 @@ class to simplify writing unit tests for your custom constraints:: $this->assertNoViolation(); } - /** - * @dataProvider provideInvalidConstraints - */ + #[DataProvider('provideInvalidConstraints')] public function testTrueIsInvalid(ContainsAlphanumeric $constraint): void { $this->validator->validate('...', $constraint);