Skip to content

Commit

Permalink
Merge pull request #322 from FriendsOfCake/maintenance
Browse files Browse the repository at this point in the history
Update testsuite and CI
  • Loading branch information
ADmad authored Aug 31, 2022
2 parents 4376303 + d1246f9 commit 1df6dd0
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 32 deletions.
25 changes: 9 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,18 +33,15 @@ 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
- name: Composer install
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
Expand All @@ -64,24 +59,22 @@ 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
with:
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
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -145,7 +145,7 @@ Configure::write('CakePdf', [
'url' => 'cover.html',
'enable-smart-shrinking' => true,
],
'toc' => true,
'toc' => true,
],

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

**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
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,5 +34,10 @@
},
"replace": {
"ceeram/cakepdf": "self.version"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
level: 6
checkMissingIterableValueType: false
bootstrapFiles:
- vendor/cakephp/cakephp/src/Core/Exception/CakeException.php
- tests/bootstrap.php
paths:
- src
5 changes: 4 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
autoloader="tests/bootstrap.php"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -15,6 +14,10 @@
</ignoreFiles>
</projectFiles>

<stubs>
<file name="vendor/cakephp/cakephp/src/Core/Exception/CakeException.php" preloadClasses="true" />
</stubs>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

Expand Down
5 changes: 3 additions & 2 deletions src/Pdf/CakePdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions tests/TestCase/Pdf/Engine/DomPdfEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Pdf/Engine/WkHtmlToPdfEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');

Expand Down

0 comments on commit 1df6dd0

Please sign in to comment.