diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c2cb8e3cc6..9f2b867dbe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,6 +30,10 @@ jobs: - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: "Use PHPUnit 9.3+ on PHP 8" + run: composer require --no-update --dev phpunit/phpunit:^9.3 + if: "matrix.php == '8.0'" + - run: composer update --no-progress ${{ matrix.composer-flags }} - run: vendor/bin/phpunit --no-coverage diff --git a/composer.json b/composer.json index 3a39e2820d..16395270c5 100644 --- a/composer.json +++ b/composer.json @@ -32,10 +32,12 @@ "michelf/php-markdown": "~1.4", "mikehaertl/php-shellcommand": "^1.4", "phpstan/phpstan": "^0.12", - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.2", "scrutinizer/ocular": "^1.5", "symfony/finder": "^4.2" }, + "minimum-stability": "dev", + "prefer-stable": true, "conflict": { "scrutinizer/ocular": "1.7.*" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b1e50943c2..0ad04ee79f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,8 +10,11 @@ processIsolation="false" stopOnFailure="false"> - - tests + + tests/functional + + + tests/unit @@ -20,8 +23,6 @@ - - diff --git a/src/Reference/Reference.php b/src/Reference/Reference.php index aeb3a6c956..ebe57aa8bf 100644 --- a/src/Reference/Reference.php +++ b/src/Reference/Reference.php @@ -65,6 +65,7 @@ public function getTitle(): string * @return string * * @deprecated Use TextNormalizer::normalize() instead + * @group legacy */ public static function normalizeReference(string $string): string { diff --git a/tests/functional/AbstractSpecTest.php b/tests/functional/AbstractSpecTest.php index 8e4d07ad79..bc01798978 100644 --- a/tests/functional/AbstractSpecTest.php +++ b/tests/functional/AbstractSpecTest.php @@ -24,7 +24,7 @@ abstract class AbstractSpecTest extends TestCase */ protected $converter; - protected function setUp() + protected function setUp(): void { $this->converter = new CommonMarkConverter(); } diff --git a/tests/functional/BinTest.php b/tests/functional/BinTest.php index b266f3f0fe..7d24b17315 100644 --- a/tests/functional/BinTest.php +++ b/tests/functional/BinTest.php @@ -35,7 +35,7 @@ public function testNoArgsOrStdin() $this->assertEquals(1, $cmd->getExitCode()); if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - $this->assertContains('Usage:', $cmd->getError()); + $this->assertStringContainsString('Usage:', $cmd->getError()); } } @@ -49,7 +49,7 @@ public function testHelpShortFlag() $cmd->execute(); $this->assertEquals(0, $cmd->getExitCode()); - $this->assertContains('Usage:', $cmd->getOutput()); + $this->assertStringContainsString('Usage:', $cmd->getOutput()); } /** @@ -62,7 +62,7 @@ public function testHelpOption() $cmd->execute(); $this->assertEquals(0, $cmd->getExitCode()); - $this->assertContains('Usage:', $cmd->getOutput()); + $this->assertStringContainsString('Usage:', $cmd->getOutput()); } /** @@ -77,7 +77,7 @@ public function testUnknownOption() $this->assertEquals(1, $cmd->getExitCode()); if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - $this->assertContains('Unknown option', $cmd->getError()); + $this->assertStringContainsString('Unknown option', $cmd->getError()); } } @@ -92,7 +92,7 @@ public function testFileArgument() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('atx_heading.html'))); - $this->assertContains($expectedContents, $cmd->getOutput()); + $this->assertStringContainsString($expectedContents, $cmd->getOutput()); } /** @@ -109,7 +109,7 @@ public function testStdin() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('atx_heading.html'))); - $this->assertContains($expectedContents, $cmd->getOutput()); + $this->assertStringContainsString($expectedContents, $cmd->getOutput()); } /** @@ -123,7 +123,7 @@ public function testUnsafe() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('safe/unsafe_output.html'))); - $this->assertContains($expectedContents, $cmd->getOutput()); + $this->assertStringContainsString($expectedContents, $cmd->getOutput()); } /** @@ -138,7 +138,7 @@ public function testSafe() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('safe/safe_output.html'))); - $this->assertContains($expectedContents, $cmd->getOutput()); + $this->assertStringContainsString($expectedContents, $cmd->getOutput()); } /** @@ -152,7 +152,7 @@ public function testVersion() $cmd->execute(); $this->assertEquals(0, $cmd->getExitCode()); - $this->assertContains(CommonMarkConverter::VERSION, trim($cmd->getOutput())); + $this->assertStringContainsString(CommonMarkConverter::VERSION, trim($cmd->getOutput())); } } diff --git a/tests/functional/Delimiter/DelimiterProcessingTest.php b/tests/functional/Delimiter/DelimiterProcessingTest.php index bc74a3c2e0..a0f211ee82 100644 --- a/tests/functional/Delimiter/DelimiterProcessingTest.php +++ b/tests/functional/Delimiter/DelimiterProcessingTest.php @@ -73,11 +73,9 @@ public function testMultipleDelimitersWithDifferentLengths() $this->assertEquals("

(1)(2)both(/2)(/1)

\n", $c->convertToHtml('@@@both@@@')); } - /** - * @expectedException \InvalidArgumentException - */ public function testMultipleDelimitersWithSameLength() { + $this->expectException(\InvalidArgumentException::class); $e = Environment::createCommonMarkEnvironment(); $e->addDelimiterProcessor(new TestDelimiterProcessor('@', 1)); $e->addDelimiterProcessor(new TestDelimiterProcessor('@', 1)); diff --git a/tests/functional/EmphasisTest.php b/tests/functional/EmphasisTest.php index 307313782f..8cc70eb079 100644 --- a/tests/functional/EmphasisTest.php +++ b/tests/functional/EmphasisTest.php @@ -44,7 +44,7 @@ public function testEmStrong() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('emstrong.html'))); - $this->assertContains($expectedContents, trim($cmd->getOutput())); + $this->assertStringContainsString($expectedContents, trim($cmd->getOutput())); } /** @@ -59,7 +59,7 @@ public function testEm() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('em.html'))); - $this->assertContains($expectedContents, trim($cmd->getOutput())); + $this->assertStringContainsString($expectedContents, trim($cmd->getOutput())); } /** @@ -74,7 +74,7 @@ public function testStrong() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('strong.html'))); - $this->assertContains($expectedContents, trim($cmd->getOutput())); + $this->assertStringContainsString($expectedContents, trim($cmd->getOutput())); } /** @@ -90,7 +90,7 @@ public function testNone() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('disabled.html'))); - $this->assertContains($expectedContents, trim($cmd->getOutput())); + $this->assertStringContainsString($expectedContents, trim($cmd->getOutput())); } /** @@ -105,7 +105,7 @@ public function testAsterisks() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('asterisks.html'))); - $this->assertContains($expectedContents, trim($cmd->getOutput())); + $this->assertStringContainsString($expectedContents, trim($cmd->getOutput())); } /** @@ -120,6 +120,6 @@ public function testUnderscores() $this->assertEquals(0, $cmd->getExitCode()); $expectedContents = trim(file_get_contents($this->getPathToData('underscores.html'))); - $this->assertContains($expectedContents, trim($cmd->getOutput())); + $this->assertStringContainsString($expectedContents, trim($cmd->getOutput())); } } diff --git a/tests/functional/Extension/GithubFlavoredMarkdownExtensionTest.php b/tests/functional/Extension/GithubFlavoredMarkdownExtensionTest.php index 5cffdaaa22..65096034d0 100644 --- a/tests/functional/Extension/GithubFlavoredMarkdownExtensionTest.php +++ b/tests/functional/Extension/GithubFlavoredMarkdownExtensionTest.php @@ -16,7 +16,7 @@ class GithubFlavoredMarkdownExtensionTest extends AbstractSpecTest { - protected function setUp() + protected function setUp(): void { $this->converter = new GithubFlavoredMarkdownConverter(); } diff --git a/tests/functional/Extension/HeadingPermalink/HeadingPermalinkExtensionTest.php b/tests/functional/Extension/HeadingPermalink/HeadingPermalinkExtensionTest.php index 41b03b1e8d..fa32e388c7 100644 --- a/tests/functional/Extension/HeadingPermalink/HeadingPermalinkExtensionTest.php +++ b/tests/functional/Extension/HeadingPermalink/HeadingPermalinkExtensionTest.php @@ -77,6 +77,9 @@ public function dataProviderForTestHeadingPermalinksWithCustomOptions() yield ["Test\n----", '

Test

