Skip to content

Commit c040501

Browse files
More tests
1 parent 102aef2 commit c040501

19 files changed

Lines changed: 671 additions & 0 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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\Repeat;
11+
12+
use PHPUnit\Framework\Attributes\DataProvider;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class DataProviderTest extends TestCase
16+
{
17+
public static function provider(): array
18+
{
19+
return [
20+
'one' => [1],
21+
'two' => [2],
22+
];
23+
}
24+
25+
#[DataProvider('provider')]
26+
public function testWithDataProvider(int $value): void
27+
{
28+
$this->assertGreaterThan(0, $value);
29+
}
30+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Repeat;
11+
12+
use PHPUnit\Framework\Attributes\Depends;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class DependsTest extends TestCase
16+
{
17+
public function testOne(): void
18+
{
19+
$this->assertTrue(true);
20+
}
21+
22+
#[Depends('testOne')]
23+
public function testTwo(): void
24+
{
25+
$this->assertTrue(true);
26+
}
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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\Repeat;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class NoReturnTypeTest extends TestCase
15+
{
16+
/** @phpstan-ignore missingType.return */
17+
public function testWithoutReturnType(): void
18+
{
19+
$this->assertTrue(true);
20+
}
21+
22+
public function testWithVoidReturn(): void
23+
{
24+
$this->assertTrue(true);
25+
}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Repeat;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class NonVoidReturnTest extends TestCase
15+
{
16+
public function testWithReturnValue(): int
17+
{
18+
$this->assertTrue(true);
19+
20+
return 1;
21+
}
22+
23+
public function testWithVoidReturn(): void
24+
{
25+
$this->assertTrue(true);
26+
}
27+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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\Repeat;
11+
12+
use PHPUnit\Framework\Attributes\Repeat;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class RepeatAttributeOverrideTest extends TestCase
16+
{
17+
#[Repeat(2)]
18+
public function testAttributeOverridesCliRepeat(): void
19+
{
20+
$this->assertTrue(true);
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Repeat;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class UnionReturnTypeTest extends TestCase
15+
{
16+
public function testWithUnionReturnType(): int|string
17+
{
18+
$this->assertTrue(true);
19+
20+
return 1;
21+
}
22+
23+
public function testWithVoidReturn(): void
24+
{
25+
$this->assertTrue(true);
26+
}
27+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
#[Repeat] attribute takes precedence over --repeat CLI option
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--no-configuration';
6+
$_SERVER['argv'][] = '--do-not-cache-result';
7+
$_SERVER['argv'][] = '--repeat';
8+
$_SERVER['argv'][] = '5';
9+
$_SERVER['argv'][] = '--debug';
10+
$_SERVER['argv'][] = __DIR__ . '/_files/RepeatAttributeOverrideTest.php';
11+
12+
require __DIR__ . '/../../bootstrap.php';
13+
14+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
15+
--EXPECTF--
16+
PHPUnit Started (PHPUnit %s using %s)
17+
Test Runner Configured
18+
Event Facade Sealed
19+
Test Suite Loaded (2 tests)
20+
Test Runner Started
21+
Test Suite Sorted
22+
Test Runner Execution Started (2 tests)
23+
Test Suite Started (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest, 2 tests)
24+
Test Preparation Started (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest::testAttributeOverridesCliRepeat (repetition 1 of 2))
25+
Test Prepared (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest::testAttributeOverridesCliRepeat (repetition 1 of 2))
26+
Test Passed (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest::testAttributeOverridesCliRepeat (repetition 1 of 2))
27+
Test Finished (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest::testAttributeOverridesCliRepeat (repetition 1 of 2))
28+
Test Preparation Started (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest::testAttributeOverridesCliRepeat (repetition 2 of 2))
29+
Test Prepared (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest::testAttributeOverridesCliRepeat (repetition 2 of 2))
30+
Test Passed (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest::testAttributeOverridesCliRepeat (repetition 2 of 2))
31+
Test Finished (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest::testAttributeOverridesCliRepeat (repetition 2 of 2))
32+
Test Suite Finished (PHPUnit\TestFixture\Repeat\RepeatAttributeOverrideTest, 2 tests)
33+
Test Runner Execution Finished
34+
Test Runner Finished
35+
PHPUnit Finished (Shell Exit Code: 0)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
--repeat with invalid value triggers warning
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--no-configuration';
6+
$_SERVER['argv'][] = '--do-not-cache-result';
7+
$_SERVER['argv'][] = '--repeat';
8+
$_SERVER['argv'][] = '0';
9+
$_SERVER['argv'][] = '--debug';
10+
$_SERVER['argv'][] = __DIR__ . '/_files/SuccessTest.php';
11+
12+
require __DIR__ . '/../../bootstrap.php';
13+
14+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
15+
--EXPECTF--
16+
PHPUnit Started (PHPUnit %s using %s)
17+
Test Runner Triggered PHPUnit Warning (Option "--repeat 0" ignored because "0" is not a positive integer)
18+
Test Runner Configured
19+
Event Facade Sealed
20+
Test Suite Loaded (2 tests)
21+
Test Runner Started
22+
Test Suite Sorted
23+
Test Runner Execution Started (2 tests)
24+
Test Suite Started (PHPUnit\TestFixture\Repeat\SuccessTest, 2 tests)
25+
Test Preparation Started (PHPUnit\TestFixture\Repeat\SuccessTest::testOne)
26+
Test Prepared (PHPUnit\TestFixture\Repeat\SuccessTest::testOne)
27+
Test Passed (PHPUnit\TestFixture\Repeat\SuccessTest::testOne)
28+
Test Finished (PHPUnit\TestFixture\Repeat\SuccessTest::testOne)
29+
Test Preparation Started (PHPUnit\TestFixture\Repeat\SuccessTest::testTwo)
30+
Test Prepared (PHPUnit\TestFixture\Repeat\SuccessTest::testTwo)
31+
Test Passed (PHPUnit\TestFixture\Repeat\SuccessTest::testTwo)
32+
Test Finished (PHPUnit\TestFixture\Repeat\SuccessTest::testTwo)
33+
Test Suite Finished (PHPUnit\TestFixture\Repeat\SuccessTest, 2 tests)
34+
Test Runner Execution Finished
35+
Test Runner Finished
36+
PHPUnit Finished (Shell Exit Code: 1)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
--repeat with JUnit XML logging includes repetition info in test names
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$junitFile = tempnam(sys_get_temp_dir(), 'phpunit_repeat_junit_');
6+
7+
$_SERVER['argv'][] = '--no-configuration';
8+
$_SERVER['argv'][] = '--do-not-cache-result';
9+
$_SERVER['argv'][] = '--repeat';
10+
$_SERVER['argv'][] = '2';
11+
$_SERVER['argv'][] = '--log-junit';
12+
$_SERVER['argv'][] = $junitFile;
13+
$_SERVER['argv'][] = __DIR__ . '/_files/SuccessTest.php';
14+
15+
require __DIR__ . '/../../bootstrap.php';
16+
17+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
18+
19+
print file_get_contents($junitFile);
20+
21+
unlink($junitFile);
22+
--EXPECTF--
23+
PHPUnit %s by Sebastian Bergmann and contributors.
24+
25+
Runtime: %s
26+
27+
.... 4 / 4 (100%)
28+
29+
Time: %s, Memory: %s
30+
31+
OK (4 tests, 4 assertions)
32+
<?xml version="1.0" encoding="UTF-8"?>
33+
<testsuites>
34+
<testsuite name="PHPUnit\TestFixture\Repeat\SuccessTest" file="%sSuccessTest.php" tests="4" assertions="4" errors="0" failures="0" skipped="0" time="%f">
35+
<testcase name="testOne (repetition 1 of 2)" file="%sSuccessTest.php" line="16" class="PHPUnit\TestFixture\Repeat\SuccessTest" classname="PHPUnit.TestFixture.Repeat.SuccessTest" assertions="1" time="%f"/>
36+
<testcase name="testOne (repetition 2 of 2)" file="%sSuccessTest.php" line="16" class="PHPUnit\TestFixture\Repeat\SuccessTest" classname="PHPUnit.TestFixture.Repeat.SuccessTest" assertions="1" time="%f"/>
37+
<testcase name="testTwo (repetition 1 of 2)" file="%sSuccessTest.php" line="21" class="PHPUnit\TestFixture\Repeat\SuccessTest" classname="PHPUnit.TestFixture.Repeat.SuccessTest" assertions="1" time="%f"/>
38+
<testcase name="testTwo (repetition 2 of 2)" file="%sSuccessTest.php" line="21" class="PHPUnit\TestFixture\Repeat\SuccessTest" classname="PHPUnit.TestFixture.Repeat.SuccessTest" assertions="1" time="%f"/>
39+
</testsuite>
40+
</testsuites>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
--repeat does not repeat test that depends on another test
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--no-configuration';
6+
$_SERVER['argv'][] = '--do-not-cache-result';
7+
$_SERVER['argv'][] = '--repeat';
8+
$_SERVER['argv'][] = '2';
9+
$_SERVER['argv'][] = '--debug';
10+
$_SERVER['argv'][] = __DIR__ . '/_files/DependsTest.php';
11+
12+
require __DIR__ . '/../../bootstrap.php';
13+
14+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
15+
--EXPECTF--
16+
PHPUnit Started (PHPUnit %s using %s)
17+
Test Runner Configured
18+
Event Facade Sealed
19+
Test Suite Loaded (3 tests)
20+
Test Runner Started
21+
Test Suite Sorted
22+
Test Runner Execution Started (3 tests)
23+
Test Suite Started (PHPUnit\TestFixture\Repeat\DependsTest, 3 tests)
24+
Test Preparation Started (PHPUnit\TestFixture\Repeat\DependsTest::testOne (repetition 1 of 2))
25+
Test Prepared (PHPUnit\TestFixture\Repeat\DependsTest::testOne (repetition 1 of 2))
26+
Test Passed (PHPUnit\TestFixture\Repeat\DependsTest::testOne (repetition 1 of 2))
27+
Test Finished (PHPUnit\TestFixture\Repeat\DependsTest::testOne (repetition 1 of 2))
28+
Test Preparation Started (PHPUnit\TestFixture\Repeat\DependsTest::testOne (repetition 2 of 2))
29+
Test Prepared (PHPUnit\TestFixture\Repeat\DependsTest::testOne (repetition 2 of 2))
30+
Test Passed (PHPUnit\TestFixture\Repeat\DependsTest::testOne (repetition 2 of 2))
31+
Test Finished (PHPUnit\TestFixture\Repeat\DependsTest::testOne (repetition 2 of 2))
32+
Test Preparation Started (PHPUnit\TestFixture\Repeat\DependsTest::testTwo)
33+
Test Prepared (PHPUnit\TestFixture\Repeat\DependsTest::testTwo)
34+
Test Passed (PHPUnit\TestFixture\Repeat\DependsTest::testTwo)
35+
Test Finished (PHPUnit\TestFixture\Repeat\DependsTest::testTwo)
36+
Test Suite Finished (PHPUnit\TestFixture\Repeat\DependsTest, 3 tests)
37+
Test Runner Execution Finished
38+
Test Runner Finished
39+
PHPUnit Finished (Shell Exit Code: 0)

0 commit comments

Comments
 (0)