From 528c92fcbdc0d7a3f0d4e573eb139aea72ede773 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 8 Mar 2023 08:26:16 +0100 Subject: [PATCH 1/4] Add whitespace to improve readability --- tests/unit/Metadata/Api/GroupsTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/Metadata/Api/GroupsTest.php b/tests/unit/Metadata/Api/GroupsTest.php index d35993001e5..05b17eeab08 100644 --- a/tests/unit/Metadata/Api/GroupsTest.php +++ b/tests/unit/Metadata/Api/GroupsTest.php @@ -31,6 +31,7 @@ public static function provider(): array 'default', ], ], + [ BankAccountTest::class, 'testBalanceIsInitiallyZero', @@ -41,6 +42,7 @@ public static function provider(): array '__phpunit_covers_bankaccount::getbalance', ], ], + [ NumericGroupAnnotationTest::class, 'testTicketAnnotationSupportsNumericValue', @@ -49,6 +51,7 @@ public static function provider(): array '3502', ], ], + [ NumericGroupAnnotationTest::class, 'testGroupAnnotationSupportsNumericValue', From 5356eb5edf751fcedd9e9d5a449c02f0ca80057a Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 8 Mar 2023 08:27:48 +0100 Subject: [PATCH 2/4] Improve data provider structure --- tests/unit/Metadata/Api/GroupsTest.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/unit/Metadata/Api/GroupsTest.php b/tests/unit/Metadata/Api/GroupsTest.php index 05b17eeab08..4481dfd6528 100644 --- a/tests/unit/Metadata/Api/GroupsTest.php +++ b/tests/unit/Metadata/Api/GroupsTest.php @@ -25,47 +25,47 @@ public static function provider(): array { return [ [ - AssertionExampleTest::class, - 'testOne', [ 'default', ], + AssertionExampleTest::class, + 'testOne', ], [ - BankAccountTest::class, - 'testBalanceIsInitiallyZero', [ 'balanceIsInitiallyZero', 'specification', '1234', '__phpunit_covers_bankaccount::getbalance', ], + BankAccountTest::class, + 'testBalanceIsInitiallyZero', ], [ - NumericGroupAnnotationTest::class, - 'testTicketAnnotationSupportsNumericValue', [ 't123456', '3502', ], + NumericGroupAnnotationTest::class, + 'testTicketAnnotationSupportsNumericValue', ], [ - NumericGroupAnnotationTest::class, - 'testGroupAnnotationSupportsNumericValue', [ 't123456', '3502', ], + NumericGroupAnnotationTest::class, + 'testGroupAnnotationSupportsNumericValue', ], ]; } #[DataProvider('provider')] - public function testGroupsAreAssigned(string $class, string $method, array $groups): void + public function testGroupsAreAssigned(array $groups, string $className, string $methodName): void { - $this->assertSame($groups, (new Groups)->groups($class, $method)); + $this->assertSame($groups, (new Groups)->groups($className, $methodName)); } } From 26d570f7e23fe4253b35398e4f557927c9e7e191 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 8 Mar 2023 08:53:38 +0100 Subject: [PATCH 3/4] This does not need to be static --- src/Metadata/Api/Groups.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Metadata/Api/Groups.php b/src/Metadata/Api/Groups.php index c2abc217174..2403609822c 100644 --- a/src/Metadata/Api/Groups.php +++ b/src/Metadata/Api/Groups.php @@ -56,7 +56,7 @@ public function groups(string $className, string $methodName, bool $includeVirtu if ($metadata->isCoversClass() || $metadata->isCoversFunction()) { assert($metadata instanceof CoversClass || $metadata instanceof CoversFunction); - $groups[] = '__phpunit_covers_' . self::canonicalizeName($metadata->asStringForCodeUnitMapper()); + $groups[] = '__phpunit_covers_' . $this->canonicalizeName($metadata->asStringForCodeUnitMapper()); continue; } @@ -64,7 +64,7 @@ public function groups(string $className, string $methodName, bool $includeVirtu if ($metadata->isCovers()) { assert($metadata instanceof Covers); - $groups[] = '__phpunit_covers_' . self::canonicalizeName($metadata->target()); + $groups[] = '__phpunit_covers_' . $this->canonicalizeName($metadata->target()); continue; } @@ -72,7 +72,7 @@ public function groups(string $className, string $methodName, bool $includeVirtu if ($metadata->isUsesClass() || $metadata->isUsesFunction()) { assert($metadata instanceof UsesClass || $metadata instanceof UsesFunction); - $groups[] = '__phpunit_uses_' . self::canonicalizeName($metadata->asStringForCodeUnitMapper()); + $groups[] = '__phpunit_uses_' . $this->canonicalizeName($metadata->asStringForCodeUnitMapper()); continue; } @@ -80,7 +80,7 @@ public function groups(string $className, string $methodName, bool $includeVirtu if ($metadata->isUses()) { assert($metadata instanceof Uses); - $groups[] = '__phpunit_uses_' . self::canonicalizeName($metadata->target()); + $groups[] = '__phpunit_uses_' . $this->canonicalizeName($metadata->target()); } } @@ -109,7 +109,7 @@ public function size(string $className, string $methodName): TestSize return TestSize::unknown(); } - private static function canonicalizeName(string $name): string + private function canonicalizeName(string $name): string { return strtolower(trim($name, '\\')); } From 513783ccb6eea094be514c4e3b0ebe23bd2bee27 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 8 Mar 2023 08:53:47 +0100 Subject: [PATCH 4/4] Add tests --- tests/_files/LargeGroupAttributesTest.php | 21 +++++ tests/_files/MediumGroupAttributesTest.php | 21 +++++ tests/_files/NoGroupsMetadataTest.php | 19 +++++ tests/_files/SmallGroupAnnotationsTest.php | 38 +++++++++ tests/_files/SmallGroupAttributesTest.php | 31 +++++++ tests/unit/Metadata/Api/GroupsTest.php | 99 +++++++++++++++++----- 6 files changed, 209 insertions(+), 20 deletions(-) create mode 100644 tests/_files/LargeGroupAttributesTest.php create mode 100644 tests/_files/MediumGroupAttributesTest.php create mode 100644 tests/_files/NoGroupsMetadataTest.php create mode 100644 tests/_files/SmallGroupAnnotationsTest.php create mode 100644 tests/_files/SmallGroupAttributesTest.php diff --git a/tests/_files/LargeGroupAttributesTest.php b/tests/_files/LargeGroupAttributesTest.php new file mode 100644 index 00000000000..f8f2a316270 --- /dev/null +++ b/tests/_files/LargeGroupAttributesTest.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture; + +use PHPUnit\Framework\Attributes\Large; +use PHPUnit\Framework\TestCase; + +#[Large] +final class LargeGroupAttributesTest extends TestCase +{ + public function testOne(): void + { + } +} diff --git a/tests/_files/MediumGroupAttributesTest.php b/tests/_files/MediumGroupAttributesTest.php new file mode 100644 index 00000000000..49cdd19a274 --- /dev/null +++ b/tests/_files/MediumGroupAttributesTest.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture; + +use PHPUnit\Framework\Attributes\Medium; +use PHPUnit\Framework\TestCase; + +#[Medium] +final class MediumGroupAttributesTest extends TestCase +{ + public function testOne(): void + { + } +} diff --git a/tests/_files/NoGroupsMetadataTest.php b/tests/_files/NoGroupsMetadataTest.php new file mode 100644 index 00000000000..d4b4d44d65e --- /dev/null +++ b/tests/_files/NoGroupsMetadataTest.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture; + +use PHPUnit\Framework\TestCase; + +final class NoGroupsMetadataTest extends TestCase +{ + public function testOne(): void + { + } +} diff --git a/tests/_files/SmallGroupAnnotationsTest.php b/tests/_files/SmallGroupAnnotationsTest.php new file mode 100644 index 00000000000..438d2d7f65b --- /dev/null +++ b/tests/_files/SmallGroupAnnotationsTest.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture; + +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\Ticket; +use PHPUnit\Framework\TestCase; + +/** + * @covers \PHPUnit\TestFixture\CoveredClass + * + * @uses \PHPUnit\TestFixture\CoveredClass + * + * @group the-group + * + * @ticket the-ticket + * + * @small + */ +final class SmallGroupAnnotationsTest extends TestCase +{ + /** + * @group another-group + * + * @ticket another-ticket + */ + public function testOne(): void + { + } +} diff --git a/tests/_files/SmallGroupAttributesTest.php b/tests/_files/SmallGroupAttributesTest.php new file mode 100644 index 00000000000..99caa59d978 --- /dev/null +++ b/tests/_files/SmallGroupAttributesTest.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture; + +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\Ticket; +use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\TestCase; + +#[CoversClass(CoveredClass::class)] +#[UsesClass(CoveredClass::class)] +#[Group('the-group')] +#[Ticket('the-ticket')] +#[Small] +final class SmallGroupAttributesTest extends TestCase +{ + #[Group('another-group')] + #[Ticket('another-ticket')] + public function testOne(): void + { + } +} diff --git a/tests/unit/Metadata/Api/GroupsTest.php b/tests/unit/Metadata/Api/GroupsTest.php index 4481dfd6528..669bdb0e00d 100644 --- a/tests/unit/Metadata/Api/GroupsTest.php +++ b/tests/unit/Metadata/Api/GroupsTest.php @@ -13,9 +13,11 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Small; use PHPUnit\Framework\TestCase; -use PHPUnit\TestFixture\AssertionExampleTest; -use PHPUnit\TestFixture\BankAccountTest; -use PHPUnit\TestFixture\NumericGroupAnnotationTest; +use PHPUnit\TestFixture\LargeGroupAttributesTest; +use PHPUnit\TestFixture\MediumGroupAttributesTest; +use PHPUnit\TestFixture\NoGroupsMetadataTest; +use PHPUnit\TestFixture\SmallGroupAnnotationsTest; +use PHPUnit\TestFixture\SmallGroupAttributesTest; #[CoversClass(Groups::class)] #[Small] @@ -28,44 +30,101 @@ public static function provider(): array [ 'default', ], - AssertionExampleTest::class, + NoGroupsMetadataTest::class, 'testOne', + false, ], [ [ - 'balanceIsInitiallyZero', - 'specification', - '1234', - '__phpunit_covers_bankaccount::getbalance', + 'the-group', + 'the-ticket', + 'small', + 'another-group', + 'another-ticket', ], - BankAccountTest::class, - 'testBalanceIsInitiallyZero', + SmallGroupAttributesTest::class, + 'testOne', + false, + ], + + [ + [ + 'the-group', + 'the-ticket', + 'small', + 'another-group', + 'another-ticket', + ], + SmallGroupAnnotationsTest::class, + 'testOne', + false, + ], + + [ + [ + 'the-group', + 'the-ticket', + 'small', + 'another-group', + 'another-ticket', + '__phpunit_covers_phpunit\testfixture\coveredclass', + '__phpunit_uses_phpunit\testfixture\coveredclass', + ], + SmallGroupAttributesTest::class, + 'testOne', + true, + ], + + [ + [ + 'the-group', + 'the-ticket', + 'small', + 'another-group', + 'another-ticket', + '__phpunit_covers_phpunit\testfixture\coveredclass', + '__phpunit_uses_phpunit\testfixture\coveredclass', + ], + SmallGroupAnnotationsTest::class, + 'testOne', + true, ], [ [ - 't123456', - '3502', + 'medium', ], - NumericGroupAnnotationTest::class, - 'testTicketAnnotationSupportsNumericValue', + MediumGroupAttributesTest::class, + 'testOne', + false, ], [ [ - 't123456', - '3502', + 'large', ], - NumericGroupAnnotationTest::class, - 'testGroupAnnotationSupportsNumericValue', + LargeGroupAttributesTest::class, + 'testOne', + false, ], ]; } #[DataProvider('provider')] - public function testGroupsAreAssigned(array $groups, string $className, string $methodName): void + public function testAssignsGroups(array $expected, string $className, string $methodName, bool $includeVirtual): void + { + $this->assertSame( + $expected, + (new Groups)->groups($className, $methodName, $includeVirtual) + ); + } + + public function testAssignsSize(): void { - $this->assertSame($groups, (new Groups)->groups($className, $methodName)); + $this->assertTrue((new Groups)->size(SmallGroupAttributesTest::class, 'testOne')->isSmall()); + $this->assertTrue((new Groups)->size(MediumGroupAttributesTest::class, 'testOne')->isMedium()); + $this->assertTrue((new Groups)->size(LargeGroupAttributesTest::class, 'testOne')->isLarge()); + $this->assertTrue((new Groups)->size(NoGroupsMetadataTest::class, 'testOne')->isUnknown()); } }