From 2a26c9e1bfa917bc9d70bf265529bededa718bca Mon Sep 17 00:00:00 2001 From: Philippe Jausions Date: Mon, 14 Nov 2022 09:21:16 +0200 Subject: [PATCH] - Added compatibility with PHPUnit 9.0 --- .gitignore | 4 +- composer.json | 2 +- phpunit.xml | 4 +- src/Tests/AbstractTest.php | 33 ++++--------- .../PhpUnit5/AbstractTestCase.php | 47 +++++++++++++++++++ .../PhpUnit5/CssConverterTestCase.php | 18 +++++++ .../PhpUnit5/ExceptionFormatterTestCase.php | 17 +++++++ .../PhpUnit5/HtmlTestCase.php | 38 +++++++++++++++ .../PhpUnit5/SvgDrawerTestCase.php | 23 +++++++++ .../PhpUnit5/TagParserTestCase.php | 39 +++++++++++++++ .../PhpUnit5/TextParserTestCase.php | 28 +++++++++++ .../PhpUnit9/AbstractTestCase.php | 39 +++++++++++++++ .../PhpUnit9/AssertContains.php | 15 ++++++ .../PhpUnit9/CssConverterTestCase.php | 18 +++++++ .../PhpUnit9/ExceptionFormatterTestCase.php | 18 +++++++ .../PhpUnit9/HtmlTestCase.php | 38 +++++++++++++++ .../PhpUnit9/SvgDrawerTestCase.php | 23 +++++++++ .../PhpUnit9/TagParserTestCase.php | 38 +++++++++++++++ .../PhpUnit9/TestCase.php | 5 ++ .../PhpUnit9/TextParserTestCase.php | 28 +++++++++++ src/Tests/CssConverterTest.php | 18 +++---- src/Tests/ExamplesTest.php | 12 ++++- .../Exception/ExceptionFormatterTest.php | 8 +++- .../Exception/LongSentenceExceptionTest.php | 3 +- src/Tests/Html2PdfTest.php | 9 ++-- src/Tests/Image/BackgroundErrorTest.php | 2 +- src/Tests/Image/SrcErrorTest.php | 2 +- src/Tests/LocaleTest.php | 4 +- src/Tests/Output/FileNameOkTest.php | 2 +- src/Tests/Parsing/HtmlTest.php | 28 +++-------- src/Tests/Parsing/ParsingTest.php | 12 ++--- src/Tests/Parsing/TagParserTest.php | 32 ++++--------- src/Tests/Parsing/TextParserTest.php | 18 +++---- src/Tests/SvgDrawerTest.php | 28 ++++------- src/Tests/Tag/MustHaveTagsTest.php | 4 +- src/Tests/Tag/Svg/CircleErrorTest.php | 2 +- src/Tests/Tag/Svg/EllipseErrorTest.php | 2 +- src/Tests/Tag/Svg/GErrorTest.php | 2 +- src/Tests/Tag/Svg/LineErrorTest.php | 2 +- src/Tests/Tag/Svg/PathErrorTest.php | 2 +- src/Tests/Tag/Svg/PathInvalidTest.php | 2 +- src/Tests/Tag/Svg/PolygonErrorTest.php | 2 +- src/Tests/Tag/Svg/PolylineErrorTest.php | 2 +- src/Tests/Tag/Svg/RectErrorTest.php | 2 +- src/Tests/Tag/TdTooLongTest.php | 2 +- src/Tests/bootstrap.php | 12 +++++ 46 files changed, 541 insertions(+), 148 deletions(-) create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit5/AbstractTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit5/CssConverterTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit5/ExceptionFormatterTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit5/HtmlTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit5/SvgDrawerTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit5/TagParserTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit5/TextParserTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit9/AbstractTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit9/AssertContains.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit9/CssConverterTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit9/ExceptionFormatterTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit9/HtmlTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit9/SvgDrawerTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit9/TagParserTestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit9/TestCase.php create mode 100644 src/Tests/CrossVersionCompatibility/PhpUnit9/TextParserTestCase.php create mode 100644 src/Tests/bootstrap.php diff --git a/.gitignore b/.gitignore index 0f84dfe6..4d8fe2ba 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,10 @@ # PhpUnit /build/ +/.phpunit.result.cache # Composer /bin/ /vendor/ -/composer.lock \ No newline at end of file +/composer.lock +/composer.phar diff --git a/composer.json b/composer.json index 70007eeb..208d9e1c 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "tecnickcom/tcpdf": "^6.3" }, "require-dev": { - "phpunit/phpunit": "^5.0" + "phpunit/phpunit": "^5.0 || ^9.0" }, "suggest": { "fagundes/zff-html2pdf": "if you need to integrate Html2Pdf with Zend Framework 2 (zf2)", diff --git a/phpunit.xml b/phpunit.xml index a86805a1..cfcda6d3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,9 @@ diff --git a/src/Tests/AbstractTest.php b/src/Tests/AbstractTest.php index 28f071b0..aa720444 100755 --- a/src/Tests/AbstractTest.php +++ b/src/Tests/AbstractTest.php @@ -4,34 +4,17 @@ use Spipu\Html2Pdf\Html2Pdf; +if (HTML2PDF_PHPUNIT_VERSION === 9) { + require_once 'CrossVersionCompatibility/PhpUnit9/AbstractTestCase.php'; +} else { + require_once 'CrossVersionCompatibility/PhpUnit5/AbstractTestCase.php'; +} + /** - * Class Html2PdfTest + * Class AbstractTest */ -abstract class AbstractTest extends \PHPUnit_Framework_TestCase +abstract class AbstractTest extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\AbstractTestCase { - /** - * @var Html2Pdf - */ - private $html2pdf; - - /** - * Executed before each test - */ - protected function setUp() - { - $this->html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', [0, 0, 0, 0]); - $this->html2pdf->pdf->SetTitle('PhpUnit Test'); - } - - /** - * Executed after each test - */ - protected function tearDown() - { - $this->html2pdf->clean(); - $this->html2pdf = null; - } - /** * Get the object to test * diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit5/AbstractTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit5/AbstractTestCase.php new file mode 100644 index 00000000..e9e59165 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit5/AbstractTestCase.php @@ -0,0 +1,47 @@ +html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', [0, 0, 0, 0]); + $this->html2pdf->pdf->SetTitle('PhpUnit Test'); + } + + /** + * Executed after each test + */ + protected function tearDown() + { + $this->html2pdf->clean(); + $this->html2pdf = null; + } + + public function expectException($exception) + { + if (method_exists(\PHPUnit_Framework_TestCase::class, 'setExpectedException')) { + $this->setExpectedException($exception); + } + } + + public function expectExceptionMessage($message, $exception = null) + { + if (method_exists(\PHPUnit_Framework_TestCase::class, 'expectExceptionMessage')) { + parent::expectExceptionMessage($message); + } elseif (method_exists(\PHPUnit_Framework_TestCase::class, 'setExpectedException')) { + $this->setExpectedException($exception, $message); + } + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit5/CssConverterTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit5/CssConverterTestCase.php new file mode 100644 index 00000000..f49d1529 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit5/CssConverterTestCase.php @@ -0,0 +1,18 @@ +cssConverter = new CssConverter(); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit5/ExceptionFormatterTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit5/ExceptionFormatterTestCase.php new file mode 100644 index 00000000..476d869b --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit5/ExceptionFormatterTestCase.php @@ -0,0 +1,17 @@ + PDF converter + * distributed under the OSL-3.0 License + * + * @package Html2pdf + * @author Laurent MINGUET + * @copyright 2017 Laurent MINGUET + */ + +namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility; + +abstract class ExceptionFormatterTestCase extends \PHPUnit_Framework_TestCase +{ +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit5/HtmlTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit5/HtmlTestCase.php new file mode 100644 index 00000000..63723435 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit5/HtmlTestCase.php @@ -0,0 +1,38 @@ + PDF converter + * distributed under the OSL-3.0 License + * + * @package Html2pdf + * @author Laurent MINGUET + * @copyright 2017 Laurent MINGUET + */ + +namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility; + +use Spipu\Html2Pdf\Parsing\Html; + +abstract class HtmlTestCase extends \PHPUnit_Framework_TestCase +{ + /** + * @var Html + */ + protected $object; + + protected function setUp() + { + $textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser') + ->disableOriginalConstructor() + ->setMethods(['prepareTxt']) + ->getMock(); + + $textParser + ->expects($this->any()) + ->method('prepareTxt') + ->will($this->returnCallback([$this, 'mockPrepareTxt'])); + + $this->object = new Html($textParser); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit5/SvgDrawerTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit5/SvgDrawerTestCase.php new file mode 100644 index 00000000..5ceda58a --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit5/SvgDrawerTestCase.php @@ -0,0 +1,23 @@ +createMock('Spipu\Html2Pdf\MyPdf'); + + $cssConverter = new CssConverter(); + + $this->svgDrawer = new SvgDrawer($myPdf, $cssConverter); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit5/TagParserTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit5/TagParserTestCase.php new file mode 100644 index 00000000..4831abde --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit5/TagParserTestCase.php @@ -0,0 +1,39 @@ + PDF converter + * distributed under the OSL-3.0 License + * + * @package Html2pdf + * @author Laurent MINGUET + * @copyright 2017 Laurent MINGUET + */ + +namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility; + +use Spipu\Html2Pdf\Parsing\Node; +use Spipu\Html2Pdf\Parsing\TagParser; + +abstract class TagParserTestCase extends \PHPUnit_Framework_TestCase +{ + /** + * @var TagParser + */ + protected $parser; + + protected function setUp() + { + $textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser') + ->disableOriginalConstructor() + ->setMethods(['prepareTxt']) + ->getMock(); + + $textParser + ->expects($this->any()) + ->method('prepareTxt') + ->will($this->returnCallback([$this, 'mockPrepareTxt'])); + + $this->parser = new TagParser($textParser); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit5/TextParserTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit5/TextParserTestCase.php new file mode 100644 index 00000000..a447e299 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit5/TextParserTestCase.php @@ -0,0 +1,28 @@ + PDF converter + * distributed under the OSL-3.0 License + * + * @package Html2pdf + * @author Laurent MINGUET + * @copyright 2017 Laurent MINGUET + */ + +namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility; + +use Spipu\Html2Pdf\Parsing\TextParser; + +abstract class TextParserTestCase extends \PHPUnit_Framework_TestCase +{ + /** + * @var TextParser + */ + protected $parser; + + protected function setUp() + { + $this->parser = new TextParser(); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit9/AbstractTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit9/AbstractTestCase.php new file mode 100644 index 00000000..b59d18ce --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit9/AbstractTestCase.php @@ -0,0 +1,39 @@ +html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', [0, 0, 0, 0]); + $this->html2pdf->pdf->SetTitle('PhpUnit Test'); + } + + /** + * Executed after each test + */ + protected function tearDown(): void + { + $this->html2pdf->clean(); + $this->html2pdf = null; + } + + public function expectExceptionMessage($message, $exception = null): void + { + // Yes, we ignore $exception + parent::expectExceptionMessage($message); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit9/AssertContains.php b/src/Tests/CrossVersionCompatibility/PhpUnit9/AssertContains.php new file mode 100644 index 00000000..8b9aa292 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit9/AssertContains.php @@ -0,0 +1,15 @@ +cssConverter = new CssConverter(); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit9/ExceptionFormatterTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit9/ExceptionFormatterTestCase.php new file mode 100644 index 00000000..a1b873c7 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit9/ExceptionFormatterTestCase.php @@ -0,0 +1,18 @@ + PDF converter + * distributed under the OSL-3.0 License + * + * @package Html2pdf + * @author Laurent MINGUET + * @copyright 2017 Laurent MINGUET + */ + +namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility; + +abstract class ExceptionFormatterTestCase extends \PHPUnit\Framework\TestCase +{ + use \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\AssertContains; +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit9/HtmlTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit9/HtmlTestCase.php new file mode 100644 index 00000000..5aa56909 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit9/HtmlTestCase.php @@ -0,0 +1,38 @@ + PDF converter + * distributed under the OSL-3.0 License + * + * @package Html2pdf + * @author Laurent MINGUET + * @copyright 2017 Laurent MINGUET + */ + +namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility; + +use Spipu\Html2Pdf\Parsing\Html; + +abstract class HtmlTestCase extends \PHPUnit\Framework\TestCase +{ + /** + * @var Html + */ + protected $object; + + protected function setUp(): void + { + $textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser') + ->disableOriginalConstructor() + ->setMethods(['prepareTxt']) + ->getMock(); + + $textParser + ->expects($this->any()) + ->method('prepareTxt') + ->willReturnCallback([$this, 'mockPrepareTxt']); + + $this->object = new Html($textParser); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit9/SvgDrawerTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit9/SvgDrawerTestCase.php new file mode 100644 index 00000000..2b774122 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit9/SvgDrawerTestCase.php @@ -0,0 +1,23 @@ +createMock('Spipu\Html2Pdf\MyPdf'); + + $cssConverter = new CssConverter(); + + $this->svgDrawer = new SvgDrawer($myPdf, $cssConverter); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit9/TagParserTestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit9/TagParserTestCase.php new file mode 100644 index 00000000..933d07d0 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit9/TagParserTestCase.php @@ -0,0 +1,38 @@ + PDF converter + * distributed under the OSL-3.0 License + * + * @package Html2pdf + * @author Laurent MINGUET + * @copyright 2017 Laurent MINGUET + */ + +namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility; + +use Spipu\Html2Pdf\Parsing\TagParser; + +abstract class TagParserTestCase extends \PHPUnit\Framework\TestCase +{ + /** + * @var TagParser + */ + protected $parser; + + protected function setUp(): void + { + $textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser') + ->disableOriginalConstructor() + ->setMethods(['prepareTxt']) + ->getMock(); + + $textParser + ->expects($this->any()) + ->method('prepareTxt') + ->willReturnCallback([$this, 'mockPrepareTxt']); + + $this->parser = new TagParser($textParser); + } +} diff --git a/src/Tests/CrossVersionCompatibility/PhpUnit9/TestCase.php b/src/Tests/CrossVersionCompatibility/PhpUnit9/TestCase.php new file mode 100644 index 00000000..18c2ce54 --- /dev/null +++ b/src/Tests/CrossVersionCompatibility/PhpUnit9/TestCase.php @@ -0,0 +1,5 @@ + PDF converter + * distributed under the OSL-3.0 License + * + * @package Html2pdf + * @author Laurent MINGUET + * @copyright 2017 Laurent MINGUET + */ + +namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility; + +use Spipu\Html2Pdf\Parsing\TextParser; + +abstract class TextParserTestCase extends \PHPUnit\Framework\TestCase +{ + /** + * @var TextParser + */ + protected $parser; + + protected function setUp(): void + { + $this->parser = new TextParser(); + } +} diff --git a/src/Tests/CssConverterTest.php b/src/Tests/CssConverterTest.php index 2b39e158..8a2bc366 100644 --- a/src/Tests/CssConverterTest.php +++ b/src/Tests/CssConverterTest.php @@ -2,23 +2,17 @@ namespace Spipu\Html2Pdf\Tests; -use Spipu\Html2Pdf\CssConverter; +if (HTML2PDF_PHPUNIT_VERSION === 9) { + require_once 'CrossVersionCompatibility/PhpUnit9/CssConverterTestCase.php'; +} else { + require_once 'CrossVersionCompatibility/PhpUnit5/CssConverterTestCase.php'; +} /** * Class CssConverterTest */ -class CssConverterTest extends \PHPUnit_Framework_TestCase +class CssConverterTest extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\CssConverterTestCase { - /** - * @var CssConverter - */ - private $cssConverter; - - public function setUp() - { - $this->cssConverter = new CssConverter(); - } - /** * @param string $css * @param string $old diff --git a/src/Tests/ExamplesTest.php b/src/Tests/ExamplesTest.php index 1154f789..27729c14 100644 --- a/src/Tests/ExamplesTest.php +++ b/src/Tests/ExamplesTest.php @@ -12,10 +12,20 @@ namespace Spipu\Html2Pdf\Tests; +if (HTML2PDF_PHPUNIT_VERSION === 9) { + abstract class BaseExamplesTest extends \PHPUnit\Framework\TestCase + { + } +} else { + abstract class BaseExamplesTest extends \PHPUnit_Framework_TestCase + { + } +} + /** * Class ExamplesTest */ -class ExamplesTest extends \PHPUnit_Framework_TestCase +class ExamplesTest extends BaseExamplesTest { /** * Launch a example diff --git a/src/Tests/Exception/ExceptionFormatterTest.php b/src/Tests/Exception/ExceptionFormatterTest.php index 5a4ce27b..180832af 100644 --- a/src/Tests/Exception/ExceptionFormatterTest.php +++ b/src/Tests/Exception/ExceptionFormatterTest.php @@ -18,10 +18,16 @@ use Spipu\Html2Pdf\Exception\ImageException; use Spipu\Html2Pdf\Exception\LongSentenceException; +if (HTML2PDF_PHPUNIT_VERSION === 9) { + require_once __DIR__ . '/../CrossVersionCompatibility/PhpUnit9/ExceptionFormatterTestCase.php'; +} else { + require_once __DIR__ . '/../CrossVersionCompatibility/PhpUnit5/ExceptionFormatterTestCase.php'; +} + /** * Class ExceptionFormaterTest */ -class ExceptionFormatterTest extends \PHPUnit_Framework_TestCase +class ExceptionFormatterTest extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\ExceptionFormatterTestCase { /** * Test the formatter / generic exception diff --git a/src/Tests/Exception/LongSentenceExceptionTest.php b/src/Tests/Exception/LongSentenceExceptionTest.php index 00709ee2..960bcd1f 100644 --- a/src/Tests/Exception/LongSentenceExceptionTest.php +++ b/src/Tests/Exception/LongSentenceExceptionTest.php @@ -23,10 +23,11 @@ class LongSentenceExceptionTest extends AbstractTest * test LongSentence Exception * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\LongSentenceException */ public function testBug() { + $this->expectException(\Spipu\Html2Pdf\Exception\LongSentenceException::class); + $sentence = 'This is a sentence.'; $bigSentence = $sentence; for ($k=0; $k<110; $k++) { diff --git a/src/Tests/Html2PdfTest.php b/src/Tests/Html2PdfTest.php index c965f309..d686e864 100644 --- a/src/Tests/Html2PdfTest.php +++ b/src/Tests/Html2PdfTest.php @@ -31,14 +31,15 @@ public function testSecurityGood() $object->writeHTML('
'); $object->writeHTML('
'); $object->writeHTML('
'); + + // Ensures we assert something + $this->assertTrue(true); } - /** - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException - * @expectedExceptionMessage Unauthorized path scheme - */ public function testSecurityKo() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); + $this->expectExceptionMessage('Unauthorized path scheme', \Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML('
'); } diff --git a/src/Tests/Image/BackgroundErrorTest.php b/src/Tests/Image/BackgroundErrorTest.php index f329019f..33f40f26 100644 --- a/src/Tests/Image/BackgroundErrorTest.php +++ b/src/Tests/Image/BackgroundErrorTest.php @@ -24,10 +24,10 @@ class BackgroundErrorTest extends AbstractTest * test: The image src is unknown * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\ImageException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\ImageException::class); $image = '/res/wrong.png'; try { diff --git a/src/Tests/Image/SrcErrorTest.php b/src/Tests/Image/SrcErrorTest.php index 036fa2bf..5b88d81b 100644 --- a/src/Tests/Image/SrcErrorTest.php +++ b/src/Tests/Image/SrcErrorTest.php @@ -25,10 +25,10 @@ class SrcErrorTest extends AbstractTest * test: The image src is unknown * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\ImageException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\ImageException::class); $image = '/res/wrong.png'; try { diff --git a/src/Tests/LocaleTest.php b/src/Tests/LocaleTest.php index 800593de..288ab984 100644 --- a/src/Tests/LocaleTest.php +++ b/src/Tests/LocaleTest.php @@ -24,10 +24,10 @@ class LocaleTest extends \PHPUnit_Framework_TestCase * test bad code * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\LocaleException */ public function testBadCode() { + $this->expectException(\Spipu\Html2Pdf\Exception\LocaleException::class); Locale::clean(); try { @@ -42,10 +42,10 @@ public function testBadCode() * test unknown code * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\LocaleException */ public function testUnknownCode() { + $this->expectException(\Spipu\Html2Pdf\Exception\LocaleException::class); Locale::clean(); try { Locale::load('aa'); diff --git a/src/Tests/Output/FileNameOkTest.php b/src/Tests/Output/FileNameOkTest.php index bb04fe2a..6b27c880 100644 --- a/src/Tests/Output/FileNameOkTest.php +++ b/src/Tests/Output/FileNameOkTest.php @@ -55,10 +55,10 @@ public function testIgnore() * test: the file extension must be PDF - Error * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\Html2PdfException */ public function testError() { + $this->expectException(\Spipu\Html2Pdf\Exception\Html2PdfException::class); $object = $this->getObject(); $object->writeHTML('

