Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests on PHP 8 #521

Merged
merged 3 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"
},
Expand Down
9 changes: 5 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="league/commonmark Test Suite">
<directory>tests</directory>
<testsuite name="league/commonmark Functional Tests">
<directory>tests/functional</directory>
</testsuite>
<testsuite name="league/commonmark Unit Tests">
<directory>tests/unit</directory>
</testsuite>
</testsuites>
<filter>
Expand All @@ -20,8 +23,6 @@
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" />
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
Expand Down
1 change: 1 addition & 0 deletions src/Reference/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function getTitle(): string
* @return string
*
* @deprecated Use TextNormalizer::normalize() instead
* @group legacy
*/
public static function normalizeReference(string $string): string
{
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/AbstractSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class AbstractSpecTest extends TestCase
*/
protected $converter;

protected function setUp()
protected function setUp(): void
{
$this->converter = new CommonMarkConverter();
}
Expand Down
18 changes: 9 additions & 9 deletions tests/functional/BinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand All @@ -49,7 +49,7 @@ public function testHelpShortFlag()
$cmd->execute();

$this->assertEquals(0, $cmd->getExitCode());
$this->assertContains('Usage:', $cmd->getOutput());
$this->assertStringContainsString('Usage:', $cmd->getOutput());
}

/**
Expand All @@ -62,7 +62,7 @@ public function testHelpOption()
$cmd->execute();

$this->assertEquals(0, $cmd->getExitCode());
$this->assertContains('Usage:', $cmd->getOutput());
$this->assertStringContainsString('Usage:', $cmd->getOutput());
}

/**
Expand All @@ -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());
}
}

Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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()));
}
}

Expand Down
4 changes: 1 addition & 3 deletions tests/functional/Delimiter/DelimiterProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ public function testMultipleDelimitersWithDifferentLengths()
$this->assertEquals("<p>(1)(2)both(/2)(/1)</p>\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));
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/EmphasisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

/**
Expand All @@ -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()));
}

/**
Expand All @@ -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()));
}

/**
Expand All @@ -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()));
}

/**
Expand All @@ -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()));
}

/**
Expand All @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class GithubFlavoredMarkdownExtensionTest extends AbstractSpecTest
{
protected function setUp()
protected function setUp(): void
{
$this->converter = new GithubFlavoredMarkdownConverter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public function dataProviderForTestHeadingPermalinksWithCustomOptions()
yield ["Test\n----", '<h2>Test<a id="custom-prefix-test" href="#test" name="test" class="custom-class" aria-hidden="true" title="Link">¶ 🦄️ &lt;3 You</a></h2>'];
}

/**
* @group legacy
*/
public function testHeadingPermalinksWithDeprecatedInnerContents()
{
$environment = Environment::createCommonMarkEnvironment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InlinesOnlyFunctionalTest extends TestCase
*/
protected $converter;

protected function setUp()
protected function setUp(): void
{
$environment = new Environment();
$environment->addExtension(new InlinesOnlyExtension());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +29,7 @@ class SmartPunctFunctionalTest extends TestCase
*/
protected $converter;

protected function setUp()
protected function setUp(): void
{
$environment = Environment::createCommonMarkEnvironment();
$environment->addExtension(new SmartPunctExtension());
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/LocalDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LocalDataTest extends AbstractLocalDataTest
*/
protected $converter;

protected function setUp()
protected function setUp(): void
{
$this->converter = new CommonMarkConverter();
}
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/Block/Element/AbstractBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/Block/Renderer/BlockQuoteRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BlockQuoteRendererTest extends TestCase
*/
protected $renderer;

protected function setUp()
protected function setUp(): void
{
$this->renderer = new BlockQuoteRenderer();
}
Expand Down Expand Up @@ -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();

Expand Down
13 changes: 6 additions & 7 deletions tests/unit/Block/Renderer/DocumentRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DocumentRendererTest extends TestCase
*/
protected $renderer;

protected function setUp()
protected function setUp(): void
{
$this->renderer = new DocumentRenderer();
}
Expand All @@ -40,7 +40,7 @@ public function testRenderEmptyDocument()

$result = $this->renderer->render($block, $fakeRenderer);

$this->assertInternalType('string', $result);
$this->assertIsString($result);
$this->assertEmpty($result);
}

Expand All @@ -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();

Expand Down
13 changes: 6 additions & 7 deletions tests/unit/Block/Renderer/FencedCodeRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FencedCodeRendererTest extends TestCase
*/
protected $renderer;

protected function setUp()
protected function setUp(): void
{
$this->renderer = new FencedCodeRenderer();
}
Expand Down Expand Up @@ -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()
Expand All @@ -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();

Expand Down