Skip to content

Commit d1246f9

Browse files
committed
Update testsuite and CI
1 parent 4376303 commit d1246f9

File tree

8 files changed

+39
-32
lines changed

8 files changed

+39
-32
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ on:
1010

1111
jobs:
1212
testsuite:
13-
runs-on: ubuntu-18.04
13+
runs-on: ubuntu-22.04
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
php-version: ['7.2', '7.4', '8.0']
17+
php-version: ['7.4', '8.0', '8.1']
1818
prefer-lowest: ['']
1919
include:
2020
- php-version: '7.2'
2121
prefer-lowest: 'prefer-lowest'
2222

2323
steps:
24-
- uses: actions/checkout@v1
25-
with:
26-
fetch-depth: 1
24+
- uses: actions/checkout@v3
2725

2826
- name: Setup PHP
2927
uses: shivammathur/setup-php@v2
@@ -35,18 +33,15 @@ jobs:
3533
- name: Install packages
3634
run: |
3735
sudo apt install xfonts-base xfonts-75dpi
38-
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
39-
sudo dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb
36+
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
37+
sudo dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb
4038
sudo apt install -f
4139
wkhtmltopdf --version
4240
4341
- name: Composer install
4442
run: |
4543
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
4644
composer update --prefer-lowest --prefer-stable
47-
elif [[ ${{ matrix.php-version }} == '8.0' ]]; then
48-
composer remove --dev mpdf/mpdf dompdf/dompdf
49-
composer install
5045
else
5146
composer install
5247
fi
@@ -64,24 +59,22 @@ jobs:
6459
6560
- name: Code Coverage Report
6661
if: matrix.php-version == '7.4'
67-
uses: codecov/codecov-action@v1
62+
uses: codecov/codecov-action@v3
6863

6964
cs-stan:
7065
name: Coding Standard & Static Analysis
71-
runs-on: ubuntu-18.04
66+
runs-on: ubuntu-22.04
7267

7368
steps:
74-
- uses: actions/checkout@v1
75-
with:
76-
fetch-depth: 1
69+
- uses: actions/checkout@v3
7770

7871
- name: Setup PHP
7972
uses: shivammathur/setup-php@v2
8073
with:
8174
php-version: '7.4'
8275
extensions: mbstring, intl
8376
coverage: none
84-
tools: cs2pr, psalm:^4.3, phpstan:^0.12
77+
tools: cs2pr, vimeo/psalm:4.26, phpstan:1.8
8578

8679
- name: Composer Install
8780
run: composer install

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Plugin containing CakePdf lib which will use a PDF engine to convert HTML to PDF.
88

99
Engines included in the plugin:
10-
* DomPdf (^0.8)
10+
* DomPdf (^0.8. Using ^2.0 is highly recommended as lower versions have various security vulnerabilities)
1111
* Mpdf (^8.0.4)
1212
* Tcpdf (^6.3)
1313
* WkHtmlToPdf **RECOMMENDED ENGINE**
@@ -145,7 +145,7 @@ Configure::write('CakePdf', [
145145
'url' => 'cover.html',
146146
'enable-smart-shrinking' => true,
147147
],
148-
'toc' => true,
148+
'toc' => true,
149149
],
150150

