-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHPUnit 9 has deprecated expectDeprecation
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
Showing
2 changed files
with
142 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters