Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build failures for the cake 5 upgrade #326

Merged
merged 16 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
Expand All @@ -74,7 +74,7 @@ jobs:
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: cs2pr
tools: cs2pr, vimeo/psalm:5.15, phpstan:1.8

- name: Composer Install
run: composer install
Expand All @@ -84,8 +84,8 @@ jobs:

- name: Run psalm
if: success() || failure()
run: vendor/bin/psalm --output-format=github
run: psalm --output-format=github
BGehrels marked this conversation as resolved.
Show resolved Hide resolved

- name: Run phpstan
if: success() || failure()
run: vendor/bin/phpstan analyse
run: phpstan analyse
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"license": "MIT",
"require": {
"php": ">=8.1",
"cakephp/cakephp": "^5.0"
"cakephp/cakephp": "^5.0.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^10.3",
"dompdf/dompdf": "^2.0",
"mpdf/mpdf": "^8.0.4",
"mpdf/mpdf": "^8.1.6",
"tecnickcom/tcpdf": "^6.3",
"cakephp/cakephp-codesniffer": "^5.0"
},
Expand All @@ -33,7 +33,7 @@
"TestApp\\": "tests/test_app/src/"
}
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"scripts": {
"check": [
"@test",
Expand Down
16 changes: 0 additions & 16 deletions config/bootstrap.php

This file was deleted.

38 changes: 12 additions & 26 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>

<testsuites>
<testsuite name="CakePdf Plugin Tests">
<directory>./tests/TestCase</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="./tests/bootstrap.php" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="CakePdf Plugin Tests">
<directory>./tests/TestCase</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</source>
</phpunit>
BGehrels marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 8 additions & 1 deletion src/Plugin.php → src/CakePdfPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@

use Cake\Core\BasePlugin;

class Plugin extends BasePlugin
class CakePdfPlugin extends BasePlugin
{
/**
* Do bootstrap or not
*
* @var bool
*/
protected bool $bootstrapEnabled = false;

/**
* Load routes or not
*
Expand Down
12 changes: 9 additions & 3 deletions src/Pdf/CakePdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ public function html(?string $html = null): mixed
/**
* Writes output to file
*
* @throws \Cake\Core\Exception\CakeException
* @param string $destination Absolute file path to write to
* @param bool $create Create file if it does not exist (if true)
* @param string|null $html Html to write
Expand All @@ -347,7 +348,12 @@ public function write(string $destination, bool $create = true, ?string $html =
return (bool)file_put_contents($destination, $output);
}

if (!$fileInfo->getPathInfo()->getRealPath()) {
$splFileInfo = $fileInfo->getPathInfo();
/** @phpstan-ignore-next-line */
if ($splFileInfo === null) {
throw new CakeException('Failed to retrieve path information');
}
if (!$splFileInfo->getRealPath()) {
mkdir($fileInfo->getPath(), 0777, true);
}

Expand All @@ -357,11 +363,11 @@ public function write(string $destination, bool $create = true, ?string $html =
/**
* Load PdfEngine
*
* @param array|string $name Classname of pdf engine without `Engine` suffix. For example `CakePdf.DomPdf`
* @param array|string|null $name Classname of pdf engine without `Engine` suffix. For example `CakePdf.DomPdf`
* @throws \Cake\Core\Exception\CakeException
* @return \CakePdf\Pdf\Engine\AbstractPdfEngine|null
*/
public function engine(string|array|null $name = null): ?AbstractPdfEngine
public function engine(array|string|null $name = null): ?AbstractPdfEngine
{
if ($name === null) {
return $this->_engineClass;
Expand Down
16 changes: 12 additions & 4 deletions src/View/PdfView.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
/**
* Constructor
*
* @param \Cake\Http\ServerRequest $request Request instance.
* @param \Cake\Http\Response $response Response instance.
* @param \Cake\Event\EventManager $eventManager Event manager instance.
* @param \Cake\Http\ServerRequest|null $request Request instance.
* @param \Cake\Http\Response|null $response Response instance.
* @param \Cake\Event\EventManager|null $eventManager Event manager instance.
* @param array $viewOptions View options. See View::$_passedVars for list of
* options which get set as class properties.
* @throws \Cake\Core\Exception\CakeException
Expand Down Expand Up @@ -82,6 +82,14 @@
$this->renderer($pdfConfig);
}

/**
* {@inheritDoc}

Check warning on line 86 in src/View/PdfView.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

When inheriting entire doc comment, @inheritdoc must be used instead of {@inheritdoc}.
ADmad marked this conversation as resolved.
Show resolved Hide resolved
*/
public static function contentType(): string {

Check failure on line 88 in src/View/PdfView.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Opening brace should be on a new line
ADmad marked this conversation as resolved.
Show resolved Hide resolved
return 'application/pdf';
}

ADmad marked this conversation as resolved.
Show resolved Hide resolved

Check failure on line 92 in src/View/PdfView.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Found more than a single empty line between content
/**
* Return CakePdf instance, optionally set engine to be used
*
Expand All @@ -104,7 +112,7 @@
* @param string|false|null $layout The layout being rendered.
* @return string The rendered view.
*/
public function render(?string $template = null, false|string|null $layout = null): string
public function render(?string $template = null, string|false|null $layout = null): string
{
$content = parent::render($template, $layout);

Expand Down
23 changes: 14 additions & 9 deletions tests/TestCase/Pdf/Engine/DomPdfEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function setUp(): void
*/
public function testReceiveOptions()
{
$engineClass = $this->getMockClass(DomPdfEngine::class, ['_createInstance']);
$engineClass = $this->getMockBuilder(DomPdfEngine::class)->disableOriginalConstructor()->onlyMethods(['_createInstance'])->getMock()::class;

$Pdf = new CakePdf([
'engine' => [
Expand Down Expand Up @@ -65,8 +65,7 @@ public function testReceiveOptions()
*/
public function testSetOptions()
{
$engineClass = $this->getMockClass(DomPdfEngine::class, ['_output']);

$engineClass = $this->getMockBuilder(DomPdfEngine::class)->disableOriginalConstructor()->onlyMethods(['_output'])->getMock()::class;
$Pdf = new CakePdf([
'engine' => [
'className' => '\\' . $engineClass,
Expand Down Expand Up @@ -114,11 +113,14 @@ public function testOutput()
*/
public function testControlFlow()
{
$engineClass = $this->getMockClass(DomPdfEngine::class, [
'_createInstance',
'_render',
'_output',
]);
$engineClass = $this->getMockBuilder(DomPdfEngine::class)
->disableOriginalConstructor()
->onlyMethods([
'_createInstance',
'_render',
'_output',
])
->getMock()::class;

$Pdf = new CakePdf([
'engine' => '\\' . $engineClass,
Expand Down Expand Up @@ -149,7 +151,10 @@ public function testControlFlow()
*/
public function testDompdfControlFlow()
{
$engineClass = $this->getMockClass(DomPdfEngine::class, ['_createInstance']);
$engineClass = $this->getMockBuilder(DomPdfEngine::class)
->disableOriginalConstructor()
->onlyMethods(['_createInstance'])
->getMock()::class;

$Pdf = new CakePdf([
'engine' => '\\' . $engineClass,
Expand Down
5 changes: 4 additions & 1 deletion tests/TestCase/Pdf/Engine/MpdfEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public function setUp(): void
*/
public function testSetOptions()
{
$engineClass = $this->getMockClass(MpdfEngine::class, ['_createInstance']);
$engineClass = $this->getMockBuilder(MpdfEngine::class)
->disableOriginalConstructor()
->onlyMethods(['_createInstance'])
->getMock()::class;

$Pdf = new CakePdf([
'engine' => [
Expand Down
Loading