Skip to content

Commit 63acb33

Browse files
MauricioFauthsebastianbergmann
authored andcommitted
Add e2e test for test method with data provider and requirement
1 parent 69e5d38 commit 63acb33

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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;
11+
12+
use Exception;
13+
use PHPUnit\Framework\Attributes\DataProvider;
14+
use PHPUnit\Framework\Attributes\DataProviderExternal;
15+
use PHPUnit\Framework\Attributes\RequiresPhpunit;
16+
use PHPUnit\Framework\TestCase;
17+
18+
final class DataProviderRequiresPhpUnitTest extends TestCase
19+
{
20+
public static function providerThatThrows(): array
21+
{
22+
throw new Exception('Should have been skipped.');
23+
}
24+
25+
public static function validProvider(): array
26+
{
27+
return [[true], [true]];
28+
}
29+
30+
public function invalidProvider(): array
31+
{
32+
return [[true], [true]];
33+
}
34+
35+
#[RequiresPhpunit('< 10')]
36+
#[DataProvider('invalidProvider')]
37+
public function testWithInvalidDataProvider(bool $param): void
38+
{
39+
$this->assertTrue($param);
40+
}
41+
42+
#[RequiresPhpunit('>= 10')]
43+
#[DataProvider('validProvider')]
44+
public function testWithValidDataProvider(bool $param): void
45+
{
46+
$this->assertTrue($param);
47+
}
48+
49+
#[RequiresPhpunit('< 10')]
50+
#[DataProvider('providerThatThrows')]
51+
public function testWithDataProviderThatThrows(): void
52+
{
53+
}
54+
55+
#[RequiresPhpunit('< 10')]
56+
#[DataProviderExternal(self::class, 'providerThatThrows')]
57+
public function testWithDataProviderExternalThatThrows(): void
58+
{
59+
}
60+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
phpunit ../../_files/DataProviderRequiresPhpUnitTest.php
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--display-skipped';
8+
$_SERVER['argv'][] = __DIR__ . '/../../_files/DataProviderRequiresPhpUnitTest.php';
9+
10+
require_once __DIR__ . '/../../bootstrap.php';
11+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
12+
--EXPECTF--
13+
PHPUnit %s by Sebastian Bergmann and contributors.
14+
15+
Runtime: %s
16+
17+
SSD. 4 / 4 (100%)
18+
19+
Time: %s, Memory: %s
20+
21+
There were 2 PHPUnit errors:
22+
23+
1) PHPUnit\TestFixture\DataProviderRequiresPhpUnitTest::testWithDataProviderThatThrows
24+
The data provider specified for PHPUnit\TestFixture\DataProviderRequiresPhpUnitTest::testWithDataProviderThatThrows is invalid
25+
Should have been skipped.
26+
27+
%s:%d
28+
29+
2) PHPUnit\TestFixture\DataProviderRequiresPhpUnitTest::testWithDataProviderExternalThatThrows
30+
The data provider specified for PHPUnit\TestFixture\DataProviderRequiresPhpUnitTest::testWithDataProviderExternalThatThrows is invalid
31+
Should have been skipped.
32+
33+
%s:%d
34+
35+
--
36+
37+
There were 2 skipped tests:
38+
39+
1) PHPUnit\TestFixture\DataProviderRequiresPhpUnitTest::testWithInvalidDataProvider with data set #0 (true)
40+
PHPUnit < 10 is required.
41+
42+
2) PHPUnit\TestFixture\DataProviderRequiresPhpUnitTest::testWithInvalidDataProvider with data set #1 (true)
43+
PHPUnit < 10 is required.
44+
45+
ERRORS!
46+
Tests: 4, Assertions: 2, Errors: 2, PHPUnit Deprecations: 1, Skipped: 2.
47+

0 commit comments

Comments
 (0)