']; } + /** + * @group legacy + */ public function testHeadingPermalinksWithDeprecatedInnerContents() { $environment = Environment::createCommonMarkEnvironment(); diff --git a/tests/functional/Extension/InlinesOnly/InlinesOnlyFunctionalTest.php b/tests/functional/Extension/InlinesOnly/InlinesOnlyFunctionalTest.php index 7d124b6362..1416599333 100644 --- a/tests/functional/Extension/InlinesOnly/InlinesOnlyFunctionalTest.php +++ b/tests/functional/Extension/InlinesOnly/InlinesOnlyFunctionalTest.php @@ -26,7 +26,7 @@ class InlinesOnlyFunctionalTest extends TestCase */ protected $converter; - protected function setUp() + protected function setUp(): void { $environment = new Environment(); $environment->addExtension(new InlinesOnlyExtension()); diff --git a/tests/functional/Extension/SmartPunct/SmartPunctFunctionalTest.php b/tests/functional/Extension/SmartPunct/SmartPunctFunctionalTest.php index 01228f0b50..f0a579f798 100644 --- a/tests/functional/Extension/SmartPunct/SmartPunctFunctionalTest.php +++ b/tests/functional/Extension/SmartPunct/SmartPunctFunctionalTest.php @@ -12,7 +12,7 @@ * file that was distributed with this source code. */ -namespace League\CommonMark\Tests\Unit\Extension\SmartPunct; +namespace League\CommonMark\Tests\Functional\Extension\SmartPunct; use League\CommonMark\CommonMarkConverter; use League\CommonMark\Environment; @@ -29,7 +29,7 @@ class SmartPunctFunctionalTest extends TestCase */ protected $converter; - protected function setUp() + protected function setUp(): void { $environment = Environment::createCommonMarkEnvironment(); $environment->addExtension(new SmartPunctExtension()); diff --git a/tests/functional/LocalDataTest.php b/tests/functional/LocalDataTest.php index d84886fb31..0a45faf389 100644 --- a/tests/functional/LocalDataTest.php +++ b/tests/functional/LocalDataTest.php @@ -26,7 +26,7 @@ class LocalDataTest extends AbstractLocalDataTest */ protected $converter; - protected function setUp() + protected function setUp(): void { $this->converter = new CommonMarkConverter(); } diff --git a/tests/unit/Block/Element/AbstractBlockTest.php b/tests/unit/Block/Element/AbstractBlockTest.php index 75a3cb530d..1ccc31903f 100644 --- a/tests/unit/Block/Element/AbstractBlockTest.php +++ b/tests/unit/Block/Element/AbstractBlockTest.php @@ -33,11 +33,10 @@ public function testSetParent() $this->assertNull($block->parent()); } - /** - * @expectedException \InvalidArgumentException - */ public function testSetParentWithInvalidNode() { + $this->expectException(\InvalidArgumentException::class); + $block = $this->getMockForAbstractClass(AbstractBlock::class); $inline = $this->getMockForAbstractClass(AbstractInline::class); diff --git a/tests/unit/Block/Renderer/BlockQuoteRendererTest.php b/tests/unit/Block/Renderer/BlockQuoteRendererTest.php index 07d66b79df..0b257190e5 100644 --- a/tests/unit/Block/Renderer/BlockQuoteRendererTest.php +++ b/tests/unit/Block/Renderer/BlockQuoteRendererTest.php @@ -29,7 +29,7 @@ class BlockQuoteRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new BlockQuoteRenderer(); } @@ -58,15 +58,14 @@ public function testRenderBlockQuote() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('blockquote', $result->getTagName()); - $this->assertContains('::blocks::', $result->getContents(true)); + $this->assertStringContainsString('::blocks::', $result->getContents(true)); $this->assertEquals(['id' => 'id'], $result->getAllAttributes()); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Block/Renderer/DocumentRendererTest.php b/tests/unit/Block/Renderer/DocumentRendererTest.php index f628011a75..f941b842a2 100644 --- a/tests/unit/Block/Renderer/DocumentRendererTest.php +++ b/tests/unit/Block/Renderer/DocumentRendererTest.php @@ -28,7 +28,7 @@ class DocumentRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new DocumentRenderer(); } @@ -40,7 +40,7 @@ public function testRenderEmptyDocument() $result = $this->renderer->render($block, $fakeRenderer); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertEmpty($result); } @@ -51,15 +51,14 @@ public function testRenderDocument() $result = $this->renderer->render($block, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('::blocks::', $result); + $this->assertIsString($result); + $this->assertStringContainsString('::blocks::', $result); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Block/Renderer/FencedCodeRendererTest.php b/tests/unit/Block/Renderer/FencedCodeRendererTest.php index df3c8c5b0c..5436c9f8a8 100644 --- a/tests/unit/Block/Renderer/FencedCodeRendererTest.php +++ b/tests/unit/Block/Renderer/FencedCodeRendererTest.php @@ -31,7 +31,7 @@ class FencedCodeRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new FencedCodeRenderer(); } @@ -59,8 +59,8 @@ public function testRenderWithLanguageSpecified() $code = $result->getContents(false); $this->assertTrue($code instanceof HtmlElement); $this->assertEquals('code', $code->getTagName()); - $this->assertContains('bar language-php', $code->getAttribute('class')); - $this->assertContains('hello world', $code->getContents(true)); + $this->assertStringContainsString('bar language-php', $code->getAttribute('class')); + $this->assertStringContainsString('hello world', $code->getContents(true)); } public function testRenderWithoutLanguageSpecified() @@ -87,14 +87,13 @@ public function testRenderWithoutLanguageSpecified() $this->assertTrue($code instanceof HtmlElement); $this->assertEquals('code', $code->getTagName()); $this->assertEquals('bar', $code->getAttribute('class')); - $this->assertContains('hello world', $code->getContents(true)); + $this->assertStringContainsString('hello world', $code->getContents(true)); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Block/Renderer/HeadingRendererTest.php b/tests/unit/Block/Renderer/HeadingRendererTest.php index ca9707b2dc..4cf57b069e 100644 --- a/tests/unit/Block/Renderer/HeadingRendererTest.php +++ b/tests/unit/Block/Renderer/HeadingRendererTest.php @@ -28,7 +28,7 @@ class HeadingRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new HeadingRenderer(); } @@ -49,7 +49,7 @@ public function testRender($level, $expectedTag) $this->assertTrue($result instanceof HtmlElement); $this->assertEquals($expectedTag, $result->getTagName()); - $this->assertContains('::inlines::', $result->getContents(true)); + $this->assertStringContainsString('::inlines::', $result->getContents(true)); $this->assertEquals(['id' => 'foo'], $result->getAllAttributes()); } @@ -65,11 +65,10 @@ public function dataForTestRender() ]; } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Block/Renderer/HtmlBlockRendererTest.php b/tests/unit/Block/Renderer/HtmlBlockRendererTest.php index 4df6790640..2656652e8b 100644 --- a/tests/unit/Block/Renderer/HtmlBlockRendererTest.php +++ b/tests/unit/Block/Renderer/HtmlBlockRendererTest.php @@ -29,7 +29,7 @@ class HtmlBlockRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new HtmlBlockRenderer(); $this->renderer->setConfiguration(new Configuration()); @@ -37,7 +37,7 @@ protected function setUp() public function testRender() { - /** @var HtmlBlock|\PHPUnit_Framework_MockObject_MockObject $block */ + /** @var HtmlBlock|\PHPUnit\Framework\MockObject\MockObject $block */ $block = $this->getMockBuilder(\League\CommonMark\Block\Element\HtmlBlock::class) ->setConstructorArgs([HtmlBlock::TYPE_6_BLOCK_ELEMENT]) ->getMock(); @@ -49,8 +49,8 @@ public function testRender() $result = $this->renderer->render($block, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('', $result); + $this->assertIsString($result); + $this->assertStringContainsString('', $result); } public function testRenderAllowHtml() @@ -59,7 +59,7 @@ public function testRenderAllowHtml() 'html_input' => Environment::HTML_INPUT_ALLOW, ])); - /** @var HtmlBlock|\PHPUnit_Framework_MockObject_MockObject $block */ + /** @var HtmlBlock|\PHPUnit\Framework\MockObject\MockObject $block */ $block = $this->getMockBuilder(\League\CommonMark\Block\Element\HtmlBlock::class) ->setConstructorArgs([HtmlBlock::TYPE_6_BLOCK_ELEMENT]) ->getMock(); @@ -71,8 +71,8 @@ public function testRenderAllowHtml() $result = $this->renderer->render($block, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('', $result); + $this->assertIsString($result); + $this->assertStringContainsString('', $result); } public function testRenderEscapeHtml() @@ -81,7 +81,7 @@ public function testRenderEscapeHtml() 'html_input' => Environment::HTML_INPUT_ESCAPE, ])); - /** @var HtmlBlock|\PHPUnit_Framework_MockObject_MockObject $block */ + /** @var HtmlBlock|\PHPUnit\Framework\MockObject\MockObject $block */ $block = $this->getMockBuilder(\League\CommonMark\Block\Element\HtmlBlock::class) ->setConstructorArgs([HtmlBlock::TYPE_6_BLOCK_ELEMENT]) ->getMock(); @@ -93,8 +93,8 @@ public function testRenderEscapeHtml() $result = $this->renderer->render($block, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('<button class="test">Test</button>', $result); + $this->assertIsString($result); + $this->assertStringContainsString('<button class="test">Test</button>', $result); } public function testRenderStripHtml() @@ -103,7 +103,7 @@ public function testRenderStripHtml() 'html_input' => Environment::HTML_INPUT_STRIP, ])); - /** @var HtmlBlock|\PHPUnit_Framework_MockObject_MockObject $block */ + /** @var HtmlBlock|\PHPUnit\Framework\MockObject\MockObject $block */ $block = $this->getMockBuilder(\League\CommonMark\Block\Element\HtmlBlock::class) ->setConstructorArgs([HtmlBlock::TYPE_6_BLOCK_ELEMENT]) ->getMock(); @@ -115,15 +115,14 @@ public function testRenderStripHtml() $result = $this->renderer->render($block, $fakeRenderer); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertEquals('', $result); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Block/Renderer/IndentedCodeRendererTest.php b/tests/unit/Block/Renderer/IndentedCodeRendererTest.php index fae86b766e..627e5f9e99 100644 --- a/tests/unit/Block/Renderer/IndentedCodeRendererTest.php +++ b/tests/unit/Block/Renderer/IndentedCodeRendererTest.php @@ -31,7 +31,7 @@ class IndentedCodeRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new IndentedCodeRenderer(); } @@ -60,14 +60,13 @@ public function testRender() $this->assertEquals('code', $code->getTagName()); $this->assertNull($code->getAttribute('class')); $this->assertEquals(['id' => 'foo'], $code->getAllAttributes()); - $this->assertContains('hello world', $code->getContents(true)); + $this->assertStringContainsString('hello world', $code->getContents(true)); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Block/Renderer/ListBlockRendererTest.php b/tests/unit/Block/Renderer/ListBlockRendererTest.php index 2b6ef3218b..bd5a6db442 100644 --- a/tests/unit/Block/Renderer/ListBlockRendererTest.php +++ b/tests/unit/Block/Renderer/ListBlockRendererTest.php @@ -29,7 +29,7 @@ class ListBlockRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new ListBlockRenderer(); } @@ -50,7 +50,7 @@ public function testRenderOrderedList($listStart = null, $expectedAttributeValue $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('ol', $result->getTagName()); $this->assertSame($expectedAttributeValue, $result->getAttribute('start')); - $this->assertContains('::blocks::', $result->getContents(true)); + $this->assertStringContainsString('::blocks::', $result->getContents(true)); $this->assertEquals('foo', $result->getAttribute('id')); } @@ -74,15 +74,14 @@ public function testRenderUnorderedList() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('ul', $result->getTagName()); - $this->assertContains('::blocks::', $result->getContents(true)); + $this->assertStringContainsString('::blocks::', $result->getContents(true)); $this->assertEquals(['id' => 'foo'], $result->getAllAttributes()); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Block/Renderer/ListItemRendererTest.php b/tests/unit/Block/Renderer/ListItemRendererTest.php index 7ca67aa436..287ca021c0 100644 --- a/tests/unit/Block/Renderer/ListItemRendererTest.php +++ b/tests/unit/Block/Renderer/ListItemRendererTest.php @@ -29,7 +29,7 @@ class ListItemRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new ListItemRenderer(); } @@ -47,11 +47,10 @@ public function testRenderUnorderedList() $this->assertEquals('
  • ::blocks::
  • ', $result->__toString()); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Block/Renderer/ParagraphRendererTest.php b/tests/unit/Block/Renderer/ParagraphRendererTest.php index 7e60880a9d..62fdcd95ab 100644 --- a/tests/unit/Block/Renderer/ParagraphRendererTest.php +++ b/tests/unit/Block/Renderer/ParagraphRendererTest.php @@ -28,7 +28,7 @@ class ParagraphRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new ParagraphRenderer(); } @@ -43,15 +43,14 @@ public function testRender() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('p', $result->getTagName()); - $this->assertContains('::inlines::', $result->getContents(true)); + $this->assertStringContainsString('::inlines::', $result->getContents(true)); $this->assertEquals(['id' => 'foo'], $result->getAllAttributes()); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Block/Renderer/ThematicBreakRendererTest.php b/tests/unit/Block/Renderer/ThematicBreakRendererTest.php index e6ef7220a9..8d491b24a8 100644 --- a/tests/unit/Block/Renderer/ThematicBreakRendererTest.php +++ b/tests/unit/Block/Renderer/ThematicBreakRendererTest.php @@ -28,7 +28,7 @@ class ThematicBreakRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new ThematicBreakRenderer(); } @@ -44,11 +44,10 @@ public function testRender() $this->assertEquals('hr', $result->getTagName()); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(BlockElement\AbstractBlock::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/CommonMarkConverterTest.php b/tests/unit/CommonMarkConverterTest.php index 7f24f44df1..9679add0bf 100644 --- a/tests/unit/CommonMarkConverterTest.php +++ b/tests/unit/CommonMarkConverterTest.php @@ -17,6 +17,7 @@ use League\CommonMark\CommonMarkConverter; use League\CommonMark\ConfigurableEnvironmentInterface; use League\CommonMark\Environment; +use League\CommonMark\Exception\UnexpectedEncodingException; use League\CommonMark\Extension\CommonMarkCoreExtension; use PHPUnit\Framework\TestCase; @@ -61,11 +62,10 @@ public function testEnvironmentAndConfigConstructor() $this->assertSame($mockEnvironment, $environment); } - /** - * @expectedException \League\CommonMark\Exception\UnexpectedEncodingException - */ public function testConvertingInvalidUTF8() { + $this->expectException(UnexpectedEncodingException::class); + $converter = new CommonMarkConverter(); $converter->convertToHtml("\x09\xca\xca"); } diff --git a/tests/unit/ConverterTest.php b/tests/unit/ConverterTest.php index 85426facb2..8c37ee57bc 100644 --- a/tests/unit/ConverterTest.php +++ b/tests/unit/ConverterTest.php @@ -16,8 +16,10 @@ use League\CommonMark\Converter; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject; +/** + * @group legacy + */ class ConverterTest extends TestCase { public function testInvokeReturnsSameOutputAsConvertToHtml() @@ -25,7 +27,7 @@ public function testInvokeReturnsSameOutputAsConvertToHtml() $inputMarkdown = '**Strong**'; $expectedHtml = 'Strong'; - /** @var Converter|PHPUnit_Framework_MockObject_MockObject $converter */ + /** @var Converter|\PHPUnit\Framework\MockObject\MockObject $converter */ $converter = $this->getMockBuilder(Converter::class) ->disableOriginalConstructor() ->setMethods(['convertToHtml']) diff --git a/tests/unit/Delimiter/DelimiterProcessorCollectionTest.php b/tests/unit/Delimiter/DelimiterProcessorCollectionTest.php index e588944b3c..ef94418a8a 100644 --- a/tests/unit/Delimiter/DelimiterProcessorCollectionTest.php +++ b/tests/unit/Delimiter/DelimiterProcessorCollectionTest.php @@ -35,12 +35,11 @@ public function testAddNewProcessor() $this->assertSame($processor2, $collection->getDelimiterProcessor('_')); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Delim processor for character "*" already exists - */ public function testAddProcessorForCharacterAlreadyRegistered() { + $this->expectException(\InvalidArgumentException::class); + + $this->expectExceptionMessage('Delim processor for character "*" already exists'); $collection = new DelimiterProcessorCollection(); $processor1 = $this->getMockForAbstractClass(DelimiterProcessorInterface::class); diff --git a/tests/unit/DocParserTest.php b/tests/unit/DocParserTest.php index 5e5319fe3a..a887964ddb 100644 --- a/tests/unit/DocParserTest.php +++ b/tests/unit/DocParserTest.php @@ -13,15 +13,14 @@ use League\CommonMark\DocParser; use League\CommonMark\Environment; +use League\CommonMark\Exception\UnexpectedEncodingException; use PHPUnit\Framework\TestCase; class DocParserTest extends TestCase { - /** - * @expectedException \League\CommonMark\Exception\UnexpectedEncodingException - */ public function testParsingWithInvalidUTF8() { + $this->expectException(UnexpectedEncodingException::class); $environment = Environment::createCommonMarkEnvironment(); $docParser = new DocParser($environment); diff --git a/tests/unit/Environment/AbstractFakeInjectable.php b/tests/unit/Environment/AbstractFakeInjectable.php new file mode 100644 index 0000000000..1249c615c9 --- /dev/null +++ b/tests/unit/Environment/AbstractFakeInjectable.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\CommonMark\Tests\Unit\Environment; + +use League\CommonMark\EnvironmentAwareInterface; +use League\CommonMark\EnvironmentInterface; +use League\CommonMark\Util\ConfigurationAwareInterface; +use League\CommonMark\Util\ConfigurationInterface; + +abstract class AbstractFakeInjectable implements ConfigurationAwareInterface, EnvironmentAwareInterface +{ + /** @var ConfigurationInterface|null */ + private $config; + + /** @var EnvironmentInterface|null */ + private $environment; + + public function setConfiguration(ConfigurationInterface $configuration) + { + $this->config = $configuration; + } + + public function setEnvironment(EnvironmentInterface $environment) + { + $this->environment = $environment; + } + + public function getConfig(): ?ConfigurationInterface + { + return $this->config; + } + + public function getEnvironment(): ?EnvironmentInterface + { + return $this->environment; + } +} diff --git a/tests/unit/Environment/FakeBlockParser.php b/tests/unit/Environment/FakeBlockParser.php new file mode 100644 index 0000000000..dc6b26b182 --- /dev/null +++ b/tests/unit/Environment/FakeBlockParser.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\CommonMark\Tests\Unit\Environment; + +use League\CommonMark\Block\Parser\BlockParserInterface; +use League\CommonMark\ContextInterface; +use League\CommonMark\Cursor; + +class FakeBlockParser extends AbstractFakeInjectable implements BlockParserInterface +{ + public function parse(ContextInterface $context, Cursor $cursor): bool + { + return false; + } +} diff --git a/tests/unit/Environment/FakeBlockRenderer.php b/tests/unit/Environment/FakeBlockRenderer.php new file mode 100644 index 0000000000..fd808e79b8 --- /dev/null +++ b/tests/unit/Environment/FakeBlockRenderer.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\CommonMark\Tests\Unit\Environment; + +use League\CommonMark\Block\Element\AbstractBlock; +use League\CommonMark\Block\Renderer\BlockRendererInterface; +use League\CommonMark\ElementRendererInterface; + +class FakeBlockRenderer extends AbstractFakeInjectable implements BlockRendererInterface +{ + public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false) + { + return ''; + } +} diff --git a/tests/unit/Environment/FakeDelimiterProcessor.php b/tests/unit/Environment/FakeDelimiterProcessor.php new file mode 100644 index 0000000000..42a424e868 --- /dev/null +++ b/tests/unit/Environment/FakeDelimiterProcessor.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\CommonMark\Tests\Unit\Environment; + +use League\CommonMark\Delimiter\DelimiterInterface; +use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface; +use League\CommonMark\Inline\Element\AbstractStringContainer; + +class FakeDelimiterProcessor extends AbstractFakeInjectable implements DelimiterProcessorInterface +{ + public function getOpeningCharacter(): string + { + return '['; + } + + public function getClosingCharacter(): string + { + return ']'; + } + + public function getMinLength(): int + { + return 1; + } + + public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int + { + return 1; + } + + public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse) + { + } +} diff --git a/tests/unit/Environment/FakeInlineParser.php b/tests/unit/Environment/FakeInlineParser.php new file mode 100644 index 0000000000..41b383ba3d --- /dev/null +++ b/tests/unit/Environment/FakeInlineParser.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\CommonMark\Tests\Unit\Environment; + +use League\CommonMark\Inline\Parser\InlineParserInterface; +use League\CommonMark\InlineParserContext; + +class FakeInlineParser extends AbstractFakeInjectable implements InlineParserInterface +{ + public function getCharacters(): array + { + return []; + } + + public function parse(InlineParserContext $inlineContext): bool + { + return false; + } +} diff --git a/tests/unit/Environment/FakeInlineRenderer.php b/tests/unit/Environment/FakeInlineRenderer.php new file mode 100644 index 0000000000..3920cf5630 --- /dev/null +++ b/tests/unit/Environment/FakeInlineRenderer.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\CommonMark\Tests\Unit\Environment; + +use League\CommonMark\ElementRendererInterface; +use League\CommonMark\Inline\Element\AbstractInline; +use League\CommonMark\Inline\Renderer\InlineRendererInterface; + +class FakeInlineRenderer extends AbstractFakeInjectable implements InlineRendererInterface +{ + public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) + { + return ''; + } +} diff --git a/tests/unit/EnvironmentTest.php b/tests/unit/EnvironmentTest.php index 5a2726bddd..4c45c440ab 100644 --- a/tests/unit/EnvironmentTest.php +++ b/tests/unit/EnvironmentTest.php @@ -19,19 +19,22 @@ use League\CommonMark\Block\Renderer\BlockRendererInterface; use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface; use League\CommonMark\Environment; -use League\CommonMark\EnvironmentAwareInterface; use League\CommonMark\Event\AbstractEvent; use League\CommonMark\Extension\ExtensionInterface; use League\CommonMark\Inline\Parser\InlineParserInterface; use League\CommonMark\Inline\Renderer\InlineRendererInterface; use League\CommonMark\Tests\Unit\Environment\FakeBlock1; use League\CommonMark\Tests\Unit\Environment\FakeBlock3; +use League\CommonMark\Tests\Unit\Environment\FakeBlockParser; +use League\CommonMark\Tests\Unit\Environment\FakeBlockRenderer; +use League\CommonMark\Tests\Unit\Environment\FakeDelimiterProcessor; use League\CommonMark\Tests\Unit\Environment\FakeInline1; use League\CommonMark\Tests\Unit\Environment\FakeInline3; +use League\CommonMark\Tests\Unit\Environment\FakeInlineParser; +use League\CommonMark\Tests\Unit\Environment\FakeInlineRenderer; use League\CommonMark\Tests\Unit\Event\FakeEvent; use League\CommonMark\Tests\Unit\Event\FakeEventListener; use League\CommonMark\Tests\Unit\Event\FakeEventListenerInvokable; -use League\CommonMark\Util\ConfigurationAwareInterface; use PHPUnit\Framework\TestCase; class EnvironmentTest extends TestCase @@ -117,7 +120,7 @@ public function testSetConfig() public function testSetConfigAfterInit() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $environment = new Environment(); // This triggers the initialization @@ -135,7 +138,7 @@ public function testMergeConfig() public function testMergeConfigAfterInit() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $environment = new Environment(); // This triggers the initialization @@ -153,11 +156,9 @@ public function testAddBlockParserAndGetter() $this->assertContains($parser, $environment->getBlockParsers()); } - /** - * @expectedException \RuntimeException - */ public function testAddBlockParserFailsAfterInitialization() { + $this->expectException(\RuntimeException::class); $environment = new Environment(); // This triggers the initialization @@ -177,11 +178,9 @@ public function testAddBlockRenderer() $this->assertContains($renderer, $environment->getBlockRenderersForClass('MyClass')); } - /** - * @expectedException \RuntimeException - */ public function testAddBlockRendererFailsAfterInitialization() { + $this->expectException(\RuntimeException::class); $environment = new Environment(); // This triggers the initialization @@ -206,11 +205,9 @@ public function testInlineParserCanMatchRegexDelimiter() $this->assertEquals(1, preg_match($environment->getInlineParserCharacterRegex(), 'foo/bar')); } - /** - * @expectedException \RuntimeException - */ public function testAddInlineParserFailsAfterInitialization() { + $this->expectException(\RuntimeException::class); $environment = new Environment(); // This triggers the initialization @@ -252,11 +249,9 @@ public function testAddDelimiterProcessor() $this->assertSame($processor, $environment->getDelimiterProcessors()->getDelimiterProcessor('*')); } - /** - * @expectedException \RuntimeException - */ public function testAddDelimiterProcessorFailsAfterInitialization() { + $this->expectException(\RuntimeException::class); $environment = new Environment(); // This triggers the initialization @@ -276,11 +271,9 @@ public function testAddInlineRenderer() $this->assertContains($renderer, $environment->getInlineRenderersForClass('MyClass')); } - /** - * @expectedException \RuntimeException - */ public function testAddInlineRendererFailsAfterInitialization() { + $this->expectException(\RuntimeException::class); $environment = new Environment(); // This triggers the initialization @@ -342,11 +335,9 @@ public function testAddExtensionAndGetter() $this->assertContains($extension, $environment->getExtensions()); } - /** - * @expectedException \RuntimeException - */ public function testAddExtensionFailsAfterInitialization() { + $this->expectException(\RuntimeException::class); $environment = new Environment(); // This triggers the initialization @@ -375,70 +366,70 @@ public function testInjectableBlockParsersGetInjected() { $environment = new Environment(); - $parser = $this->getMockBuilder([BlockParserInterface::class, EnvironmentAwareInterface::class, ConfigurationAwareInterface::class])->getMock(); - $parser->expects($this->once())->method('setEnvironment')->with($environment); - $parser->expects($this->once())->method('setConfiguration'); - + $parser = new FakeBlockParser(); $environment->addBlockParser($parser); // Trigger initialization $environment->getBlockParsers(); + + $this->assertSame($environment, $parser->getEnvironment()); + $this->assertNotNull($parser->getConfig()); } public function testInjectableBlockRenderersGetInjected() { $environment = new Environment(); - $renderer = $this->getMockBuilder([BlockRendererInterface::class, EnvironmentAwareInterface::class, ConfigurationAwareInterface::class])->getMock(); - $renderer->expects($this->once())->method('setEnvironment')->with($environment); - $renderer->expects($this->once())->method('setConfiguration'); - + $renderer = new FakeBlockRenderer(); $environment->addBlockRenderer('', $renderer); // Trigger initialization $environment->getBlockParsers(); + + $this->assertSame($environment, $renderer->getEnvironment()); + $this->assertNotNull($renderer->getConfig()); } public function testInjectableInlineParsersGetInjected() { $environment = new Environment(); - $parser = $this->getMockBuilder([InlineParserInterface::class, EnvironmentAwareInterface::class, ConfigurationAwareInterface::class])->getMock(); - $parser->expects($this->once())->method('setEnvironment')->with($environment); - $parser->expects($this->once())->method('setConfiguration'); - + $parser = new FakeInlineParser(); $environment->addInlineParser($parser); // Trigger initialization $environment->getBlockParsers(); + + $this->assertSame($environment, $parser->getEnvironment()); + $this->assertNotNull($parser->getConfig()); } public function testInjectableInlineRenderersGetInjected() { $environment = new Environment(); - $renderer = $this->getMockBuilder([InlineRendererInterface::class, EnvironmentAwareInterface::class, ConfigurationAwareInterface::class])->getMock(); - $renderer->expects($this->once())->method('setEnvironment')->with($environment); - $renderer->expects($this->once())->method('setConfiguration'); - + $renderer = new FakeInlineRenderer(); $environment->addInlineRenderer('', $renderer); // Trigger initialization $environment->getBlockParsers(); + + $this->assertSame($environment, $renderer->getEnvironment()); + $this->assertNotNull($renderer->getConfig()); } public function testInjectableDelimiterProcessorsGetInjected() { $environment = new Environment(); - $processor = $this->getMockBuilder([DelimiterProcessorInterface::class, EnvironmentAwareInterface::class, ConfigurationAwareInterface::class])->getMock(); - $processor->expects($this->once())->method('setEnvironment')->with($environment); - $processor->expects($this->once())->method('setConfiguration'); - + $processor = new FakeDelimiterProcessor(); $environment->addDelimiterProcessor($processor); // Trigger initialization $environment->getBlockParsers(); + + $this->assertSame($environment, $processor->getEnvironment()); + $this->assertNotNull($processor->getConfig()); } public function testInjectableEventListenersGetInjected() @@ -575,11 +566,9 @@ public function testEventDispatching() $this->assertEquals('b', $actualOrder[2]); } - /** - * @expectedException \RuntimeException - */ public function testAddEventListenerFailsAfterInitialization() { + $this->expectException(\RuntimeException::class); $environment = new Environment(); $event = $this->createMock(AbstractEvent::class); diff --git a/tests/unit/Extension/Autolink/InlineMentionParserTest.php b/tests/unit/Extension/Autolink/InlineMentionParserTest.php index 19b5472e6e..e3bc1ce876 100644 --- a/tests/unit/Extension/Autolink/InlineMentionParserTest.php +++ b/tests/unit/Extension/Autolink/InlineMentionParserTest.php @@ -18,6 +18,8 @@ /** * @deprecated + * + * @group legacy */ final class InlineMentionParserTest extends TestCase { diff --git a/tests/unit/Extension/HeadingPermalink/Slug/DefaultSlugGeneratorTest.php b/tests/unit/Extension/HeadingPermalink/Slug/DefaultSlugGeneratorTest.php index ababd43232..35f5ebb8ef 100644 --- a/tests/unit/Extension/HeadingPermalink/Slug/DefaultSlugGeneratorTest.php +++ b/tests/unit/Extension/HeadingPermalink/Slug/DefaultSlugGeneratorTest.php @@ -16,6 +16,8 @@ /** * @deprecated + * + * @group legacy */ final class DefaultSlugGeneratorTest extends TestCase { diff --git a/tests/unit/Extension/SmartPunct/QuoteRendererTest.php b/tests/unit/Extension/SmartPunct/QuoteRendererTest.php index e5c8b9c9a8..7a50a68456 100644 --- a/tests/unit/Extension/SmartPunct/QuoteRendererTest.php +++ b/tests/unit/Extension/SmartPunct/QuoteRendererTest.php @@ -31,17 +31,16 @@ final class QuoteRendererTest extends TestCase /** @var ElementRendererInterface */ private $htmlRenderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new QuoteRenderer(); $this->htmlRenderer = $this->createMock(ElementRendererInterface::class); } - /** - * @expectedException \InvalidArgumentException - */ public function testInvalidInlineType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->createMock(Text::class); $this->renderer->render($inline, $this->htmlRenderer); diff --git a/tests/unit/Extension/SmartPunct/SmartPunctExtensionTest.php b/tests/unit/Extension/SmartPunct/SmartPunctExtensionTest.php index 69b74268a4..faf5bf4612 100644 --- a/tests/unit/Extension/SmartPunct/SmartPunctExtensionTest.php +++ b/tests/unit/Extension/SmartPunct/SmartPunctExtensionTest.php @@ -29,7 +29,7 @@ final class SmartPunctExtensionTest extends TestCase */ protected $environment; - protected function setUp() + protected function setUp(): void { $this->environment = Environment::createCommonMarkEnvironment(); $this->environment->addExtension(new SmartPunctExtension()); diff --git a/tests/unit/Extension/Strikethrough/StrikethroughRendererTest.php b/tests/unit/Extension/Strikethrough/StrikethroughRendererTest.php index dce334e94b..cf0ff27af9 100644 --- a/tests/unit/Extension/Strikethrough/StrikethroughRendererTest.php +++ b/tests/unit/Extension/Strikethrough/StrikethroughRendererTest.php @@ -25,7 +25,7 @@ class StrikethroughRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new StrikethroughRenderer(); } @@ -40,15 +40,14 @@ public function testRender() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('del', $result->getTagName()); - $this->assertContains('::inlines::', $result->getContents(true)); + $this->assertStringContainsString('::inlines::', $result->getContents(true)); $this->assertEquals(['id' => 'some"&id'], $result->getAllAttributes()); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidNodeType() { + $this->expectException(\InvalidArgumentException::class); + $inline = new Text('ruh roh'); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Extension/TableOfContents/TableOfContentsDeprecationTest.php b/tests/unit/Extension/TableOfContents/TableOfContentsDeprecationTest.php index 76bf955ce2..0676101aee 100644 --- a/tests/unit/Extension/TableOfContents/TableOfContentsDeprecationTest.php +++ b/tests/unit/Extension/TableOfContents/TableOfContentsDeprecationTest.php @@ -16,6 +16,9 @@ use League\CommonMark\Extension\TableOfContents\TableOfContents as DeprecatedTableOfContents; use PHPUnit\Framework\TestCase; +/** + * @group legacy + */ final class TableOfContentsDeprecationTest extends TestCase { /** diff --git a/tests/unit/Extension/TaskList/TaskListItemMarkerRendererTest.php b/tests/unit/Extension/TaskList/TaskListItemMarkerRendererTest.php index 7b3ed8bba7..82fcd3033b 100644 --- a/tests/unit/Extension/TaskList/TaskListItemMarkerRendererTest.php +++ b/tests/unit/Extension/TaskList/TaskListItemMarkerRendererTest.php @@ -50,11 +50,10 @@ public function testWithUncheckedItem() $this->assertNull($result->getAttribute('checked')); } - /** - * @expectedException \InvalidArgumentException - */ public function testWithInvalidInlineElement() { + $this->expectException(\InvalidArgumentException::class); + $renderer = new TaskListItemMarkerRenderer(); $htmlRenderer = $this->getMockForAbstractClass(ElementRendererInterface::class); diff --git a/tests/unit/HtmlElementTest.php b/tests/unit/HtmlElementTest.php index 3db08838c0..000091364b 100644 --- a/tests/unit/HtmlElementTest.php +++ b/tests/unit/HtmlElementTest.php @@ -89,7 +89,7 @@ public function testToString() $div = new HtmlElement('div'); $div->setContents([$p, $img]); - $this->assertInternalType('string', $div->getContents(true)); + $this->assertIsString($div->getContents(true)); $this->assertEquals('

    ', $div->getContents(true)); $this->assertEquals('

    ', $div->__toString()); diff --git a/tests/unit/HtmlRendererTest.php b/tests/unit/HtmlRendererTest.php index 9c0d082023..8021a93c80 100644 --- a/tests/unit/HtmlRendererTest.php +++ b/tests/unit/HtmlRendererTest.php @@ -24,11 +24,9 @@ public function testRenderBlock() $renderer->renderBlock(new Paragraph()); } - /** - * @expectedException \RuntimeException - */ public function testRenderBlockWithMissingRenderer() { + $this->expectException(\RuntimeException::class); $environment = $this->createMock(EnvironmentInterface::class); $environment->method('getBlockRenderersForClass')->willReturn([]); @@ -48,11 +46,10 @@ public function testRenderInline() $renderer->renderInline(new Text()); } - /** - * @expectedException \RuntimeException - */ public function testRenderInlineWithMissingRenderer() { + $this->expectException(\RuntimeException::class); + $environment = $this->createMock(EnvironmentInterface::class); $environment->method('getInlineRenderersForClass')->willReturn([]); diff --git a/tests/unit/Inline/Renderer/CodeRendererTest.php b/tests/unit/Inline/Renderer/CodeRendererTest.php index 9237392ae4..7cd57f6e59 100644 --- a/tests/unit/Inline/Renderer/CodeRendererTest.php +++ b/tests/unit/Inline/Renderer/CodeRendererTest.php @@ -28,7 +28,7 @@ class CodeRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new CodeRenderer(); } @@ -43,15 +43,14 @@ public function testRender() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('code', $result->getTagName()); - $this->assertContains('echo "hello world";', $result->getContents(true)); + $this->assertStringContainsString('echo "hello world";', $result->getContents(true)); $this->assertEquals(['id' => 'foo'], $result->getAllAttributes()); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(InlineElement\AbstractInline::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Inline/Renderer/EmphasisRendererTest.php b/tests/unit/Inline/Renderer/EmphasisRendererTest.php index d21e2d0984..c0cf15d140 100644 --- a/tests/unit/Inline/Renderer/EmphasisRendererTest.php +++ b/tests/unit/Inline/Renderer/EmphasisRendererTest.php @@ -28,7 +28,7 @@ class EmphasisRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new EmphasisRenderer(); } @@ -43,15 +43,14 @@ public function testRender() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('em', $result->getTagName()); - $this->assertContains('::inlines::', $result->getContents(true)); + $this->assertStringContainsString('::inlines::', $result->getContents(true)); $this->assertEquals(['id' => 'foo'], $result->getAllAttributes()); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(InlineElement\AbstractInline::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Inline/Renderer/HtmlInlineRendererTest.php b/tests/unit/Inline/Renderer/HtmlInlineRendererTest.php index 8b3126bef1..601e276ff5 100644 --- a/tests/unit/Inline/Renderer/HtmlInlineRendererTest.php +++ b/tests/unit/Inline/Renderer/HtmlInlineRendererTest.php @@ -29,7 +29,7 @@ class HtmlInlineRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new HtmlInlineRenderer(); $this->renderer->setConfiguration(new Configuration()); @@ -42,8 +42,8 @@ public function testRender() $result = $this->renderer->render($inline, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('

    Test

    ', $result); + $this->assertIsString($result); + $this->assertStringContainsString('

    Test

    ', $result); } public function testRenderAllowHtml() @@ -57,8 +57,8 @@ public function testRenderAllowHtml() $result = $this->renderer->render($inline, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('

    Test

    ', $result); + $this->assertIsString($result); + $this->assertStringContainsString('

    Test

    ', $result); } public function testRenderEscapeHtml() @@ -72,8 +72,8 @@ public function testRenderEscapeHtml() $result = $this->renderer->render($inline, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('<h1 class="test">Test</h1>', $result); + $this->assertIsString($result); + $this->assertStringContainsString('<h1 class="test">Test</h1>', $result); } public function testRenderStripHtml() @@ -87,15 +87,14 @@ public function testRenderStripHtml() $result = $this->renderer->render($inline, $fakeRenderer); - $this->assertInternalType('string', $result); + $this->assertIsString($result); $this->assertEquals('', $result); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(InlineElement\AbstractInline::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Inline/Renderer/ImageRendererTest.php b/tests/unit/Inline/Renderer/ImageRendererTest.php index 8939907207..0bca9dc53d 100644 --- a/tests/unit/Inline/Renderer/ImageRendererTest.php +++ b/tests/unit/Inline/Renderer/ImageRendererTest.php @@ -29,7 +29,7 @@ class ImageRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new ImageRenderer(); $this->renderer->setConfiguration(new Configuration()); @@ -45,11 +45,11 @@ public function testRenderWithTitle() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('img', $result->getTagName()); - $this->assertContains('http://example.com/foo.jpg', $result->getAttribute('src')); - $this->assertContains('foo.jpg', $result->getAttribute('src')); - $this->assertContains('::inlines::', $result->getAttribute('alt')); - $this->assertContains('::title::', $result->getAttribute('title')); - $this->assertContains('::id::', $result->getAttribute('id')); + $this->assertStringContainsString('http://example.com/foo.jpg', $result->getAttribute('src')); + $this->assertStringContainsString('foo.jpg', $result->getAttribute('src')); + $this->assertStringContainsString('::inlines::', $result->getAttribute('alt')); + $this->assertStringContainsString('::title::', $result->getAttribute('title')); + $this->assertStringContainsString('::id::', $result->getAttribute('id')); } public function testRenderWithoutTitle() @@ -61,9 +61,9 @@ public function testRenderWithoutTitle() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('img', $result->getTagName()); - $this->assertContains('http://example.com/foo.jpg', $result->getAttribute('src')); - $this->assertContains('foo.jpg', $result->getAttribute('src')); - $this->assertContains('::inlines::', $result->getAttribute('alt')); + $this->assertStringContainsString('http://example.com/foo.jpg', $result->getAttribute('src')); + $this->assertStringContainsString('foo.jpg', $result->getAttribute('src')); + $this->assertStringContainsString('::inlines::', $result->getAttribute('alt')); $this->assertNull($result->getAttribute('title')); } @@ -79,7 +79,7 @@ public function testRenderAllowUnsafeLink() $result = $this->renderer->render($inline, $fakeRenderer); $this->assertTrue($result instanceof HtmlElement); - $this->assertContains('javascript:void(0)', $result->getAttribute('src')); + $this->assertStringContainsString('javascript:void(0)', $result->getAttribute('src')); } public function testRenderDisallowUnsafeLink() @@ -97,11 +97,10 @@ public function testRenderDisallowUnsafeLink() $this->assertEquals('', $result->getAttribute('src')); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(InlineElement\AbstractInline::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Inline/Renderer/LinkRendererTest.php b/tests/unit/Inline/Renderer/LinkRendererTest.php index 3e36e7fa24..1eaf29ac5c 100644 --- a/tests/unit/Inline/Renderer/LinkRendererTest.php +++ b/tests/unit/Inline/Renderer/LinkRendererTest.php @@ -29,7 +29,7 @@ class LinkRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new LinkRenderer(); $this->renderer->setConfiguration(new Configuration()); @@ -45,10 +45,10 @@ public function testRenderWithTitle() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('a', $result->getTagName()); - $this->assertContains('http://example.com/foo.html', $result->getAttribute('href')); - $this->assertContains('::title::', $result->getAttribute('title')); - $this->assertContains('::inlines::', $result->getContents(true)); - $this->assertContains('::id::', $result->getAttribute('id')); + $this->assertStringContainsString('http://example.com/foo.html', $result->getAttribute('href')); + $this->assertStringContainsString('::title::', $result->getAttribute('title')); + $this->assertStringContainsString('::inlines::', $result->getContents(true)); + $this->assertStringContainsString('::id::', $result->getAttribute('id')); } public function testRenderWithoutTitle() @@ -60,9 +60,9 @@ public function testRenderWithoutTitle() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('a', $result->getTagName()); - $this->assertContains('http://example.com/foo.html', $result->getAttribute('href')); + $this->assertStringContainsString('http://example.com/foo.html', $result->getAttribute('href')); $this->assertNull($result->getAttribute('title')); - $this->assertContains('::inlines::', $result->getContents(true)); + $this->assertStringContainsString('::inlines::', $result->getContents(true)); } public function testRenderAllowUnsafeLink() @@ -77,7 +77,7 @@ public function testRenderAllowUnsafeLink() $result = $this->renderer->render($inline, $fakeRenderer); $this->assertTrue($result instanceof HtmlElement); - $this->assertContains('javascript:void(0)', $result->getAttribute('href')); + $this->assertStringContainsString('javascript:void(0)', $result->getAttribute('href')); } public function testRenderDisallowUnsafeLink() @@ -95,11 +95,10 @@ public function testRenderDisallowUnsafeLink() $this->assertEquals('', $result->getAttribute('href')); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(InlineElement\AbstractInline::class); $fakeRenderer = new FakeHtmlRenderer(); @@ -116,8 +115,8 @@ public function testRenderWithExternalTarget() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('a', $result->getTagName()); - $this->assertContains('http://example.com/foo.html', $result->getAttribute('href')); - $this->assertContains('noopener', $result->getAttribute('rel')); - $this->assertContains('noreferrer', $result->getAttribute('rel')); + $this->assertStringContainsString('http://example.com/foo.html', $result->getAttribute('href')); + $this->assertStringContainsString('noopener', $result->getAttribute('rel')); + $this->assertStringContainsString('noreferrer', $result->getAttribute('rel')); } } diff --git a/tests/unit/Inline/Renderer/NewlineRendererTest.php b/tests/unit/Inline/Renderer/NewlineRendererTest.php index df38466b16..571800ceb9 100644 --- a/tests/unit/Inline/Renderer/NewlineRendererTest.php +++ b/tests/unit/Inline/Renderer/NewlineRendererTest.php @@ -27,7 +27,7 @@ class NewlineRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new NewlineRenderer(); } @@ -39,8 +39,8 @@ public function testRenderHardbreak() $result = $this->renderer->render($inline, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('
    ', $result); + $this->assertIsString($result); + $this->assertStringContainsString('
    ', $result); } public function testRenderSoftbreak() @@ -51,15 +51,14 @@ public function testRenderSoftbreak() $result = $this->renderer->render($inline, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('::softbreakChar::', $result); + $this->assertIsString($result); + $this->assertStringContainsString('::softbreakChar::', $result); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(InlineElement\AbstractInline::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Inline/Renderer/StrongRendererTest.php b/tests/unit/Inline/Renderer/StrongRendererTest.php index 55b9ae4fbd..2cc3cb5b65 100644 --- a/tests/unit/Inline/Renderer/StrongRendererTest.php +++ b/tests/unit/Inline/Renderer/StrongRendererTest.php @@ -28,7 +28,7 @@ class StrongRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new StrongRenderer(); } @@ -43,15 +43,14 @@ public function testRender() $this->assertTrue($result instanceof HtmlElement); $this->assertEquals('strong', $result->getTagName()); - $this->assertContains('::inlines::', $result->getContents(true)); + $this->assertStringContainsString('::inlines::', $result->getContents(true)); $this->assertEquals(['id' => 'foo'], $result->getAllAttributes()); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(InlineElement\AbstractInline::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/Inline/Renderer/TextRendererTest.php b/tests/unit/Inline/Renderer/TextRendererTest.php index b0b9ba6129..1e6e072961 100644 --- a/tests/unit/Inline/Renderer/TextRendererTest.php +++ b/tests/unit/Inline/Renderer/TextRendererTest.php @@ -27,7 +27,7 @@ class TextRendererTest extends TestCase */ protected $renderer; - protected function setUp() + protected function setUp(): void { $this->renderer = new TextRenderer(); } @@ -39,15 +39,14 @@ public function testRender() $result = $this->renderer->render($inline, $fakeRenderer); - $this->assertInternalType('string', $result); - $this->assertContains('foo bar', $result); + $this->assertIsString($result); + $this->assertStringContainsString('foo bar', $result); } - /** - * @expectedException \InvalidArgumentException - */ public function testRenderWithInvalidType() { + $this->expectException(\InvalidArgumentException::class); + $inline = $this->getMockForAbstractClass(InlineElement\AbstractInline::class); $fakeRenderer = new FakeHtmlRenderer(); diff --git a/tests/unit/UnmatchedBlockCloserTest.php b/tests/unit/UnmatchedBlockCloserTest.php index 209fcb3113..0088a46a8b 100644 --- a/tests/unit/UnmatchedBlockCloserTest.php +++ b/tests/unit/UnmatchedBlockCloserTest.php @@ -36,11 +36,10 @@ public function testResetTip() $this->assertTrue($closer->areAllClosed()); } - /** - * @expectedException \RuntimeException - */ public function testResetTipWithNullTip() { + $this->expectException(\RuntimeException::class); + $context = $this->getMockForAbstractClass(ContextInterface::class); $context->method('getTip')->willReturn(null); diff --git a/tests/unit/Util/ArrayCollectionTest.php b/tests/unit/Util/ArrayCollectionTest.php index 02a75e2180..84f744f9db 100644 --- a/tests/unit/Util/ArrayCollectionTest.php +++ b/tests/unit/Util/ArrayCollectionTest.php @@ -52,6 +52,9 @@ public function testGetIterator() $this->assertEquals($array, $iterator->getArrayCopy()); } + /** + * @group legacy + */ public function testAdd() { $collection = new ArrayCollection(); @@ -64,6 +67,9 @@ public function testAdd() $this->assertEquals(['foo', 'bar'], $collection->toArray()); } + /** + * @group legacy + */ public function testSet() { $collection = new ArrayCollection(['foo']); @@ -76,6 +82,9 @@ public function testSet() $this->assertEquals(['foo', 'foo' => 2], $collection->toArray()); } + /** + * @group legacy + */ public function testGet() { $collection = new ArrayCollection(['foo' => 1, 'bar']); @@ -85,6 +94,9 @@ public function testGet() $this->assertNull($collection->get('bar')); } + /** + * @group legacy + */ public function testRemove() { $collection = new ArrayCollection(['foo' => 1, 'bar', 'baz']); @@ -106,6 +118,9 @@ public function testRemove() $this->assertEquals([], $collection->toArray()); } + /** + * @group legacy + */ public function testRemoveNulls() { $collection = new ArrayCollection(['foo' => null]); @@ -119,6 +134,9 @@ public function testRemoveNulls() $this->assertEquals([], $collection->toArray()); } + /** + * @group legacy + */ public function testIsEmpty() { $collection = new ArrayCollection(); @@ -135,6 +153,9 @@ public function testIsEmpty() $this->assertFalse($collection->isEmpty()); } + /** + * @group legacy + */ public function testContains() { $object = new \stdClass(); @@ -155,6 +176,9 @@ public function testContains() $this->assertFalse($collection->contains('FOO')); } + /** + * @group legacy + */ public function testIndexOf() { $object = new \stdClass(); @@ -175,6 +199,9 @@ public function testIndexOf() $this->assertTrue(false === $collection->indexOf('FOO')); } + /** + * @group legacy + */ public function testContainsKey() { $collection = new ArrayCollection(['foo' => 1, 'bar']); @@ -197,10 +224,10 @@ public function testCount() $collection = new ArrayCollection(['foo']); $this->assertEquals(1, $collection->count()); - $collection->add('bar'); + $collection[] = 'bar'; $this->assertEquals(2, $collection->count()); - $collection->remove(0); + unset($collection[0]); $this->assertEquals(1, $collection->count()); } @@ -320,6 +347,9 @@ public function testToArray() $this->assertEquals([2 => 1, 'foo'], $collection->toArray()); } + /** + * @group legacy + */ public function testReplaceWith() { $collection = new ArrayCollection(['foo' => 1, 'bar']); @@ -330,6 +360,9 @@ public function testReplaceWith() $this->assertEquals(['baz', 42], $replaced->toArray()); } + /** + * @group legacy + */ public function testRemoveGaps() { $collection = new ArrayCollection(['', true, false, null, [], 0, '0', 1]); diff --git a/tests/unit/Util/Html5EntitiesTest.php b/tests/unit/Util/Html5EntitiesTest.php index f88b7ea2e1..335dfa6d98 100644 --- a/tests/unit/Util/Html5EntitiesTest.php +++ b/tests/unit/Util/Html5EntitiesTest.php @@ -5,6 +5,9 @@ use League\CommonMark\Util\Html5Entities; use PHPUnit\Framework\TestCase; +/** + * @group legacy + */ class Html5EntitiesTest extends TestCase { public function testEntityToChar() diff --git a/tests/unit/Util/RegexHelperTest.php b/tests/unit/Util/RegexHelperTest.php index 3c4c0af398..9597042914 100644 --- a/tests/unit/Util/RegexHelperTest.php +++ b/tests/unit/Util/RegexHelperTest.php @@ -23,246 +23,246 @@ class RegexHelperTest extends TestCase public function testEscapable() { $regex = '/^' . RegexHelper::PARTIAL_ESCAPABLE . '$/'; - $this->assertRegExp($regex, '&'); - $this->assertRegExp($regex, '/'); - $this->assertRegExp($regex, '\\'); - $this->assertRegExp($regex, '('); - $this->assertRegExp($regex, ')'); + $this->assertRegexMatches($regex, '&'); + $this->assertRegexMatches($regex, '/'); + $this->assertRegexMatches($regex, '\\'); + $this->assertRegexMatches($regex, '('); + $this->assertRegexMatches($regex, ')'); } public function testEscapedChar() { $regex = '/^' . RegexHelper::PARTIAL_ESCAPED_CHAR . '$/'; - $this->assertRegExp($regex, '\\&'); - $this->assertRegExp($regex, '\\/'); - $this->assertRegExp($regex, '\\\\'); - $this->assertRegExp($regex, '\)'); - $this->assertRegExp($regex, '\('); + $this->assertRegexMatches($regex, '\\&'); + $this->assertRegexMatches($regex, '\\/'); + $this->assertRegexMatches($regex, '\\\\'); + $this->assertRegexMatches($regex, '\)'); + $this->assertRegexMatches($regex, '\('); } public function testInDoubleQuotes() { $regex = '/^' . RegexHelper::PARTIAL_IN_DOUBLE_QUOTES . '$/'; - $this->assertRegExp($regex, '"\\&"'); - $this->assertRegExp($regex, '"\\/"'); - $this->assertRegExp($regex, '"\\\\"'); + $this->assertRegexMatches($regex, '"\\&"'); + $this->assertRegexMatches($regex, '"\\/"'); + $this->assertRegexMatches($regex, '"\\\\"'); } public function testInSingleQuotes() { $regex = '/^' . RegexHelper::PARTIAL_IN_SINGLE_QUOTES . '$/'; - $this->assertRegExp($regex, '\'\\&\''); - $this->assertRegExp($regex, '\'\\/\''); - $this->assertRegExp($regex, '\'\\\\\''); + $this->assertRegexMatches($regex, '\'\\&\''); + $this->assertRegexMatches($regex, '\'\\/\''); + $this->assertRegexMatches($regex, '\'\\\\\''); } public function testInParens() { $regex = '/^' . RegexHelper::PARTIAL_IN_PARENS . '$/'; - $this->assertRegExp($regex, '(\\&)'); - $this->assertRegExp($regex, '(\\/)'); - $this->assertRegExp($regex, '(\\\\)'); + $this->assertRegexMatches($regex, '(\\&)'); + $this->assertRegexMatches($regex, '(\\/)'); + $this->assertRegexMatches($regex, '(\\\\)'); } public function testRegChar() { $regex = '/^' . RegexHelper::PARTIAL_REG_CHAR . '$/'; - $this->assertRegExp($regex, 'a'); - $this->assertRegExp($regex, 'A'); - $this->assertRegExp($regex, '!'); - $this->assertNotRegExp($regex, ' '); + $this->assertRegexMatches($regex, 'a'); + $this->assertRegexMatches($regex, 'A'); + $this->assertRegexMatches($regex, '!'); + $this->assertRegexDoesNotMatch($regex, ' '); } public function testInParensNoSp() { $regex = '/^' . RegexHelper::PARTIAL_IN_PARENS_NOSP . '$/'; - $this->assertRegExp($regex, '(a)'); - $this->assertRegExp($regex, '(A)'); - $this->assertRegExp($regex, '(!)'); - $this->assertNotRegExp($regex, '(a )'); + $this->assertRegexMatches($regex, '(a)'); + $this->assertRegexMatches($regex, '(A)'); + $this->assertRegexMatches($regex, '(!)'); + $this->assertRegexDoesNotMatch($regex, '(a )'); } public function testTagname() { $regex = '/^' . RegexHelper::PARTIAL_TAGNAME . '$/'; - $this->assertRegExp($regex, 'a'); - $this->assertRegExp($regex, 'img'); - $this->assertRegExp($regex, 'h1'); - $this->assertNotRegExp($regex, '11'); + $this->assertRegexMatches($regex, 'a'); + $this->assertRegexMatches($regex, 'img'); + $this->assertRegexMatches($regex, 'h1'); + $this->assertRegexDoesNotMatch($regex, '11'); } public function testBlockTagName() { $regex = '/^' . RegexHelper::PARTIAL_BLOCKTAGNAME . '$/'; - $this->assertRegExp($regex, 'p'); - $this->assertRegExp($regex, 'div'); - $this->assertRegExp($regex, 'h1'); - $this->assertNotRegExp($regex, 'a'); - $this->assertNotRegExp($regex, 'h7'); + $this->assertRegexMatches($regex, 'p'); + $this->assertRegexMatches($regex, 'div'); + $this->assertRegexMatches($regex, 'h1'); + $this->assertRegexDoesNotMatch($regex, 'a'); + $this->assertRegexDoesNotMatch($regex, 'h7'); } public function testAttributeName() { $regex = '/^' . RegexHelper::PARTIAL_ATTRIBUTENAME . '$/'; - $this->assertRegExp($regex, 'href'); - $this->assertRegExp($regex, 'class'); - $this->assertRegExp($regex, 'data-src'); - $this->assertNotRegExp($regex, '-key'); + $this->assertRegexMatches($regex, 'href'); + $this->assertRegexMatches($regex, 'class'); + $this->assertRegexMatches($regex, 'data-src'); + $this->assertRegexDoesNotMatch($regex, '-key'); } public function testUnquotedValue() { $regex = '/^' . RegexHelper::PARTIAL_UNQUOTEDVALUE . '$/'; - $this->assertRegExp($regex, 'foo'); - $this->assertRegExp($regex, 'bar'); - $this->assertNotRegExp($regex, '"baz"'); + $this->assertRegexMatches($regex, 'foo'); + $this->assertRegexMatches($regex, 'bar'); + $this->assertRegexDoesNotMatch($regex, '"baz"'); } public function testSingleQuotedValue() { $regex = '/^' . RegexHelper::PARTIAL_SINGLEQUOTEDVALUE . '$/'; - $this->assertRegExp($regex, '\'foo\''); - $this->assertRegExp($regex, '\'bar\''); - $this->assertNotRegExp($regex, '"baz"'); + $this->assertRegexMatches($regex, '\'foo\''); + $this->assertRegexMatches($regex, '\'bar\''); + $this->assertRegexDoesNotMatch($regex, '"baz"'); } public function testDoubleQuotedValue() { $regex = '/^' . RegexHelper::PARTIAL_DOUBLEQUOTEDVALUE . '$/'; - $this->assertRegExp($regex, '"foo"'); - $this->assertRegExp($regex, '"bar"'); - $this->assertNotRegExp($regex, '\'baz\''); + $this->assertRegexMatches($regex, '"foo"'); + $this->assertRegexMatches($regex, '"bar"'); + $this->assertRegexDoesNotMatch($regex, '\'baz\''); } public function testAttributeValue() { $regex = '/^' . RegexHelper::PARTIAL_ATTRIBUTEVALUE . '$/'; - $this->assertRegExp($regex, 'foo'); - $this->assertRegExp($regex, '\'bar\''); - $this->assertRegExp($regex, '"baz"'); + $this->assertRegexMatches($regex, 'foo'); + $this->assertRegexMatches($regex, '\'bar\''); + $this->assertRegexMatches($regex, '"baz"'); } public function testAttributeValueSpec() { $regex = '/^' . RegexHelper::PARTIAL_ATTRIBUTEVALUESPEC . '$/'; - $this->assertRegExp($regex, '=foo'); - $this->assertRegExp($regex, '= foo'); - $this->assertRegExp($regex, ' =foo'); - $this->assertRegExp($regex, ' = foo'); - $this->assertRegExp($regex, '=\'bar\''); - $this->assertRegExp($regex, '= \'bar\''); - $this->assertRegExp($regex, ' =\'bar\''); - $this->assertRegExp($regex, ' = \'bar\''); - $this->assertRegExp($regex, '="baz"'); - $this->assertRegExp($regex, '= "baz"'); - $this->assertRegExp($regex, ' ="baz"'); - $this->assertRegExp($regex, ' = "baz"'); + $this->assertRegexMatches($regex, '=foo'); + $this->assertRegexMatches($regex, '= foo'); + $this->assertRegexMatches($regex, ' =foo'); + $this->assertRegexMatches($regex, ' = foo'); + $this->assertRegexMatches($regex, '=\'bar\''); + $this->assertRegexMatches($regex, '= \'bar\''); + $this->assertRegexMatches($regex, ' =\'bar\''); + $this->assertRegexMatches($regex, ' = \'bar\''); + $this->assertRegexMatches($regex, '="baz"'); + $this->assertRegexMatches($regex, '= "baz"'); + $this->assertRegexMatches($regex, ' ="baz"'); + $this->assertRegexMatches($regex, ' = "baz"'); } public function testAttribute() { $regex = '/^' . RegexHelper::PARTIAL_ATTRIBUTE . '$/'; - $this->assertRegExp($regex, ' disabled'); - $this->assertRegExp($regex, ' disabled="disabled"'); - $this->assertRegExp($regex, ' href="http://www.google.com"'); - $this->assertNotRegExp($regex, 'disabled', 'There must be at least one space at the start'); + $this->assertRegexMatches($regex, ' disabled'); + $this->assertRegexMatches($regex, ' disabled="disabled"'); + $this->assertRegexMatches($regex, ' href="http://www.google.com"'); + $this->assertRegexDoesNotMatch($regex, 'disabled', 'There must be at least one space at the start'); } public function testOpenTag() { $regex = '/^' . RegexHelper::PARTIAL_OPENTAG . '$/'; - $this->assertRegExp($regex, '
    '); - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, ''); - $this->assertNotRegExp($regex, '

    '); + $this->assertRegexMatches($regex, '
    '); + $this->assertRegexMatches($regex, '
    '); + $this->assertRegexMatches($regex, ''); + $this->assertRegexDoesNotMatch($regex, '

    '); } public function testCloseTag() { $regex = '/^' . RegexHelper::PARTIAL_CLOSETAG . '$/'; - $this->assertRegExp($regex, '

    '); - $this->assertRegExp($regex, '
    '); - $this->assertNotRegExp($regex, '
    '); - $this->assertNotRegExp($regex, ''); + $this->assertRegexMatches($regex, '

    '); + $this->assertRegexMatches($regex, ''); + $this->assertRegexDoesNotMatch($regex, '
    '); + $this->assertRegexDoesNotMatch($regex, ''); } public function testOpenBlockTag() { $regex = '/^' . RegexHelper::PARTIAL_OPENBLOCKTAG . '$/'; - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, '
    '); - $this->assertRegExp($regex, '
    '); - $this->assertRegExp($regex, '

    '); - $this->assertNotRegExp($regex, '', 'This is not a block element'); - $this->assertNotRegExp($regex, '

    ', 'This is not an opening tag'); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, '
    '); + $this->assertRegexMatches($regex, '
    '); + $this->assertRegexMatches($regex, '

    '); + $this->assertRegexDoesNotMatch($regex, '', 'This is not a block element'); + $this->assertRegexDoesNotMatch($regex, '

    ', 'This is not an opening tag'); } public function testCloseBlockTag() { $regex = '/^' . RegexHelper::PARTIAL_CLOSEBLOCKTAG . '$/'; - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, '

    '); - $this->assertNotRegExp($regex, '
    ', 'This is not a block element'); - $this->assertNotRegExp($regex, '
    ', 'This is not a closing tag'); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, '

    '); + $this->assertRegexDoesNotMatch($regex, '', 'This is not a block element'); + $this->assertRegexDoesNotMatch($regex, '
    ', 'This is not a closing tag'); } public function testHtmlComment() { $regex = '/^' . RegexHelper::PARTIAL_HTMLCOMMENT . '$/'; - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, ''); - $this->assertNotRegExp($regex, ''); - $this->assertNotRegExp($regex, ''); - $this->assertNotRegExp($regex, ''); - $this->assertNotRegExp($regex, ''); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, ''); + $this->assertRegexDoesNotMatch($regex, ''); + $this->assertRegexDoesNotMatch($regex, ''); + $this->assertRegexDoesNotMatch($regex, ''); + $this->assertRegexDoesNotMatch($regex, ''); } public function testProcessingInstruction() { $regex = '/^' . RegexHelper::PARTIAL_PROCESSINGINSTRUCTION . '$/'; - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, ''); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, ''); } public function testDeclaration() { $regex = '/^' . RegexHelper::PARTIAL_DECLARATION . '$/'; - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, ''); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, ''); } public function testCDATA() { $regex = '/^' . RegexHelper::PARTIAL_CDATA . '$/'; - $this->assertRegExp($regex, 'John Smith]]>'); - $this->assertRegExp($regex, ']]>'); + $this->assertRegexMatches($regex, 'John Smith]]>'); + $this->assertRegexMatches($regex, ']]>'); } public function testHtmlTag() { $regex = '/^' . RegexHelper::PARTIAL_HTMLTAG . '$/'; - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, '

    '); - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, ''); - $this->assertRegExp($regex, 'John Smith]]>'); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, '

    '); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, ''); + $this->assertRegexMatches($regex, 'John Smith]]>'); } public function testHtmlBlockOpen() { $regex = '/^' . RegexHelper::PARTIAL_HTMLBLOCKOPEN . '$/'; - $this->assertRegExp($regex, '

    '); - $this->assertRegExp($regex, '

    '); + $this->assertRegexMatches($regex, '

    '); + $this->assertRegexMatches($regex, '

    '); } public function testLinkTitle() { $regex = '/^' . RegexHelper::PARTIAL_HTMLBLOCKOPEN . '$/'; - $this->assertRegExp($regex, '

    '); - $this->assertRegExp($regex, '

    '); + $this->assertRegexMatches($regex, '

    '); + $this->assertRegexMatches($regex, '

    '); } public function testUnescape() @@ -330,11 +330,10 @@ public function blockTypesWithValidOpenerRegexes() yield [HtmlBlock::TYPE_7_MISC_ELEMENT]; } - /** - * @expectedException \InvalidArgumentException - */ public function testInvalidHtmlBlockOpenRegex() { + $this->expectException(\InvalidArgumentException::class); + RegexHelper::getHtmlBlockOpenRegex(8); } @@ -361,10 +360,11 @@ public function blockTypesWithValidCloserRegexes() * @param int $type * * @dataProvider blockTypesWithInvalidCloserRegexes - * @expectedException \InvalidArgumentException */ public function testInvalidHtmlBlockCloseRegex(int $type) { + $this->expectException(\InvalidArgumentException::class); + RegexHelper::getHtmlBlockCloseRegex($type); } @@ -374,4 +374,22 @@ public function blockTypesWithInvalidCloserRegexes() yield [HtmlBlock::TYPE_7_MISC_ELEMENT]; yield [8]; } + + private function assertRegexMatches(string $pattern, string $string, string $message = ''): void + { + if (\method_exists($this, 'assertMatchesRegularExpression')) { + $this->assertMatchesRegularExpression($pattern, $string, $message); + } else { + $this->assertRegExp($pattern, $string, $message); + } + } + + private function assertRegexDoesNotMatch(string $pattern, string $string, string $message = ''): void + { + if (\method_exists($this, 'assertDoesNotMatchRegularExpression')) { + $this->assertDoesNotMatchRegularExpression($pattern, $string, $message); + } else { + $this->assertNotRegExp($pattern, $string, $message); + } + } }