diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b41a900..267392d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -10,20 +10,18 @@ on:
jobs:
testsuite:
- runs-on: ubuntu-18.04
+ runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
- php-version: ['7.2', '7.4', '8.0']
+ php-version: ['7.4', '8.0', '8.1']
prefer-lowest: ['']
include:
- php-version: '7.2'
prefer-lowest: 'prefer-lowest'
steps:
- - uses: actions/checkout@v1
- with:
- fetch-depth: 1
+ - uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
@@ -35,8 +33,8 @@ jobs:
- name: Install packages
run: |
sudo apt install xfonts-base xfonts-75dpi
- wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
- sudo dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb
+ wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
+ sudo dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb
sudo apt install -f
wkhtmltopdf --version
@@ -44,9 +42,6 @@ jobs:
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
- elif [[ ${{ matrix.php-version }} == '8.0' ]]; then
- composer remove --dev mpdf/mpdf dompdf/dompdf
- composer install
else
composer install
fi
@@ -64,16 +59,14 @@ jobs:
- name: Code Coverage Report
if: matrix.php-version == '7.4'
- uses: codecov/codecov-action@v1
+ uses: codecov/codecov-action@v3
cs-stan:
name: Coding Standard & Static Analysis
- runs-on: ubuntu-18.04
+ runs-on: ubuntu-22.04
steps:
- - uses: actions/checkout@v1
- with:
- fetch-depth: 1
+ - uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
@@ -81,7 +74,7 @@ jobs:
php-version: '7.4'
extensions: mbstring, intl
coverage: none
- tools: cs2pr, psalm:^4.3, phpstan:^0.12
+ tools: cs2pr, vimeo/psalm:4.26, phpstan:1.8
- name: Composer Install
run: composer install
diff --git a/README.md b/README.md
index b68afea..b5a6630 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
Plugin containing CakePdf lib which will use a PDF engine to convert HTML to PDF.
Engines included in the plugin:
-* DomPdf (^0.8)
+* DomPdf (^0.8. Using ^2.0 is highly recommended as lower versions have various security vulnerabilities)
* Mpdf (^8.0.4)
* Tcpdf (^6.3)
* WkHtmlToPdf **RECOMMENDED ENGINE**
@@ -145,7 +145,7 @@ Configure::write('CakePdf', [
'url' => 'cover.html',
'enable-smart-shrinking' => true,
],
- 'toc' => true,
+ 'toc' => true,
],
/**
@@ -294,8 +294,8 @@ try using file system paths instead for the assets.
```
-**Note:** Since v0.12.16 wkhtmltopdf requires the option `enable-local-file-access`
-to be able to use local filesytem paths for assets. You can enable it by setting
+**Note:** Since v0.12.16 wkhtmltopdf requires the option `enable-local-file-access`
+to be able to use local filesytem paths for assets. You can enable it by setting
`'enable-local-file-access' => true` in the engine config array.
## Get header and footer on all pages
diff --git a/composer.json b/composer.json
index 7dfa6bd..b727cbb 100644
--- a/composer.json
+++ b/composer.json
@@ -9,7 +9,7 @@
},
"require-dev": {
"phpunit/phpunit": "~8.5.0 || ^9.3",
- "dompdf/dompdf": "^0.8.6",
+ "dompdf/dompdf": "^2.0",
"mpdf/mpdf": "^8.0.4",
"tecnickcom/tcpdf": "^6.3",
"cakephp/cakephp-codesniffer": "^4.2"
@@ -34,5 +34,10 @@
},
"replace": {
"ceeram/cakepdf": "self.version"
+ },
+ "config": {
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": true
+ }
}
}
diff --git a/phpstan.neon b/phpstan.neon
index 343d302..ac67f30 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -2,6 +2,7 @@ parameters:
level: 6
checkMissingIterableValueType: false
bootstrapFiles:
+ - vendor/cakephp/cakephp/src/Core/Exception/CakeException.php
- tests/bootstrap.php
paths:
- src
diff --git a/psalm.xml b/psalm.xml
index 5ac7025..0b28919 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -1,6 +1,5 @@
+
+
+
+
diff --git a/src/Pdf/CakePdf.php b/src/Pdf/CakePdf.php
index 6e0613e..fef394d 100644
--- a/src/Pdf/CakePdf.php
+++ b/src/Pdf/CakePdf.php
@@ -347,7 +347,7 @@ public function write(string $destination, bool $create = true, ?string $html =
return (bool)file_put_contents($destination, $output);
}
- if (!$fileInfo->isFile() && !$fileInfo->getPathInfo()->getRealPath()) {
+ if (!$fileInfo->getPathInfo()->getRealPath()) {
mkdir($fileInfo->getPath(), 0777, true);
}
@@ -372,11 +372,12 @@ public function engine($name = null): ?AbstractPdfEngine
$name = $name['className'];
}
+ /** @var class-string<\CakePdf\Pdf\Engine\AbstractPdfEngine>|null $engineClassName */
$engineClassName = App::className($name, 'Pdf/Engine', 'Engine');
if ($engineClassName === null) {
throw new Exception(sprintf('Pdf engine "%s" not found', $name));
}
- if (!is_subclass_of($engineClassName, 'CakePdf\Pdf\Engine\AbstractPdfEngine')) {
+ if (!is_subclass_of($engineClassName, AbstractPdfEngine::class)) {
throw new Exception('Pdf engines must extend "AbstractPdfEngine"');
}
$this->_engineClass = new $engineClassName($this);
diff --git a/tests/TestCase/Pdf/Engine/DomPdfEngineTest.php b/tests/TestCase/Pdf/Engine/DomPdfEngineTest.php
index d57270a..8aa5898 100644
--- a/tests/TestCase/Pdf/Engine/DomPdfEngineTest.php
+++ b/tests/TestCase/Pdf/Engine/DomPdfEngineTest.php
@@ -128,16 +128,16 @@ public function testControlFlow()
$Engine = $Pdf->engine();
$Engine
- ->expects($this->at(0))
+ ->expects($this->once())
->method('_createInstance')
->willReturn($DomPDF);
$Engine
- ->expects($this->at(1))
+ ->expects($this->once())
->method('_render')
->with($Pdf, $DomPDF)
->willReturn($DomPDF);
$Engine
- ->expects($this->at(2))
+ ->expects($this->once())
->method('_output')
->with($DomPDF);
@@ -161,22 +161,22 @@ public function testDompdfControlFlow()
->method('_createInstance')
->will($this->returnCallback(function ($options) {
$Dompdf = $this->getMockBuilder('\Dompdf\Dompdf')
- ->setMethods(['setPaper', 'loadHtml', 'render', 'output'])
+ ->onlyMethods(['setPaper', 'loadHtml', 'render', 'output'])
->setConstructorArgs([$options])
->getMock();
$Dompdf
- ->expects($this->at(0))
+ ->expects($this->once())
->method('setPaper')
->with('A4', 'portrait');
$Dompdf
- ->expects($this->at(1))
+ ->expects($this->once())
->method('loadHtml')
->with(null);
$Dompdf
- ->expects($this->at(2))
+ ->expects($this->once())
->method('render');
$Dompdf
- ->expects($this->at(3))
+ ->expects($this->once())
->method('output');
return $Dompdf;
diff --git a/tests/TestCase/Pdf/Engine/WkHtmlToPdfEngineTest.php b/tests/TestCase/Pdf/Engine/WkHtmlToPdfEngineTest.php
index 6a4f42d..cfa184d 100644
--- a/tests/TestCase/Pdf/Engine/WkHtmlToPdfEngineTest.php
+++ b/tests/TestCase/Pdf/Engine/WkHtmlToPdfEngineTest.php
@@ -150,6 +150,10 @@ public function testGetCommand()
public function testCoverUrlMissing()
{
+ if (!shell_exec('which wkhtmltopdf')) {
+ $this->markTestSkipped('wkhtmltopdf not found');
+ }
+
$this->expectException(Exception::class);
$this->expectExceptionMessage('The url for the cover is missing. Use the "url" index.');