Hello World

'); $object->output('test.bad'); diff --git a/src/Tests/Parsing/HtmlTest.php b/src/Tests/Parsing/HtmlTest.php index 4dd5fd22..762a8af6 100644 --- a/src/Tests/Parsing/HtmlTest.php +++ b/src/Tests/Parsing/HtmlTest.php @@ -12,33 +12,17 @@ namespace Spipu\Html2Pdf\Tests\Parsing; -use Spipu\Html2Pdf\Parsing\Html; +if (HTML2PDF_PHPUNIT_VERSION === 9) { + require_once __DIR__ . '/../CrossVersionCompatibility/PhpUnit9/HtmlTestCase.php'; +} else { + require_once __DIR__ . '/../CrossVersionCompatibility/PhpUnit5/HtmlTestCase.php'; +} /** * Class HtmlTest */ -class HtmlTest extends \PHPUnit_Framework_TestCase +class HtmlTest extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\HtmlTestCase { - /** - * @var Html - */ - private $object; - - protected function setUp() - { - $textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser') - ->disableOriginalConstructor() - ->setMethods(['prepareTxt']) - ->getMock(); - - $textParser - ->expects($this->any()) - ->method('prepareTxt') - ->will($this->returnCallback([$this, 'mockPrepareTxt'])); - - $this->object = new Html($textParser); - } - /** * mock of prepareTxt method * diff --git a/src/Tests/Parsing/ParsingTest.php b/src/Tests/Parsing/ParsingTest.php index 6a406546..01ac2ea3 100644 --- a/src/Tests/Parsing/ParsingTest.php +++ b/src/Tests/Parsing/ParsingTest.php @@ -24,10 +24,10 @@ class ParsingTest extends AbstractTest * test: The tag is unknown * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testUnknownTag() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML('Hello World'); $object->output('test.pdf', 'S'); @@ -37,10 +37,10 @@ public function testUnknownTag() * test: Too many tag closures found * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testTooManyClosuresFound() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML('Hello'); $object->output('test.pdf', 'S'); @@ -50,10 +50,10 @@ public function testTooManyClosuresFound() * test: Tags are closed in a wrong order * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testWrongClosedOrder() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML('Hello'); $object->output('test.pdf', 'S'); @@ -63,10 +63,10 @@ public function testWrongClosedOrder() * test: The following tag has not been closed * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testNotClosed() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML('Hello'); $object->output('test.pdf', 'S'); @@ -76,10 +76,10 @@ public function testNotClosed() * test: The following tags have not been closed * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testNotClosedMore() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML('Hello'); $object->output('test.pdf', 'S'); @@ -89,10 +89,10 @@ public function testNotClosedMore() * test: The HTML tag code provided is invalid * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testInvalidCode() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML('Hello'); $object->output('test.pdf', 'S'); diff --git a/src/Tests/Parsing/TagParserTest.php b/src/Tests/Parsing/TagParserTest.php index 026a5f59..e6f29c24 100644 --- a/src/Tests/Parsing/TagParserTest.php +++ b/src/Tests/Parsing/TagParserTest.php @@ -13,33 +13,18 @@ namespace Spipu\Html2Pdf\Tests\Parsing; use Spipu\Html2Pdf\Parsing\Node; -use Spipu\Html2Pdf\Parsing\TagParser; + +if (HTML2PDF_PHPUNIT_VERSION === 9) { + require_once __DIR__ . '/../CrossVersionCompatibility/PhpUnit9/TagParserTestCase.php'; +} else { + require_once __DIR__ . '/../CrossVersionCompatibility/PhpUnit5/TagParserTestCase.php'; +} /** * Class TagParserTest */ -class TagParserTest extends \PHPUnit_Framework_TestCase +class TagParserTest extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\TagParserTestCase { - /** - * @var TagParser - */ - private $parser; - - protected function setUp() - { - $textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser') - ->disableOriginalConstructor() - ->setMethods(['prepareTxt']) - ->getMock(); - - $textParser - ->expects($this->any()) - ->method('prepareTxt') - ->will($this->returnCallback([$this, 'mockPrepareTxt'])); - - $this->parser = new TagParser($textParser); - } - /** * mock of prepareTxt method * @@ -83,11 +68,10 @@ public function tagAttributesProvider() /** * Test if a bad tag is detected - * - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testAnalyzeTagBadTag() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $this->parser->analyzeTag('test'); } diff --git a/src/Tests/Parsing/TextParserTest.php b/src/Tests/Parsing/TextParserTest.php index 3d41bbc4..0e2cec51 100644 --- a/src/Tests/Parsing/TextParserTest.php +++ b/src/Tests/Parsing/TextParserTest.php @@ -12,23 +12,17 @@ namespace Spipu\Html2Pdf\Tests\Parsing; -use Spipu\Html2Pdf\Parsing\TextParser; +if (HTML2PDF_PHPUNIT_VERSION === 9) { + require_once __DIR__ . '/../CrossVersionCompatibility/PhpUnit9/TextParserTestCase.php'; +} else { + require_once __DIR__ . '/../CrossVersionCompatibility/PhpUnit5/TextParserTestCase.php'; +} /** * Class TextParserTest */ -class TextParserTest extends \PHPUnit_Framework_TestCase +class TextParserTest extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\TextParserTestCase { - /** - * @var TextParser - */ - private $parser; - - protected function setUp() - { - $this->parser = new TextParser(); - } - /** * Test if it works */ diff --git a/src/Tests/SvgDrawerTest.php b/src/Tests/SvgDrawerTest.php index 61d7cac1..3f951cdb 100644 --- a/src/Tests/SvgDrawerTest.php +++ b/src/Tests/SvgDrawerTest.php @@ -2,35 +2,23 @@ namespace Spipu\Html2Pdf\Tests; -use Spipu\Html2Pdf\CssConverter; -use Spipu\Html2Pdf\SvgDrawer; +if (HTML2PDF_PHPUNIT_VERSION === 9) { + require_once 'CrossVersionCompatibility/PhpUnit9/SvgDrawerTestCase.php'; +} else { + require_once 'CrossVersionCompatibility/PhpUnit5/SvgDrawerTestCase.php'; +} /** - * Class Html2PdfTest + * Class SvgDrawerTest */ -class SvgDrawerTest extends \PHPUnit_Framework_TestCase +class SvgDrawerTest extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\SvgDrawerTestCase { - /** - * @var SvgDrawer - */ - private $svgDrawer; - - public function setUp() - { - $myPdf = $this->createMock('Spipu\Html2Pdf\MyPdf'); - - $cssConverter = new CssConverter(); - - $this->svgDrawer = new SvgDrawer($myPdf, $cssConverter); - } - /** * Test IsDrawing Exception - * - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testIsDrawingException() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $properties = [ 'x' => 0, 'y' => 0, diff --git a/src/Tests/Tag/MustHaveTagsTest.php b/src/Tests/Tag/MustHaveTagsTest.php index 90f930f1..6e485f6a 100644 --- a/src/Tests/Tag/MustHaveTagsTest.php +++ b/src/Tests/Tag/MustHaveTagsTest.php @@ -43,10 +43,10 @@ public function testOk() * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testNotEmptyThead() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $html = ''; $html.= ''; $html.= ''; @@ -61,10 +61,10 @@ public function testNotEmptyThead() * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testNotEmptyTfoot() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $html = '
World
'; $html.= ''; $html.= ''; diff --git a/src/Tests/Tag/Svg/CircleErrorTest.php b/src/Tests/Tag/Svg/CircleErrorTest.php index 520466a1..8d627a75 100644 --- a/src/Tests/Tag/Svg/CircleErrorTest.php +++ b/src/Tests/Tag/Svg/CircleErrorTest.php @@ -23,10 +23,10 @@ class CircleErrorTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML(''); $object->output('test.pdf', 'S'); diff --git a/src/Tests/Tag/Svg/EllipseErrorTest.php b/src/Tests/Tag/Svg/EllipseErrorTest.php index 2274fd42..0dff4520 100644 --- a/src/Tests/Tag/Svg/EllipseErrorTest.php +++ b/src/Tests/Tag/Svg/EllipseErrorTest.php @@ -23,10 +23,10 @@ class EllipseErrorTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML(''); $object->output('test.pdf', 'S'); diff --git a/src/Tests/Tag/Svg/GErrorTest.php b/src/Tests/Tag/Svg/GErrorTest.php index 6cce43d7..8a5c0c34 100644 --- a/src/Tests/Tag/Svg/GErrorTest.php +++ b/src/Tests/Tag/Svg/GErrorTest.php @@ -23,10 +23,10 @@ class GErrorTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML(''); $object->output('test.pdf', 'S'); diff --git a/src/Tests/Tag/Svg/LineErrorTest.php b/src/Tests/Tag/Svg/LineErrorTest.php index d99cb0f7..748dad2e 100644 --- a/src/Tests/Tag/Svg/LineErrorTest.php +++ b/src/Tests/Tag/Svg/LineErrorTest.php @@ -23,10 +23,10 @@ class LineErrorTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML(''); $object->output('test.pdf', 'S'); diff --git a/src/Tests/Tag/Svg/PathErrorTest.php b/src/Tests/Tag/Svg/PathErrorTest.php index 6fb16bad..196ca97e 100644 --- a/src/Tests/Tag/Svg/PathErrorTest.php +++ b/src/Tests/Tag/Svg/PathErrorTest.php @@ -23,10 +23,10 @@ class PathErrorTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML(''); $object->output('test.pdf', 'S'); diff --git a/src/Tests/Tag/Svg/PathInvalidTest.php b/src/Tests/Tag/Svg/PathInvalidTest.php index e270c938..8ea2d5be 100644 --- a/src/Tests/Tag/Svg/PathInvalidTest.php +++ b/src/Tests/Tag/Svg/PathInvalidTest.php @@ -23,10 +23,10 @@ class PathInvalidTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $html = ' diff --git a/src/Tests/Tag/Svg/PolygonErrorTest.php b/src/Tests/Tag/Svg/PolygonErrorTest.php index eac218bf..360764f7 100644 --- a/src/Tests/Tag/Svg/PolygonErrorTest.php +++ b/src/Tests/Tag/Svg/PolygonErrorTest.php @@ -23,10 +23,10 @@ class PolygonErrorTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML(''); $object->output('test.pdf', 'S'); diff --git a/src/Tests/Tag/Svg/PolylineErrorTest.php b/src/Tests/Tag/Svg/PolylineErrorTest.php index 4f6c4db1..0d17f35a 100644 --- a/src/Tests/Tag/Svg/PolylineErrorTest.php +++ b/src/Tests/Tag/Svg/PolylineErrorTest.php @@ -23,10 +23,10 @@ class PolylineErrorTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML(''); $object->output('test.pdf', 'S'); diff --git a/src/Tests/Tag/Svg/RectErrorTest.php b/src/Tests/Tag/Svg/RectErrorTest.php index 1f21be9f..49f2a57d 100644 --- a/src/Tests/Tag/Svg/RectErrorTest.php +++ b/src/Tests/Tag/Svg/RectErrorTest.php @@ -23,10 +23,10 @@ class RectErrorTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class); $object = $this->getObject(); $object->writeHTML(''); $object->output('test.pdf', 'S'); diff --git a/src/Tests/Tag/TdTooLongTest.php b/src/Tests/Tag/TdTooLongTest.php index 89b5f546..abb427e7 100644 --- a/src/Tests/Tag/TdTooLongTest.php +++ b/src/Tests/Tag/TdTooLongTest.php @@ -24,10 +24,10 @@ class TdTooLongTest extends AbstractTest * test * * @return void - * @expectedException \Spipu\Html2Pdf\Exception\TableException */ public function testCase() { + $this->expectException(\Spipu\Html2Pdf\Exception\TableException::class); $sentence = 'Hello World ! '; $sentences = ''; for ($k=0; $k<100; $k++) { diff --git a/src/Tests/bootstrap.php b/src/Tests/bootstrap.php new file mode 100644 index 00000000..c56643f4 --- /dev/null +++ b/src/Tests/bootstrap.php @@ -0,0 +1,12 @@ += 0 +) { + define('HTML2PDF_PHPUNIT_VERSION', 9); + require_once 'CrossVersionCompatibility/PhpUnit9/TestCase.php'; +} else { + define('HTML2PDF_PHPUNIT_VERSION', 5); +}
World