Skip to content

Commit 9de65b7

Browse files
authored
Merge pull request #733 from jausions/phpunit-9-compatibility
Added compatibility with PHPUnit 9
2 parents e258a36 + 2a26c9e commit 9de65b7

46 files changed

Lines changed: 541 additions & 148 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
# PhpUnit
1414
/build/
15+
/.phpunit.result.cache
1516

1617
# Composer
1718
/bin/
1819
/vendor/
19-
/composer.lock
20+
/composer.lock
21+
/composer.phar

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"tecnickcom/tcpdf": "^6.3"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^5.0"
22+
"phpunit/phpunit": "^5.0 || ^9.0"
2323
},
2424
"suggest": {
2525
"fagundes/zff-html2pdf": "if you need to integrate Html2Pdf with Zend Framework 2 (zf2)",

phpunit.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
4-
bootstrap="./vendor/autoload.php" colors="true" backupGlobals="false"
4+
bootstrap="./src/Tests/bootstrap.php"
5+
colors="true"
6+
backupGlobals="false"
57
backupStaticAttributes="false"
68
verbose="true"
79
>

src/Tests/AbstractTest.php

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,17 @@
44

55
use Spipu\Html2Pdf\Html2Pdf;
66

7+
if (HTML2PDF_PHPUNIT_VERSION === 9) {
8+
require_once 'CrossVersionCompatibility/PhpUnit9/AbstractTestCase.php';
9+
} else {
10+
require_once 'CrossVersionCompatibility/PhpUnit5/AbstractTestCase.php';
11+
}
12+
713
/**
8-
* Class Html2PdfTest
14+
* Class AbstractTest
915
*/
10-
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
16+
abstract class AbstractTest extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\AbstractTestCase
1117
{
12-
/**
13-
* @var Html2Pdf
14-
*/
15-
private $html2pdf;
16-
17-
/**
18-
* Executed before each test
19-
*/
20-
protected function setUp()
21-
{
22-
$this->html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', [0, 0, 0, 0]);
23-
$this->html2pdf->pdf->SetTitle('PhpUnit Test');
24-
}
25-
26-
/**
27-
* Executed after each test
28-
*/
29-
protected function tearDown()
30-
{
31-
$this->html2pdf->clean();
32-
$this->html2pdf = null;
33-
}
34-
3518
/**
3619
* Get the object to test
3720
*
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
4+
5+
use Spipu\Html2Pdf\Html2Pdf;
6+
7+
abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
8+
{
9+
/**
10+
* @var Html2Pdf
11+
*/
12+
protected $html2pdf;
13+
14+
/**
15+
* Executed before each test
16+
*/
17+
protected function setUp()
18+
{
19+
$this->html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', [0, 0, 0, 0]);
20+
$this->html2pdf->pdf->SetTitle('PhpUnit Test');
21+
}
22+
23+
/**
24+
* Executed after each test
25+
*/
26+
protected function tearDown()
27+
{
28+
$this->html2pdf->clean();
29+
$this->html2pdf = null;
30+
}
31+
32+
public function expectException($exception)
33+
{
34+
if (method_exists(\PHPUnit_Framework_TestCase::class, 'setExpectedException')) {
35+
$this->setExpectedException($exception);
36+
}
37+
}
38+
39+
public function expectExceptionMessage($message, $exception = null)
40+
{
41+
if (method_exists(\PHPUnit_Framework_TestCase::class, 'expectExceptionMessage')) {
42+
parent::expectExceptionMessage($message);
43+
} elseif (method_exists(\PHPUnit_Framework_TestCase::class, 'setExpectedException')) {
44+
$this->setExpectedException($exception, $message);
45+
}
46+
}
47+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
4+
5+
use Spipu\Html2Pdf\CssConverter;
6+
7+
abstract class CssConverterTestCase extends \PHPUnit_Framework_TestCase
8+
{
9+
/**
10+
* @var CssConverter
11+
*/
12+
protected $cssConverter;
13+
14+
public function setUp()
15+
{
16+
$this->cssConverter = new CssConverter();
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Html2Pdf Library - Tests
4+
*
5+
* HTML => PDF converter
6+
* distributed under the OSL-3.0 License
7+
*
8+
* @package Html2pdf
9+
* @author Laurent MINGUET <webmaster@html2pdf.fr>
10+
* @copyright 2017 Laurent MINGUET
11+
*/
12+
13+
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
14+
15+
abstract class ExceptionFormatterTestCase extends \PHPUnit_Framework_TestCase
16+
{
17+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Html2Pdf Library - Tests
4+
*
5+
* HTML => PDF converter
6+
* distributed under the OSL-3.0 License
7+
*
8+
* @package Html2pdf
9+
* @author Laurent MINGUET <webmaster@html2pdf.fr>
10+
* @copyright 2017 Laurent MINGUET
11+
*/
12+
13+
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
14+
15+
use Spipu\Html2Pdf\Parsing\Html;
16+
17+
abstract class HtmlTestCase extends \PHPUnit_Framework_TestCase
18+
{
19+
/**
20+
* @var Html
21+
*/
22+
protected $object;
23+
24+
protected function setUp()
25+
{
26+
$textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser')
27+
->disableOriginalConstructor()
28+
->setMethods(['prepareTxt'])
29+
->getMock();
30+
31+
$textParser
32+
->expects($this->any())
33+
->method('prepareTxt')
34+
->will($this->returnCallback([$this, 'mockPrepareTxt']));
35+
36+
$this->object = new Html($textParser);
37+
}
38+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
4+
5+
use Spipu\Html2Pdf\CssConverter;
6+
use Spipu\Html2Pdf\SvgDrawer;
7+
8+
abstract class SvgDrawerTestCase extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var SvgDrawer
12+
*/
13+
protected $svgDrawer;
14+
15+
public function setUp()
16+
{
17+
$myPdf = $this->createMock('Spipu\Html2Pdf\MyPdf');
18+
19+
$cssConverter = new CssConverter();
20+
21+
$this->svgDrawer = new SvgDrawer($myPdf, $cssConverter);
22+
}
23+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Html2Pdf Library - Tests
4+
*
5+
* HTML => PDF converter
6+
* distributed under the OSL-3.0 License
7+
*
8+
* @package Html2pdf
9+
* @author Laurent MINGUET <webmaster@html2pdf.fr>
10+
* @copyright 2017 Laurent MINGUET
11+
*/
12+
13+
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
14+
15+
use Spipu\Html2Pdf\Parsing\Node;
16+
use Spipu\Html2Pdf\Parsing\TagParser;
17+
18+
abstract class TagParserTestCase extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @var TagParser
22+
*/
23+
protected $parser;
24+
25+
protected function setUp()
26+
{
27+
$textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser')
28+
->disableOriginalConstructor()
29+
->setMethods(['prepareTxt'])
30+
->getMock();
31+
32+
$textParser
33+
->expects($this->any())
34+
->method('prepareTxt')
35+
->will($this->returnCallback([$this, 'mockPrepareTxt']));
36+
37+
$this->parser = new TagParser($textParser);
38+
}
39+
}

0 commit comments

Comments
 (0)