Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 8, 2023
1 parent 26d570f commit 513783c
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 20 deletions.
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
{
}
}
99 changes: 79 additions & 20 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 @@ -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());
}
}

0 comments on commit 513783c

Please sign in to comment.