Skip to content

Commit c83590d

Browse files
authored
Merge pull request #960 from thephpleague/phpunit-10
PHPUnit 10 & 11
2 parents fada621 + fc73c34 commit c83590d

File tree

59 files changed

+206
-216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+206
-216
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/.idea/
22
/.phpcs-cache
33
/.phpunit.result.cache
4+
/.phpunit.cache
45
/build/
56
/docs/_site/
67
composer.lock

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"michelf/php-markdown": "^1.4 || ^2.0",
4141
"nyholm/psr7": "^1.5",
4242
"phpstan/phpstan": "^1.8.2",
43-
"phpunit/phpunit": "^9.5.21",
43+
"phpunit/phpunit": "^9.5.21 || ^10.5.9 || ^11.0.0",
4444
"scrutinizer/ocular": "^1.8.1",
4545
"symfony/finder": "^5.3 | ^6.0 || ^7.0",
4646
"symfony/yaml": "^2.3 | ^3.0 | ^4.0 | ^5.0 | ^6.0 || ^7.0",

phpunit.xml.dist

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
bootstrap="vendor/autoload.php"
44
backupGlobals="false"
5-
backupStaticAttributes="false"
5+
backupStaticProperties="false"
66
colors="true"
7-
verbose="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
117
processIsolation="false"
128
stopOnFailure="false"
13-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
9+
cacheDirectory=".phpunit.cache"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd">
1411
<coverage>
1512
<include>
1613
<directory suffix=".php">src/</directory>