151151
/**
@@ -294,8 +294,8 @@ try using file system paths instead for the assets.
294294
<img src="<?= WWW_ROOT ?>img/logo.png" />
295295
```
296296

297-
**Note:** Since v0.12.16 wkhtmltopdf requires the option `enable-local-file-access`
298-
to be able to use local filesytem paths for assets. You can enable it by setting
297+
**Note:** Since v0.12.16 wkhtmltopdf requires the option `enable-local-file-access`
298+
to be able to use local filesytem paths for assets. You can enable it by setting
299299
`'enable-local-file-access' => true` in the engine config array.
300300

301301
## Get header and footer on all pages

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"require-dev": {
1111
"phpunit/phpunit": "~8.5.0 || ^9.3",
12-
"dompdf/dompdf": "^0.8.6",
12+
"dompdf/dompdf": "^2.0",
1313
"mpdf/mpdf": "^8.0.4",
1414
"tecnickcom/tcpdf": "^6.3",
1515
"cakephp/cakephp-codesniffer": "^4.2"
@@ -34,5 +34,10 @@
3434
},
3535
"replace": {
3636
"ceeram/cakepdf": "self.version"
37+
},
38+
"config": {
39+
"allow-plugins": {
40+
"dealerdirect/phpcodesniffer-composer-installer": true
41+
}
3742
}
3843
}

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ parameters:
22
level: 6
33
checkMissingIterableValueType: false
44
bootstrapFiles:
5+
- vendor/cakephp/cakephp/src/Core/Exception/CakeException.php
56
- tests/bootstrap.php
67
paths:
78
- src

psalm.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0"?>
22
<psalm
3-
totallyTyped="false"
43
resolveFromConfigFile="true"
54
autoloader="tests/bootstrap.php"
65
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -15,6 +14,10 @@
1514
</ignoreFiles>
1615
</projectFiles>
1716

17+
<stubs>
18+
<file name="vendor/cakephp/cakephp/src/Core/Exception/CakeException.php" preloadClasses="true" />
19+
</stubs>
20+
1821
<issueHandlers>
1922
<LessSpecificReturnType errorLevel="info" />
2023

src/Pdf/CakePdf.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public function write(string $destination, bool $create = true, ?string $html =
347347
return (bool)file_put_contents($destination, $output);
348348
}
349349

350-
if (!$fileInfo->isFile() && !$fileInfo->getPathInfo()->getRealPath()) {
350+
if (!$fileInfo->getPathInfo()->getRealPath()) {
351351
mkdir($fileInfo->getPath(), 0777, true);
352352
}
353353

@@ -372,11 +372,12 @@ public function engine($name = null): ?AbstractPdfEngine
372372
$name = $name['className'];
373373
}
374374

375+
/** @var class-string<\CakePdf\Pdf\Engine\AbstractPdfEngine>|null $engineClassName */
375376
$engineClassName = App::className($name, 'Pdf/Engine', 'Engine');
376377
if ($engineClassName === null) {
377378
throw new Exception(sprintf('Pdf engine "%s" not found', $name));
378379
}
379-
if (!is_subclass_of($engineClassName, 'CakePdf\Pdf\Engine\AbstractPdfEngine')) {
380+
if (!is_subclass_of($engineClassName, AbstractPdfEngine::class)) {
380381
throw new Exception('Pdf engines must extend "AbstractPdfEngine"');
381382
}
382383
$this->_engineClass = new $engineClassName($this);

tests/TestCase/Pdf/Engine/DomPdfEngineTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ public function testControlFlow()
128128

129129
$Engine = $Pdf->engine();
130130
$Engine
131-
->expects($this->at(0))
131+
->expects($this->once())
132132
->method('_createInstance')
133133
->willReturn($DomPDF);
134134
$Engine
135-
->expects($this->at(1))
135+
->expects($this->once())
136136
->method('_render')
137137
->with($Pdf, $DomPDF)
138138
->willReturn($DomPDF);
139139
$Engine
140-
->expects($this->at(2))
140+
->expects($this->once())
141141
->method('_output')
142142
->with($DomPDF);
143143

@@ -161,22 +161,22 @@ public function testDompdfControlFlow()
161161
->method('_createInstance')
162162
->will($this->returnCallback(function ($options) {
163163
$Dompdf = $this->getMockBuilder('\Dompdf\Dompdf')
164-
->setMethods(['setPaper', 'loadHtml', 'render', 'output'])
164+
->onlyMethods(['setPaper', 'loadHtml', 'render', 'output'])
165165
->setConstructorArgs([$options])
166166
->getMock();
167167
$Dompdf
168-
->expects($this->at(0))
168+
->expects($this->once())
169169
->method('setPaper')
170170
->with('A4', 'portrait');
171171
$Dompdf
172-
->expects($this->at(1))
172+
->expects($this->once())
173173
->method('loadHtml')
174174
->with(null);
175175
$Dompdf
176-
->expects($this->at(2))
176+
->expects($this->once())
177177
->method('render');
178178
$Dompdf
179-
->expects($this->at(3))
179+
->expects($this->once())
180180
->method('output');
181181

182182
return $Dompdf;

tests/TestCase/Pdf/Engine/WkHtmlToPdfEngineTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ public function testGetCommand()
150150

151151
public function testCoverUrlMissing()
152152
{
153+
if (!shell_exec('which wkhtmltopdf')) {
154+
$this->markTestSkipped('wkhtmltopdf not found');
155+
}
156+
153157
$this->expectException(Exception::class);
154158
$this->expectExceptionMessage('The url for the cover is missing. Use the "url" index.');
155159

0 commit comments

Comments
 (0)