Skip to content

Commit faa4840

Browse files
committed
Merge branch '8.0' into 8.1
* 8.0: Use PHPUnit attribute in another data provider Replace PHPDoc dataProvider with attribute syntax
2 parents 211b930 + e70da9d commit faa4840

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

best_practices.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,12 @@ checks that all application URLs load successfully::
403403
// tests/ApplicationAvailabilityFunctionalTest.php
404404
namespace App\Tests;
405405

406+
use PHPUnit\Framework\Attributes\DataProvider;
406407
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
407-
408+
408409
class ApplicationAvailabilityFunctionalTest extends WebTestCase
409410
{
410-
/**
411-
* @dataProvider urlProvider
412-
*/
411+
#[DataProvider('urlProvider')]
413412
public function testPageIsSuccessful($url): void
414413
{
415414
$client = self::createClient();
@@ -418,7 +417,7 @@ checks that all application URLs load successfully::
418417
$this->assertResponseIsSuccessful();
419418
}
420419

421-
public function urlProvider(): \Generator
420+
public static function urlProvider(): \Generator
422421
{
423422
yield ['/'];
424423
yield ['/posts'];

validation/custom_constraint.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ class to simplify writing unit tests for your custom constraints::
563563

564564
use App\Validator\ContainsAlphanumeric;
565565
use App\Validator\ContainsAlphanumericValidator;
566+
use PHPUnit\Framework\Attributes\DataProvider;
566567
use Symfony\Component\Validator\ConstraintValidatorInterface;
567568
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
568569

@@ -580,9 +581,7 @@ class to simplify writing unit tests for your custom constraints::
580581
$this->assertNoViolation();
581582
}
582583

583-
/**
584-
* @dataProvider provideInvalidConstraints
585-
*/
584+
#[DataProvider('provideInvalidConstraints')]
586585
public function testTrueIsInvalid(ContainsAlphanumeric $constraint): void
587586
{
588587
$this->validator->validate('...', $constraint);
@@ -592,7 +591,7 @@ class to simplify writing unit tests for your custom constraints::
592591
->assertRaised();
593592
}
594593

595-
public function provideInvalidConstraints(): \Generator
594+
public static function provideInvalidConstraints(): \Generator
596595
{
597596
yield [new ContainsAlphanumeric(message: 'myMessage')];
598597
// ...

0 commit comments

Comments
 (0)