tests/functional/AbstractLocalDataTest.php renamed to tests/functional/AbstractLocalDataTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* This is particularly useful for testing minor variations allowed by the spec
2727
* or small regressions not tested by the spec.
2828
*/
29-
abstract class AbstractLocalDataTest extends TestCase
29+
abstract class AbstractLocalDataTestCase extends TestCase
3030
{
3131
/**
3232
* @param array<string, mixed> $config
@@ -36,7 +36,7 @@ abstract protected function createConverter(array $config = []): ConverterInterf
3636
/**
3737
* @return iterable<array{string, string, array<string, mixed>, string}>
3838
*/
39-
abstract public function dataProvider(): iterable;
39+
abstract public static function dataProvider(): iterable;
4040

4141
/**
4242
* @dataProvider dataProvider
@@ -61,7 +61,7 @@ public function testWithLocalData(string $markdown, string $html, array $config,
6161
/**
6262
* @return iterable<array{string, string, array<string, mixed>, string}>
6363
*/
64-
protected function loadTests(string $dir, string $pattern = '*', string $inputFormat = '.md', string $outputFormat = '.html'): iterable
64+
final protected static function loadTests(string $dir, string $pattern = '*', string $inputFormat = '.md', string $outputFormat = '.html'): iterable
6565
{
6666
$finder = new Finder();
6767
$finder->files()

tests/functional/AbstractSpecTest.php renamed to tests/functional/AbstractSpecTestCase.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818

1919
use League\CommonMark\CommonMarkConverter;
2020
use League\CommonMark\MarkdownConverter;
21-
use League\CommonMark\Util\SpecReader;
2221
use PHPUnit\Framework\TestCase;
2322

24-
abstract class AbstractSpecTest extends TestCase
23+
abstract class AbstractSpecTestCase extends TestCase
2524
{
2625
protected MarkdownConverter $converter;
2726

@@ -33,35 +32,25 @@ protected function setUp(): void
3332
/**
3433
* @dataProvider dataProvider
3534
*
36-
* @param string $markdown Markdown to parse
37-
* @param string $html Expected result
35+
* @param string $input Markdown to parse
36+
* @param string $output Expected result
3837
*/
39-
public function testSpecExample(string $markdown, string $html): void
38+
public function testSpecExample(string $input, string $output, string $type = '', string $section = '', int $number = -1): void
4039
{
41-
$actualResult = (string) $this->converter->convert($markdown);
40+
$actualResult = (string) $this->converter->convert($input);
4241

4342
$failureMessage = 'Unexpected result:';
44-
$failureMessage .= "\n=== markdown ===============\n" . $this->showSpaces($markdown);
45-
$failureMessage .= "\n=== expected ===============\n" . $this->showSpaces($html);
43+
$failureMessage .= "\n=== markdown ===============\n" . $this->showSpaces($input);
44+
$failureMessage .= "\n=== expected ===============\n" . $this->showSpaces($output);
4645
$failureMessage .= "\n=== got ====================\n" . $this->showSpaces($actualResult);
4746

48-
$this->assertEquals($html, $actualResult, $failureMessage);
47+
$this->assertEquals($output, $actualResult, $failureMessage);
4948
}
5049

51-
public function dataProvider(): \Generator
52-
{
53-
yield from $this->loadSpecExamples();
54-
}
55-
56-
protected function loadSpecExamples(): \Generator
57-
{
58-
yield from SpecReader::readFile($this->getFileName());
59-
}
50+
abstract public static function dataProvider(): \Generator;
6051

6152
private function showSpaces(string $str): string
6253
{
6354
return \strtr($str, ["\t" => '', ' ' => '']);
6455
}
65-
66-
abstract protected function getFileName(): string;
6756
}

tests/functional/CMarkRegressionTest.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,24 @@
1616

1717
namespace League\CommonMark\Tests\Functional;
1818

19+
use League\CommonMark\Util\SpecReader;
20+
1921
/**
2022
* Tests the parser against the CommonMark spec
2123
*/
22-
final class CMarkRegressionTest extends AbstractSpecTest
24+
final class CMarkRegressionTest extends AbstractSpecTestCase
2325
{
24-
protected function getFileName(): string
26+
public static function dataProvider(): \Generator
2527
{
26-
return __DIR__ . '/../../vendor/commonmark/cmark/test/regression.txt';
27-
}
28-
29-
/**
30-
* @deprecated
31-
*
32-
* We can't currently render spec example 13 exactly how the upstream library does. We'll likely need to overhaul
33-
* our rendering approach in order to fix that, so we'll use this temporary workaround for now.
34-
*/
35-
public function dataProvider(): \Generator
36-
{
37-
foreach (parent::dataProvider() as $example) {
28+
$tests = SpecReader::readFile(__DIR__ . '/../../vendor/commonmark/cmark/test/regression.txt');
29+
foreach ($tests as $example) {
30+
// We can't currently render spec example 13 exactly how the upstream library does. We'll likely need to overhaul
31+
// our rendering approach in order to fix that, so we'll use this temporary workaround for now.
3832
if ($example['number'] === 13) {
39-
yield \str_replace('</script></li>', "</script>\n</li>", $example);
40-
} else {
41-
yield $example;
33+
$example['output'] = \str_replace('</script></li>', "</script>\n</li>", $example['output']);
4234
}
35+
36+
yield $example;
4337
}
4438
}
4539
}

tests/functional/CommonMarkJSRegressionTest.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,24 @@
1616

1717
namespace League\CommonMark\Tests\Functional;
1818

19+
use League\CommonMark\Util\SpecReader;
20+
1921
/**
2022
* Tests the parser against the CommonMark spec
2123
*/
22-
final class CommonMarkJSRegressionTest extends AbstractSpecTest
24+
final class CommonMarkJSRegressionTest extends AbstractSpecTestCase
2325
{
24-
protected function getFileName(): string
26+
public static function dataProvider(): \Generator
2527
{
26-
return __DIR__ . '/../../vendor/commonmark/commonmark.js/test/regression.txt';
27-
}
28-
29-
/**
30-
* @deprecated
31-
*
32-
* We can't currently render spec example 18 exactly how the upstream library does. We'll likely need to overhaul
33-
* our rendering approach in order to fix that, so we'll use this temporary workaround for now.
34-
*/
35-
public function dataProvider(): \Generator
36-
{
37-
foreach (parent::dataProvider() as $example) {
28+
$tests = SpecReader::readFile(__DIR__ . '/../../vendor/commonmark/commonmark.js/test/regression.txt');
29+
foreach ($tests as $example) {
30+
// We can't currently render spec example 18 exactly how the upstream library does. We'll likely need to overhaul
31+
// our rendering approach in order to fix that, so we'll use this temporary workaround for now.
3832
if ($example['number'] === 18) {
39-
yield \str_replace('</script></li>', "</script>\n</li>", $example);
40-
} else {
41-
yield $example;
33+
$example['output'] = \str_replace('</script></li>', "</script>\n</li>", $example['output']);
4234
}
35+
36+
yield $example;
4337
}
4438
}
4539
}

tests/functional/Delimiter/DelimiterProcessingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testAsymmetricDelimiterProcessing(string $input, string $expecte
5555
/**
5656
* @return iterable<array<string>>
5757
*/
58-
public function asymmetricDelimiterDataProvider(): iterable
58+
public static function asymmetricDelimiterDataProvider(): iterable
5959
{
6060
yield ['{foo} bar', "<p>FOO bar</p>\n"];
6161
yield ['f{oo ba}r', "<p>fOO BAr</p>\n"];

tests/functional/Extension/Attributes/LocalDataTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
2121
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
2222
use League\CommonMark\MarkdownConverter;
23-
use League\CommonMark\Tests\Functional\AbstractLocalDataTest;
23+
use League\CommonMark\Tests\Functional\AbstractLocalDataTestCase;
2424

2525
/**
2626
* @internal
2727
*/
28-
final class LocalDataTest extends AbstractLocalDataTest
28+
final class LocalDataTest extends AbstractLocalDataTestCase
2929
{
3030
/**
3131
* @param array<string, mixed> $config
@@ -43,8 +43,8 @@ protected function createConverter(array $config = []): ConverterInterface
4343
/**
4444
* {@inheritDoc}
4545
*/
46-
public function dataProvider(): iterable
46+
public static function dataProvider(): iterable
4747
{
48-
yield from $this->loadTests(__DIR__ . '/data');
48+
yield from self::loadTests(__DIR__ . '/data');
4949
}
5050
}

tests/functional/Extension/Autolink/AutolinkXmlTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
use League\CommonMark\Environment\Environment;
1818
use League\CommonMark\Extension\Autolink\AutolinkExtension;
1919
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
20-
use League\CommonMark\Tests\Functional\AbstractLocalDataTest;
20+
use League\CommonMark\Tests\Functional\AbstractLocalDataTestCase;
2121
use League\CommonMark\Xml\MarkdownToXmlConverter;
2222

23-
final class AutolinkXmlTest extends AbstractLocalDataTest
23+
final class AutolinkXmlTest extends AbstractLocalDataTestCase
2424
{
2525
/**
2626
* @param array<string, mixed> $config
@@ -37,8 +37,8 @@ protected function createConverter(array $config = []): ConverterInterface
3737
/**
3838
* {@inheritDoc}
3939
*/
40-
public function dataProvider(): iterable
40+
public static function dataProvider(): iterable
4141
{
42-
yield from $this->loadTests(__DIR__ . '/xml', '*', '.md', '.xml');
42+
yield from self::loadTests(__DIR__ . '/xml', '*', '.md', '.xml');
4343
}
4444
}

0 commit comments

Comments
 (0)