Skip to content

Commit

Permalink
PHPUnit 9 has deprecated expectDeprecation
Browse files Browse the repository at this point in the history
It will be removed in PHPUnit 10. As such,
we have to migrate to our own way of testing
for deprecations, warnings and errors.
  • Loading branch information
gocom committed Jun 7, 2024
1 parent 6ec7449 commit 158ac83
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 102 deletions.
142 changes: 142 additions & 0 deletions test/Netcarver/Textile/Test/ParserDeprecationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

/**
* Textile - A Humane Web Text Generator.
*
* @link https://github.com/textile/php-textile
*/

namespace Netcarver\Textile\Test;

use Netcarver\Textile\Test\Parser\DeprecatedPrepare;
use Netcarver\Textile\Test\Parser\DeprecatedTextileCommon;
use PHPUnit\Framework\TestCase;
use Netcarver\Textile\Parser;

class ParserDeprecationTest extends TestCase
{
/**
* @var Parser
*/
private $parser;

protected function setUp(): void
{
$this->parser = new Parser();

set_error_handler(static function ($errorNumber) {
if (!($errorNumber & error_reporting())) {
return false;
}

throw new \Exception('', E_USER_DEPRECATED);
}, E_USER_DEPRECATED);
}

protected function tearDown(): void
{
restore_error_handler();
}

public function testSetRelativeImagePrefixChaining()
{
$this->expectExceptionCode(E_USER_DEPRECATED);

$symbol = @$this->parser
->setRelativeImagePrefix('abc')
->setSymbol('test', 'TestValue')
->getSymbol('test');

$this->assertEquals('TestValue', $symbol);

$this->parser->setRelativeImagePrefix('abc');
}

public function testDeprecatedEncodingArgument()
{
$this->expectExceptionCode(E_USER_DEPRECATED);

$this->assertSame(
'content',
@$this->parser->textileThis('content', false, true)
);

$this->assertSame(
'content',
$this->parser->textileEncode('content')
);

$this->parser->textileThis('content', false, true);
}

public function testDeprecatedTextileCommon()
{
$this->expectExceptionCode(E_USER_DEPRECATED);

$parser = new DeprecatedTextileCommon();

$this->assertSame(
' content',
@$parser->testTextileCommon(' content', false)
);

$this->assertSame(
' content',
@$parser->testTextileCommon(' content', true)
);

$parser->testTextileCommon('content', false);
}

public function testDeprecatedPrepare()
{
$this->expectExceptionCode(E_USER_DEPRECATED);

$parser = new DeprecatedPrepare();

$this->assertSame(
' content',
@$parser->parse(' content')
);

$parser->parse('content');
}

public function testDeprecatedTextileRestricted()
{
$this->expectExceptionCode(E_USER_DEPRECATED);

$this->assertSame(
' content',
@$this->parser->textileRestricted(' content')
);

$this->parser->textileRestricted('content');
}

public function testDeprecatedTextileThis()
{
$this->expectExceptionCode(E_USER_DEPRECATED);

$this->assertSame(
' content',
@$this->parser->textileThis(' content')
);

$this->parser->textileThis('content');
}

public function testDeprecatedSetRelativeImagePrefix()
{
$this->expectExceptionCode(E_USER_DEPRECATED);

@$this->parser->setRelativeImagePrefix('/1/');

$this->assertSame(
' <img alt="" src="/1/2.jpg" /> <a href="/1/2">1</a>',
$this->parser->parse(' !2.jpg! "1":2')
);

$this->parser->setRelativeImagePrefix('/1/');
}
}
102 changes: 0 additions & 102 deletions test/Netcarver/Textile/Test/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace Netcarver\Textile\Test;

use Netcarver\Textile\Test\Parser\DeprecatedPrepare;
use Netcarver\Textile\Test\Parser\DeprecatedTextileCommon;
use PHPUnit\Framework\TestCase;
use Netcarver\Textile\Parser;

Expand Down Expand Up @@ -62,18 +60,6 @@ public function testSetGetSymbol()
);
}

public function testSetRelativeImagePrefixChaining()
{
$this->expectError();

$symbol = $this->parser
->setRelativeImagePrefix('abc')
->setSymbol('test', 'TestValue')
->getSymbol('test');

$this->assertEquals('TestValue', $symbol);
}

public function testSetGetDimensionlessImage()
{
$this->assertFalse(
Expand All @@ -97,94 +83,6 @@ public function testEncode()
);
}

public function testDeprecatedEncodingArgument()
{
$this->expectDeprecation();

$this->assertSame(
'content',
@$this->parser->textileThis('content', false, true)
);

$this->assertSame(
'content',
$this->parser->textileEncode('content')
);

$this->parser->textileThis('content', false, true);
}

public function testDeprecatedTextileCommon()
{
$this->expectDeprecation();

$parser = new DeprecatedTextileCommon();

$this->assertSame(
' content',
@$parser->testTextileCommon(' content', false)
);

$this->assertSame(
' content',
@$parser->testTextileCommon(' content', true)
);

$parser->testTextileCommon('content', false);
}

public function testDeprecatedPrepare()
{
$this->expectDeprecation();

$parser = new DeprecatedPrepare();

$this->assertSame(
' content',
@$parser->parse(' content')
);

$parser->parse('content');
}

public function testDeprecatedTextileRestricted()
{
$this->expectDeprecation();

$this->assertSame(
' content',
@$this->parser->textileRestricted(' content')
);

$this->parser->textileRestricted('content');
}

public function testDeprecatedTextileThis()
{
$this->expectDeprecation();

$this->assertSame(
' content',
@$this->parser->textileThis(' content')
);

$this->parser->textileThis('content');
}

public function testDeprecatedSetRelativeImagePrefix()
{
$this->expectDeprecation();

@$this->parser->setRelativeImagePrefix('/1/');

$this->assertSame(
' <img alt="" src="/1/2.jpg" /> <a href="/1/2">1</a>',
$this->parser->parse(' !2.jpg! "1":2')
);

$this->parser->setRelativeImagePrefix('/1/');
}

public function testInvalidDocumentType()
{
$this->expectException('\InvalidArgumentException');
Expand Down

0 comments on commit 158ac83

Please sign in to comment.