Skip to content

Commit

Permalink
- Added compatibility with PHPUnit 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
f-houssait committed Nov 14, 2022
1 parent c002749 commit 2a26c9e
Show file tree
Hide file tree
Showing 46 changed files with 541 additions and 148 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

# PhpUnit
/build/
/.phpunit.result.cache

# Composer
/bin/
/vendor/
/composer.lock
/composer.lock
/composer.phar
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
bootstrap="./vendor/autoload.php" colors="true" backupGlobals="false"
bootstrap="./src/Tests/bootstrap.php"
colors="true"
backupGlobals="false"
backupStaticAttributes="false"
verbose="true"
>
Expand Down
33 changes: 8 additions & 25 deletions src/Tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
47 changes: 47 additions & 0 deletions src/Tests/CrossVersionCompatibility/PhpUnit5/AbstractTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;

use Spipu\Html2Pdf\Html2Pdf;

abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @var Html2Pdf
*/
protected $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;
}

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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;

use Spipu\Html2Pdf\CssConverter;

abstract class CssConverterTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @var CssConverter
*/
protected $cssConverter;

public function setUp()
{
$this->cssConverter = new CssConverter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <[email protected]>
* @copyright 2017 Laurent MINGUET
*/

namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;

abstract class ExceptionFormatterTestCase extends \PHPUnit_Framework_TestCase
{
}
38 changes: 38 additions & 0 deletions src/Tests/CrossVersionCompatibility/PhpUnit5/HtmlTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <[email protected]>
* @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);
}
}
23 changes: 23 additions & 0 deletions src/Tests/CrossVersionCompatibility/PhpUnit5/SvgDrawerTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;

use Spipu\Html2Pdf\CssConverter;
use Spipu\Html2Pdf\SvgDrawer;

abstract class SvgDrawerTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @var SvgDrawer
*/
protected $svgDrawer;

public function setUp()
{
$myPdf = $this->createMock('Spipu\Html2Pdf\MyPdf');

$cssConverter = new CssConverter();

$this->svgDrawer = new SvgDrawer($myPdf, $cssConverter);
}
}
39 changes: 39 additions & 0 deletions src/Tests/CrossVersionCompatibility/PhpUnit5/TagParserTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <[email protected]>
* @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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <[email protected]>
* @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();
}
}
39 changes: 39 additions & 0 deletions src/Tests/CrossVersionCompatibility/PhpUnit9/AbstractTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;

use Spipu\Html2Pdf\Html2Pdf;

abstract class AbstractTestCase extends \PHPUnit\Framework\TestCase
{
use \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\AssertContains;

/**
* @var Html2Pdf
*/
protected $html2pdf;

/**
* Executed before each test
*/
protected function setUp(): void
{
$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(): void
{
$this->html2pdf->clean();
$this->html2pdf = null;
}

public function expectExceptionMessage($message, $exception = null): void
{
// Yes, we ignore $exception
parent::expectExceptionMessage($message);
}
}
15 changes: 15 additions & 0 deletions src/Tests/CrossVersionCompatibility/PhpUnit9/AssertContains.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9;

trait AssertContains
{
public static function assertContains($needle, $haystack, string $message = ''): void
{
if (is_string($haystack)) {
parent::assertStringContainsString($needle, $haystack, $message);
} else {
parent::assertContains($needle, $haystack, $message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;

use Spipu\Html2Pdf\CssConverter;

abstract class CssConverterTestCase extends \PHPUnit\Framework\TestCase
{
/**
* @var CssConverter
*/
protected $cssConverter;

public function setUp(): void
{
$this->cssConverter = new CssConverter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <[email protected]>
* @copyright 2017 Laurent MINGUET
*/

namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;

abstract class ExceptionFormatterTestCase extends \PHPUnit\Framework\TestCase
{
use \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\AssertContains;
}
Loading

0 comments on commit 2a26c9e

Please sign in to comment.