Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions src/Event/Value/Test/Phpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
*/
final readonly class Phpt extends Test
{
/**
* @var positive-int
*/
private int $repeatAttemptNumber;

/**
* @param non-empty-string $file
* @param positive-int $repeatAttemptNumber
*/
public function __construct(string $file, int $repeatAttemptNumber = 1)
{
parent::__construct($file);

$this->repeatAttemptNumber = $repeatAttemptNumber;
}

public function isPhpt(): true
{
return true;
Expand All @@ -26,14 +42,18 @@ public function isPhpt(): true
*/
public function id(): string
{
return $this->file();
return $this->name();
}

/**
* @return non-empty-string
*/
public function name(): string
{
return $this->file();
if ($this->repeatAttemptNumber === 1) {
return $this->file();
}

return $this->file() . " (repeat attempt #{$this->repeatAttemptNumber})";
}
}
37 changes: 28 additions & 9 deletions src/Event/Value/Test/TestMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,29 @@
private MetadataCollection $metadata;
private TestDataCollection $testData;

/**
* @var positive-int
*/
private int $repeatAttemptNumber;

/**
* @param class-string $className
* @param non-empty-string $methodName
* @param non-empty-string $file
* @param non-negative-int $line
* @param positive-int $repeatAttemptNumber
*/
public function __construct(string $className, string $methodName, string $file, int $line, TestDox $testDox, MetadataCollection $metadata, TestDataCollection $testData)
public function __construct(string $className, string $methodName, string $file, int $line, TestDox $testDox, MetadataCollection $metadata, TestDataCollection $testData, int $repeatAttemptNumber = 1)
{
parent::__construct($file);

$this->className = $className;
$this->methodName = $methodName;
$this->line = $line;
$this->testDox = $testDox;
$this->metadata = $metadata;
$this->testData = $testData;
$this->className = $className;
$this->methodName = $methodName;
$this->line = $line;
$this->testDox = $testDox;
$this->metadata = $metadata;
$this->testData = $testData;
$this->repeatAttemptNumber = $repeatAttemptNumber;
}

/**
Expand Down Expand Up @@ -129,7 +136,13 @@ public function nameWithClass(): string
public function name(): string
{
if (!$this->testData->hasDataFromDataProvider()) {
return $this->methodName;
$name = $this->methodName;

if ($this->repeatAttemptNumber !== 1) {
$name .= " (repeat attempt #{$this->repeatAttemptNumber})";
}
Comment on lines +141 to +143
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to not change those names for the first attempt, because I don't know if the change in the name should be considered as a BC break


return $name;
}

$dataSetName = $this->testData->dataFromDataProvider()->dataSetName();
Expand All @@ -146,6 +159,12 @@ public function name(): string
);
}

return $this->methodName . $dataSetName;
$name = $this->methodName . $dataSetName;

if ($this->repeatAttemptNumber !== 1) {
$name .= " (repeat attempt #{$this->repeatAttemptNumber})";
}

return $name;
}
}
1 change: 1 addition & 0 deletions src/Event/Value/Test/TestMethodBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static function fromTestCase(TestCase $testCase, bool $useTestCaseForTest
$testDox,
MetadataRegistry::parser()->forClassAndMethod($testCase::class, $methodName),
self::dataFor($testCase),
$testCase->repeatAttemptNumber(),
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Event/Value/TestSuite/TestSuiteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPUnit\Event\Code\TestCollection;
use PHPUnit\Event\RuntimeException;
use PHPUnit\Framework\DataProviderTestSuite;
use PHPUnit\Framework\RepeatTestSuite;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite as FrameworkTestSuite;
use PHPUnit\Runner\Phpt\TestCase as PhptTestCase;
Expand Down Expand Up @@ -107,7 +108,9 @@ private static function process(FrameworkTestSuite $testSuite, array &$tests): v
continue;
}

if ($test instanceof TestCase || $test instanceof PhptTestCase) {
if ($test instanceof TestCase ||
$test instanceof PhptTestCase ||
$test instanceof RepeatTestSuite) {
$tests[] = $test->valueObjectForEvents();
}
}
Expand Down
62 changes: 62 additions & 0 deletions src/Framework/AbstractRepeatTestSuite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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\Framework;

use function count;
use PHPUnit\Event;
use PHPUnit\Runner\Phpt\TestCase as PhptTestCase;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @template T of TestCase|PhptTestCase
*/
abstract readonly class AbstractRepeatTestSuite implements Reorderable, Test
{
/**
* @var non-empty-list<T>
*/
protected array $tests;

/**
* @param non-empty-list<T> $tests
*/
public function __construct(array $tests)
{
$this->tests = $tests;
}

final public function count(): int
{
return count($this->tests);
}

final public function sortId(): string
{
return $this->tests[0]->sortId();
}

final public function provides(): array
{
return $this->tests[0]->provides();
}

final public function requires(): array
{
return $this->tests[0]->requires();
}

final public function valueObjectForEvents(): Event\Code\Phpt|Event\Code\TestMethod
{
return $this->tests[0]->valueObjectForEvents();
}
}
66 changes: 66 additions & 0 deletions src/Framework/RepeatTestSuite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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\Framework;

use PHPUnit\Metadata\Api\ProvidedData;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @extends AbstractRepeatTestSuite<TestCase>
*/
final readonly class RepeatTestSuite extends AbstractRepeatTestSuite
{
public function run(): void
{
$defectOccurred = false;

foreach ($this->tests as $test) {
if ($defectOccurred) {
$test->markSkippedForErrorInPreviousRepetition();

continue;
}

$test->run();

if ($test->status()->isFailure() || $test->status()->isError() || $test->status()->isSkipped()) {
$defectOccurred = true;
}
}
}

public function name(): string
{
return $this->tests[0]::class . '::' . $this->tests[0]->nameWithDataSet();
}

/**
* @param array<ProvidedData> $data
*/
public function setData(int|string $dataName, array $data): void
{
foreach ($this->tests as $test) {
$test->setData($dataName, $data);
}
}

/**
* @param list<ExecutionOrderDependency> $dependencies
*/
public function setDependencies(array $dependencies): void
{
foreach ($this->tests as $test) {
$test->setDependencies($dependencies);
}
}
}
Loading