Skip to content

Commit

Permalink
Merge pull request #960 from thephpleague/phpunit-10
Browse files Browse the repository at this point in the history
PHPUnit 10 & 11
  • Loading branch information
colinodell authored Feb 2, 2024
2 parents fada621 + fc73c34 commit c83590d
Show file tree
Hide file tree
Showing 59 changed files with 206 additions and 216 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.idea/
/.phpcs-cache
/.phpunit.result.cache
/.phpunit.cache
/build/
/docs/_site/
composer.lock
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"michelf/php-markdown": "^1.4 || ^2.0",
"nyholm/psr7": "^1.5",
"phpstan/phpstan": "^1.8.2",
"phpunit/phpunit": "^9.5.21",
"phpunit/phpunit": "^9.5.21 || ^10.5.9 || ^11.0.0",
"scrutinizer/ocular": "^1.8.1",
"symfony/finder": "^5.3 | ^6.0 || ^7.0",
"symfony/yaml": "^2.3 | ^3.0 | ^4.0 | ^5.0 | ^6.0 || ^7.0",
Expand Down
9 changes: 3 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
backupStaticProperties="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
cacheDirectory=".phpunit.cache"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* This is particularly useful for testing minor variations allowed by the spec
* or small regressions not tested by the spec.
*/
abstract class AbstractLocalDataTest extends TestCase
abstract class AbstractLocalDataTestCase extends TestCase
{
/**
* @param array<string, mixed> $config
Expand All @@ -36,7 +36,7 @@ abstract protected function createConverter(array $config = []): ConverterInterf
/**
* @return iterable<array{string, string, array<string, mixed>, string}>
*/
abstract public function dataProvider(): iterable;
abstract public static function dataProvider(): iterable;

/**
* @dataProvider dataProvider
Expand All @@ -61,7 +61,7 @@ public function testWithLocalData(string $markdown, string $html, array $config,
/**
* @return iterable<array{string, string, array<string, mixed>, string}>
*/
protected function loadTests(string $dir, string $pattern = '*', string $inputFormat = '.md', string $outputFormat = '.html'): iterable
final protected static function loadTests(string $dir, string $pattern = '*', string $inputFormat = '.md', string $outputFormat = '.html'): iterable
{
$finder = new Finder();
$finder->files()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

use League\CommonMark\CommonMarkConverter;
use League\CommonMark\MarkdownConverter;
use League\CommonMark\Util\SpecReader;
use PHPUnit\Framework\TestCase;

abstract class AbstractSpecTest extends TestCase
abstract class AbstractSpecTestCase extends TestCase
{
protected MarkdownConverter $converter;

Expand All @@ -33,35 +32,25 @@ protected function setUp(): void
/**
* @dataProvider dataProvider
*
* @param string $markdown Markdown to parse
* @param string $html Expected result
* @param string $input Markdown to parse
* @param string $output Expected result
*/
public function testSpecExample(string $markdown, string $html): void
public function testSpecExample(string $input, string $output, string $type = '', string $section = '', int $number = -1): void
{
$actualResult = (string) $this->converter->convert($markdown);
$actualResult = (string) $this->converter->convert($input);

$failureMessage = 'Unexpected result:';
$failureMessage .= "\n=== markdown ===============\n" . $this->showSpaces($markdown);
$failureMessage .= "\n=== expected ===============\n" . $this->showSpaces($html);
$failureMessage .= "\n=== markdown ===============\n" . $this->showSpaces($input);
$failureMessage .= "\n=== expected ===============\n" . $this->showSpaces($output);
$failureMessage .= "\n=== got ====================\n" . $this->showSpaces($actualResult);

$this->assertEquals($html, $actualResult, $failureMessage);
$this->assertEquals($output, $actualResult, $failureMessage);
}

public function dataProvider(): \Generator
{
yield from $this->loadSpecExamples();
}

protected function loadSpecExamples(): \Generator
{
yield from SpecReader::readFile($this->getFileName());
}
abstract public static function dataProvider(): \Generator;

private function showSpaces(string $str): string
{
return \strtr($str, ["\t" => '', ' ' => '']);
}

abstract protected function getFileName(): string;
}
28 changes: 11 additions & 17 deletions tests/functional/CMarkRegressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,24 @@

namespace League\CommonMark\Tests\Functional;

use League\CommonMark\Util\SpecReader;

/**
* Tests the parser against the CommonMark spec
*/
final class CMarkRegressionTest extends AbstractSpecTest
final class CMarkRegressionTest extends AbstractSpecTestCase
{
protected function getFileName(): string
public static function dataProvider(): \Generator
{
return __DIR__ . '/../../vendor/commonmark/cmark/test/regression.txt';
}

/**
* @deprecated
*
* We can't currently render spec example 13 exactly how the upstream library does. We'll likely need to overhaul
* our rendering approach in order to fix that, so we'll use this temporary workaround for now.
*/
public function dataProvider(): \Generator
{
foreach (parent::dataProvider() as $example) {
$tests = SpecReader::readFile(__DIR__ . '/../../vendor/commonmark/cmark/test/regression.txt');
foreach ($tests as $example) {
// We can't currently render spec example 13 exactly how the upstream library does. We'll likely need to overhaul
// our rendering approach in order to fix that, so we'll use this temporary workaround for now.
if ($example['number'] === 13) {
yield \str_replace('</script></li>', "</script>\n</li>", $example);
} else {
yield $example;
$example['output'] = \str_replace('</script></li>', "</script>\n</li>", $example['output']);
}

yield $example;
}
}
}
28 changes: 11 additions & 17 deletions tests/functional/CommonMarkJSRegressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,24 @@

namespace League\CommonMark\Tests\Functional;

use League\CommonMark\Util\SpecReader;

/**
* Tests the parser against the CommonMark spec
*/
final class CommonMarkJSRegressionTest extends AbstractSpecTest
final class CommonMarkJSRegressionTest extends AbstractSpecTestCase
{
protected function getFileName(): string
public static function dataProvider(): \Generator
{
return __DIR__ . '/../../vendor/commonmark/commonmark.js/test/regression.txt';
}

/**
* @deprecated
*
* We can't currently render spec example 18 exactly how the upstream library does. We'll likely need to overhaul
* our rendering approach in order to fix that, so we'll use this temporary workaround for now.
*/
public function dataProvider(): \Generator
{
foreach (parent::dataProvider() as $example) {
$tests = SpecReader::readFile(__DIR__ . '/../../vendor/commonmark/commonmark.js/test/regression.txt');
foreach ($tests as $example) {
// We can't currently render spec example 18 exactly how the upstream library does. We'll likely need to overhaul
// our rendering approach in order to fix that, so we'll use this temporary workaround for now.
if ($example['number'] === 18) {
yield \str_replace('</script></li>', "</script>\n</li>", $example);
} else {
yield $example;
$example['output'] = \str_replace('</script></li>', "</script>\n</li>", $example['output']);
}

yield $example;
}
}
}
2 changes: 1 addition & 1 deletion tests/functional/Delimiter/DelimiterProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testAsymmetricDelimiterProcessing(string $input, string $expecte
/**
* @return iterable<array<string>>
*/
public function asymmetricDelimiterDataProvider(): iterable
public static function asymmetricDelimiterDataProvider(): iterable
{
yield ['{foo} bar', "<p>FOO bar</p>\n"];
yield ['f{oo ba}r', "<p>fOO BAr</p>\n"];
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/Extension/Attributes/LocalDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
use League\CommonMark\MarkdownConverter;
use League\CommonMark\Tests\Functional\AbstractLocalDataTest;
use League\CommonMark\Tests\Functional\AbstractLocalDataTestCase;

/**
* @internal
*/
final class LocalDataTest extends AbstractLocalDataTest
final class LocalDataTest extends AbstractLocalDataTestCase
{
/**
* @param array<string, mixed> $config
Expand All @@ -43,8 +43,8 @@ protected function createConverter(array $config = []): ConverterInterface
/**
* {@inheritDoc}
*/
public function dataProvider(): iterable
public static function dataProvider(): iterable
{
yield from $this->loadTests(__DIR__ . '/data');
yield from self::loadTests(__DIR__ . '/data');
}
}
8 changes: 4 additions & 4 deletions tests/functional/Extension/Autolink/AutolinkXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\Autolink\AutolinkExtension;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Tests\Functional\AbstractLocalDataTest;
use League\CommonMark\Tests\Functional\AbstractLocalDataTestCase;
use League\CommonMark\Xml\MarkdownToXmlConverter;

final class AutolinkXmlTest extends AbstractLocalDataTest
final class AutolinkXmlTest extends AbstractLocalDataTestCase
{
/**
* @param array<string, mixed> $config
Expand All @@ -37,8 +37,8 @@ protected function createConverter(array $config = []): ConverterInterface
/**
* {@inheritDoc}
*/
public function dataProvider(): iterable
public static function dataProvider(): iterable
{
yield from $this->loadTests(__DIR__ . '/xml', '*', '.md', '.xml');
yield from self::loadTests(__DIR__ . '/xml', '*', '.md', '.xml');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testEmailAutolinks(string $input, string $expected): void
/**
* @return iterable<array<mixed>>
*/
public function dataProviderForEmailAutolinks(): iterable
public static function dataProviderForEmailAutolinks(): iterable
{
yield ['You can try emailing [email protected] but that inbox doesn\'t actually exist.', '<p>You can try emailing <a href="mailto:[email protected]">[email protected]</a> but that inbox doesn\'t actually exist.</p>'];
yield ['> This processor can even handle email addresses like [email protected] inside of blockquotes!', "<blockquote>\n<p>This processor can even handle email addresses like <a href=\"mailto:[email protected]\">[email protected]</a> inside of blockquotes!</p>\n</blockquote>"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testUrlAutolinks(string $input, string $expected): void
/**
* @return iterable<array<mixed>>
*/
public function dataProviderForAutolinkTests(): iterable
public static function dataProviderForAutolinkTests(): iterable
{
// Basic examples
yield ['You can search on http://google.com for stuff.', '<p>You can search on <a href="http://google.com">http://google.com</a> for stuff.</p>'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testConfiguration(string $markdown, array $config, string $expec
/**
* @return iterable<array<mixed>>
*/
public function getTestData(): iterable
public static function getTestData(): iterable
{
yield ['*Emphasis*', [], "<p><em>Emphasis</em></p>\n"];
yield ['**Strong**', [], "<p><strong>Strong</strong></p>\n"];
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/Extension/CommonMark/CommonMarkXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
use League\CommonMark\ConverterInterface;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Tests\Functional\AbstractLocalDataTest;
use League\CommonMark\Tests\Functional\AbstractLocalDataTestCase;
use League\CommonMark\Xml\MarkdownToXmlConverter;

final class CommonMarkXmlTest extends AbstractLocalDataTest
final class CommonMarkXmlTest extends AbstractLocalDataTestCase
{
/**
* @param array<string, mixed> $config
Expand All @@ -35,8 +35,8 @@ protected function createConverter(array $config = []): ConverterInterface
/**
* {@inheritDoc}
*/
public function dataProvider(): iterable
public static function dataProvider(): iterable
{
yield from $this->loadTests(__DIR__ . '/xml', '*', '.md', '.xml');
yield from self::loadTests(__DIR__ . '/xml', '*', '.md', '.xml');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testExample(string $markdown, array $config, string $expectedHtm
/**
* @return iterable<mixed>
*/
public function provideTestCases(): iterable
public static function provideTestCases(): iterable
{
$markdown = <<<MD
# Hello World
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\DescriptionList\DescriptionListExtension;
use League\CommonMark\MarkdownConverter;
use League\CommonMark\Tests\Functional\AbstractSpecTest;
use League\CommonMark\Tests\Functional\AbstractSpecTestCase;
use League\CommonMark\Util\SpecReader;

final class DescriptionListSpecTest extends AbstractSpecTest
final class DescriptionListSpecTest extends AbstractSpecTestCase
{
protected function setUp(): void
{
Expand All @@ -30,8 +31,8 @@ protected function setUp(): void
$this->converter = new MarkdownConverter($environment);
}

protected function getFileName(): string
public static function dataProvider(): \Generator
{
return __DIR__ . '/spec.txt';
yield from SpecReader::readFile(__DIR__ . '/spec.txt');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
use League\CommonMark\Extension\Embed\Bridge\OscaroteroEmbedAdapter;
use League\CommonMark\Extension\Embed\EmbedExtension;
use League\CommonMark\MarkdownConverter;
use League\CommonMark\Tests\Functional\AbstractLocalDataTest;
use League\CommonMark\Tests\Functional\AbstractLocalDataTestCase;

final class OscaroteroEmbedAdapterTest extends AbstractLocalDataTest
final class OscaroteroEmbedAdapterTest extends AbstractLocalDataTestCase
{
/**
* {@inheritDoc}
Expand All @@ -42,8 +42,8 @@ protected function createConverter(array $config = []): ConverterInterface
/**
* {@inheritDoc}
*/
public function dataProvider(): iterable
public static function dataProvider(): iterable
{
yield from $this->loadTests(__DIR__ . '/data');
yield from self::loadTests(__DIR__ . '/data');
}
}
8 changes: 4 additions & 4 deletions tests/functional/Extension/Embed/EmbedExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\Embed\EmbedExtension;
use League\CommonMark\MarkdownConverter;
use League\CommonMark\Tests\Functional\AbstractLocalDataTest;
use League\CommonMark\Tests\Functional\AbstractLocalDataTestCase;
use League\CommonMark\Tests\Unit\Extension\Embed\FakeAdapter;

final class EmbedExtensionTest extends AbstractLocalDataTest
final class EmbedExtensionTest extends AbstractLocalDataTestCase
{
/**
* {@inheritDoc}
Expand All @@ -48,8 +48,8 @@ protected function createConverter(array $config = []): ConverterInterface
/**
* {@inheritDoc}
*/
public function dataProvider(): iterable
public static function dataProvider(): iterable
{
yield from $this->loadTests(__DIR__ . '/data');
yield from self::loadTests(__DIR__ . '/data');
}
}
Loading

0 comments on commit c83590d

Please sign in to comment.