Skip to content

Commit e103270

Browse files
More tests
1 parent c040501 commit e103270

8 files changed

Lines changed: 200 additions & 2 deletions

File tree

.php-cs-fixer.dist.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
->notName('TestAttributeOnHookMethodsTest.php')
2525
// InvokableConstraintAndPipeOperatorTest.php uses PHP 8.5 syntax
2626
->notName('InvokableConstraintAndPipeOperatorTest.php')
27+
// NoReturnTypeTest.php must have a method without a return type declaration
28+
->notPath('repeat/_files/NoReturnTypeTest.php')
2729
// FirstPartyClass.php and PhpDeprecationTest.php must not use declare(strict_types=1);
2830
->notPath('error-handler/_files/php-deprecation/src/FirstPartyClass.php')
2931
->notPath('error-handler/_files/php-deprecation/tests/PhpDeprecationTest.php')

phpunit.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<directory suffix=".phpt">tests/end-to-end/migration</directory>
3636
<directory suffix=".phpt">tests/end-to-end/phpt</directory>
3737
<directory suffix=".phpt">tests/end-to-end/regression</directory>
38+
<directory suffix=".phpt">tests/end-to-end/repeat</directory>
3839
<directory suffix=".phpt">tests/end-to-end/test-doubles/generator</directory>
3940
<directory suffix=".phpt">tests/end-to-end/test-doubles/runtime</directory>
4041
<directory suffix=".phpt">tests/end-to-end/testdox</directory>
@@ -44,6 +45,7 @@
4445
<exclude>tests/end-to-end/groups-from-configuration/_files</exclude>
4546
<exclude>tests/end-to-end/logging/_files</exclude>
4647
<exclude>tests/end-to-end/migration/_files</exclude>
48+
<exclude>tests/end-to-end/repeat/_files</exclude>
4749
<exclude>tests/end-to-end/self-direct-indirect/_files</exclude>
4850
<exclude>tests/end-to-end/testdox/_files</exclude>
4951
</testsuite>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Metadata\Attribute;
11+
12+
use PHPUnit\Framework\Attributes\Repeat;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class RepeatTest extends TestCase
16+
{
17+
#[Repeat(5, failureThreshold: 2)]
18+
public function testOne(): void
19+
{
20+
}
21+
}

tests/end-to-end/repeat/_files/NoReturnTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
final class NoReturnTypeTest extends TestCase
1515
{
1616
/** @phpstan-ignore missingType.return */
17-
public function testWithoutReturnType(): void
17+
public function testWithoutReturnType()
1818
{
1919
$this->assertTrue(true);
2020
}

tests/end-to-end/repeat/repeat-skips-no-return-type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
--repeat does not repeat test without return type declaration
2+
--repeat skips test without return type declaration
33
--FILE--
44
<?php declare(strict_types=1);
55
$_SERVER['argv'][] = '--no-configuration';

tests/unit/Metadata/MetadataCollectionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#[UsesClass(PostCondition::class)]
4242
#[UsesClass(PreCondition::class)]
4343
#[UsesClass(PreserveGlobalState::class)]
44+
#[UsesClass(Repeat::class)]
4445
#[UsesClass(RequiresFunction::class)]
4546
#[UsesClass(RequiresMethod::class)]
4647
#[UsesClass(RequiresOperatingSystem::class)]
@@ -571,6 +572,14 @@ public function test_Can_be_filtered_for_UsesMethod(): void
571572
$this->assertTrue($collection->asArray()[0]->isUsesMethod());
572573
}
573574

575+
public function test_Can_be_filtered_for_Repeat(): void
576+
{
577+
$collection = $this->collectionWithOneOfEach()->isRepeat();
578+
579+
$this->assertCount(1, $collection);
580+
$this->assertTrue($collection->asArray()[0]->isRepeat());
581+
}
582+
574583
public function test_Can_be_filtered_for_WithoutErrorHandler(): void
575584
{
576585
$collection = $this->collectionWithOneOfEach()->isWithoutErrorHandler();
@@ -650,6 +659,7 @@ private function collectionWithOneOfEach(): MetadataCollection
650659
Metadata::usesTrait(''),
651660
Metadata::usesFunction(''),
652661
Metadata::usesMethod('', ''),
662+
Metadata::repeat(3, 1),
653663
Metadata::withEnvironmentVariableOnClass('foo', 'bar'),
654664
Metadata::withoutErrorHandler(),
655665
],

tests/unit/Metadata/MetadataTest.php

Lines changed: 145 additions & 0 deletions
Large diffs are not rendered by default.

tests/unit/Metadata/Parser/AttributeParserTestCase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Metadata\DependsOnClass;
1616
use PHPUnit\Metadata\DependsOnMethod;
1717
use PHPUnit\Metadata\InvalidAttributeException;
18+
use PHPUnit\Metadata\Repeat;
1819
use PHPUnit\Metadata\RequiresEnvironmentVariable;
1920
use PHPUnit\Metadata\RequiresPhp;
2021
use PHPUnit\Metadata\RequiresPhpExtension;
@@ -52,6 +53,7 @@
5253
use PHPUnit\TestFixture\Metadata\Attribute\PhpunitAttributeThatDoesNotExistTest;
5354
use PHPUnit\TestFixture\Metadata\Attribute\PreserveGlobalStateTest;
5455
use PHPUnit\TestFixture\Metadata\Attribute\ProcessIsolationTest;
56+
use PHPUnit\TestFixture\Metadata\Attribute\RepeatTest;
5557
use PHPUnit\TestFixture\Metadata\Attribute\RequiresEnvironmentVariableTest;
5658
use PHPUnit\TestFixture\Metadata\Attribute\RequiresFunctionTest;
5759
use PHPUnit\TestFixture\Metadata\Attribute\RequiresMethodTest;
@@ -1201,6 +1203,22 @@ public function test_parses_Ticket_attribute_on_method(): void
12011203
$this->assertSame('another-ticket', $metadata->asArray()[1]->groupName());
12021204
}
12031205

1206+
#[TestDox('Parses #[Repeat] attribute on method')]
1207+
public function test_parses_Repeat_attribute_on_method(): void
1208+
{
1209+
$metadata = $this->parser()->forMethod(RepeatTest::class, 'testOne')->isRepeat();
1210+
1211+
$this->assertCount(1, $metadata);
1212+
$this->assertTrue($metadata->asArray()[0]->isRepeat());
1213+
1214+
$repeat = $metadata->asArray()[0];
1215+
1216+
assert($repeat instanceof Repeat);
1217+
1218+
$this->assertSame(5, $repeat->times());
1219+
$this->assertSame(2, $repeat->failureThreshold());
1220+
}
1221+
12041222
#[TestDox('Parses #[WithoutErrorHandler] attribute on method')]
12051223
public function test_parses_WithoutErrorHandler_attribute_on_method(): void
12061224
{

0 commit comments

Comments
 (0)