From 881136ad8c1c18ec93c5d7672843778bccc00eba Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 19 Sep 2024 13:20:53 +0200 Subject: [PATCH 1/3] =?UTF-8?q?[Testing]=C2=A0Update=20tests=20to=20use=20?= =?UTF-8?q?attributes=20for=20data=20providers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best_practices.rst | 10 +++++++--- validation/custom_constraint.rst | 5 ++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/best_practices.rst b/best_practices.rst index 2c393cae9c6..ae373d0b58a 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); From 624e07820e4d33ce59c0fedbc2cabec0c2d9b749 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 20 Sep 2024 17:55:35 +0200 Subject: [PATCH 2/3] - --- best_practices.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices.rst b/best_practices.rst index ae373d0b58a..50a43e336f0 100644 --- a/best_practices.rst +++ b/best_practices.rst @@ -435,7 +435,7 @@ 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. + 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 From d04ebc7f11bf38a6fb5fb5847db8ae271e4f6c31 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 23 Sep 2024 14:47:12 +0200 Subject: [PATCH 3/3] - --- best_practices.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices.rst b/best_practices.rst index 50a43e336f0..6ec1cf60cd4 100644 --- a/best_practices.rst +++ b/best_practices.rst @@ -435,7 +435,7 @@ 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. + 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