Skip to content

Commit

Permalink
Merge branch '10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 8, 2023
2 parents 9079530 + 513783c commit 34d1764
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/Metadata/Api/Groups.php
Expand Up @@ -56,31 +56,31 @@ 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;
}

if ($metadata->isCovers()) {
assert($metadata instanceof Covers);

$groups[] = '__phpunit_covers_' . self::canonicalizeName($metadata->target());
$groups[] = '__phpunit_covers_' . $this->canonicalizeName($metadata->target());

continue;
}

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;
}

if ($metadata->isUses()) {
assert($metadata instanceof Uses);

$groups[] = '__phpunit_uses_' . self::canonicalizeName($metadata->target());
$groups[] = '__phpunit_uses_' . $this->canonicalizeName($metadata->target());
}
}

Expand Down Expand Up @@ -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, '\\'));
}
Expand Down
21 changes: 21 additions & 0 deletions tests/_files/LargeGroupAttributesTest.php
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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
{
}
}
21 changes: 21 additions & 0 deletions tests/_files/MediumGroupAttributesTest.php
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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
{
}
}
19 changes: 19 additions & 0 deletions tests/_files/NoGroupsMetadataTest.php
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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
{
}
}
38 changes: 38 additions & 0 deletions tests/_files/SmallGroupAnnotationsTest.php
@@ -0,0 +1,38 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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
{
}
}
31 changes: 31 additions & 0 deletions tests/_files/SmallGroupAttributesTest.php
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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
{
}
}
104 changes: 83 additions & 21 deletions tests/unit/Metadata/Api/GroupsTest.php
Expand Up @@ -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]
Expand All @@ -25,44 +27,104 @@ public static function provider(): array
{
return [
[
AssertionExampleTest::class,
'testOne',
[
'default',
],
NoGroupsMetadataTest::class,
'testOne',
false,
],

[
BankAccountTest::class,
'testBalanceIsInitiallyZero',
[
'balanceIsInitiallyZero',
'specification',
'1234',
'__phpunit_covers_bankaccount::getbalance',
'the-group',
'the-ticket',
'small',
'another-group',
'another-ticket',
],
SmallGroupAttributesTest::class,
'testOne',
false,
],

[
NumericGroupAnnotationTest::class,
'testTicketAnnotationSupportsNumericValue',
[
't123456',
'3502',
'the-group',
'the-ticket',
'small',
'another-group',
'another-ticket',
],
SmallGroupAnnotationsTest::class,
'testOne',
false,
],

[
NumericGroupAnnotationTest::class,
'testGroupAnnotationSupportsNumericValue',
[
't123456',
'3502',
'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,
],

[
[
'medium',
],
MediumGroupAttributesTest::class,
'testOne',
false,
],

[
[
'large',
],
LargeGroupAttributesTest::class,
'testOne',
false,
],
];
}

#[DataProvider('provider')]
public function testGroupsAreAssigned(string $class, string $method, array $groups): 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($class, $method));
$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());
}
}

0 comments on commit 34d1764

Please sign in to comment.