Skip to content

Commit f44aaff

Browse files
committed
Bump up phpunit version
1 parent d2f5617 commit f44aaff

File tree

5 files changed

+66
-41
lines changed

5 files changed

+66
-41
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
php-version: ['8.1', '8.2', '8.3']
20+
php-version: ['8.2', '8.3', '8.3']
2121
dependencies: ['highest']
2222
include:
23-
- php-version: '8.4'
24-
dependencies: 'highest'
25-
composer-options: '--ignore-platform-req=php'
2623
- php-version: '8.1'
2724
dependencies: 'lowest'
2825

@@ -37,12 +34,10 @@ jobs:
3734
coverage: pcov
3835

3936
- name: Install packages
40-
run: |
41-
sudo apt install xfonts-base xfonts-75dpi
42-
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
43-
sudo dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb
44-
sudo apt install -f
45-
wkhtmltopdf --version
37+
uses: awalsh128/cache-apt-pkgs-action@v1
38+
with:
39+
packages: xfonts-base xfonts-75dpi wkhtmltopdf
40+
version: ubuntu-24.04
4641

4742
- name: Composer install
4843
uses: ramsey/composer-install@v3
@@ -56,14 +51,14 @@ jobs:
5651
- name: Run PHPUnit
5752
run: |
5853
if [[ ${{ matrix.php-version }} == '8.3' ]]; then
59-
vendor/bin/phpunit --display-warnings --display-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml
54+
vendor/bin/phpunit --display-warnings --display-deprecations --display-phpunit-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml
6055
else
61-
vendor/bin/phpunit --display-warnings --display-deprecations
56+
vendor/bin/phpunit --display-warnings --display-deprecations --display-phpunit-deprecations
6257
fi
6358
6459
- name: Code Coverage Report
6560
if: matrix.php-version == '8.3'
66-
uses: codecov/codecov-action@v4
61+
uses: codecov/codecov-action@v5
6762
env:
6863
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6964

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"cakephp/cakephp": "^5.0.1"
1010
},
1111
"require-dev": {
12-
"phpunit/phpunit": "^10.3",
12+
"phpunit/phpunit": "^10.5.5 || ^11.1.3",
1313
"dompdf/dompdf": "^2.0",
1414
"mpdf/mpdf": "^8.1.6",
1515
"tecnickcom/tcpdf": "^6.3",

src/Pdf/CakePdf.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,11 @@ public function write(string $destination, bool $create = true, ?string $html =
362362
/**
363363
* Load PdfEngine
364364
*
365-
* @param array|string|null $name Classname of pdf engine without `Engine` suffix. For example `CakePdf.DomPdf`
365+
* @param \CakePdf\Pdf\Engine\AbstractPdfEngine|array|string|null $name Classname of pdf engine without `Engine` suffix. For example `CakePdf.DomPdf`
366366
* @throws \Cake\Core\Exception\CakeException
367367
* @return \CakePdf\Pdf\Engine\AbstractPdfEngine|null
368368
*/
369-
public function engine(array|string|null $name = null): ?AbstractPdfEngine
369+
public function engine(AbstractPdfEngine|array|string|null $name = null): ?AbstractPdfEngine
370370
{
371371
if ($name === null) {
372372
return $this->_engineClass;
@@ -377,13 +377,26 @@ public function engine(array|string|null $name = null): ?AbstractPdfEngine
377377
$name = $name['className'];
378378
}
379379

380+
if (is_object($name)) {
381+
assert(
382+
is_subclass_of($name, AbstractPdfEngine::class),
383+
'Pdf engines must extend "AbstractPdfEngine"'
384+
);
385+
386+
$this->_engineClass = $name;
387+
$this->_engineClass->setConfig($config);
388+
389+
return $this->_engineClass;
390+
}
391+
380392
$engineClassName = App::className($name, 'Pdf/Engine', 'Engine');
381393
if ($engineClassName === null) {
382394
throw new CakeException(sprintf('Pdf engine "%s" not found', $name));
383395
}
384-
if (!is_subclass_of($engineClassName, AbstractPdfEngine::class)) {
385-
throw new CakeException('Pdf engines must extend "AbstractPdfEngine"');
386-
}
396+
assert(
397+
is_subclass_of($engineClassName, AbstractPdfEngine::class, true),
398+
'Pdf engines must extend "AbstractPdfEngine"'
399+
);
387400
$this->_engineClass = new $engineClassName($this);
388401
$this->_engineClass->setConfig($config);
389402

tests/TestCase/Pdf/Engine/DomPdfEngineTest.php

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@ public function setUp(): void
2727
*/
2828
public function testReceiveOptions()
2929
{
30-
$engineClass = $this->getMockBuilder(DomPdfEngine::class)->disableOriginalConstructor()->onlyMethods(['_createInstance'])->getMock()::class;
30+
$mock = $this->getMockBuilder(DomPdfEngine::class)
31+
->disableOriginalConstructor()
32+
->onlyMethods(['_createInstance'])
33+
->getMock();
3134

3235
$Pdf = new CakePdf([
3336
'engine' => [
34-
'className' => '\\' . $engineClass,
37+
'className' => $mock,
3538
'options' => [
3639
'isJavascriptEnabled' => false,
3740
'isHtml5ParserEnabled' => true,
3841
],
3942
],
4043
]);
4144

45+
$mock->__construct($Pdf);
46+
4247
$expected = [
4348
'fontCache' => TMP,
4449
'tempDir' => TMP,
@@ -51,11 +56,11 @@ public function testReceiveOptions()
5156
->expects($this->once())
5257
->method('_createInstance')
5358
->with($expected)
54-
->will($this->returnCallback(function ($options) use ($expected) {
59+
->willReturnCallback(function ($options) use ($expected) {
5560
$this->assertEquals($expected, $options);
5661

5762
return new Dompdf($options);
58-
}));
63+
});
5964

6065
$Pdf->engine()->output();
6166
}
@@ -65,30 +70,36 @@ public function testReceiveOptions()
6570
*/
6671
public function testSetOptions()
6772
{
68-
$engineClass = $this->getMockBuilder(DomPdfEngine::class)->disableOriginalConstructor()->onlyMethods(['_output'])->getMock()::class;
73+
$mock = $this->getMockBuilder(DomPdfEngine::class)
74+
->disableOriginalConstructor()
75+
->onlyMethods(['_output'])
76+
->getMock();
77+
6978
$Pdf = new CakePdf([
7079
'engine' => [
71-
'className' => '\\' . $engineClass,
80+
'className' => $mock,
7281
'options' => [
7382
'isJavascriptEnabled' => false,
7483
'isHtml5ParserEnabled' => true,
7584
],
7685
],
7786
]);
7887

88+
$mock->__construct($Pdf);
89+
7990
$Pdf
8091
->engine()
8192
->expects($this->once())
8293
->method('_output')
83-
->will($this->returnCallback(function ($Dompdf) {
94+
->willReturnCallback(function ($Dompdf) {
8495
$Options = $Dompdf->getOptions();
8596
$this->assertEquals(TMP, $Options->getFontCache());
8697
$this->assertEquals(TMP, $Options->getTempDir());
8798
$this->assertFalse($Options->getIsJavascriptEnabled());
8899
$this->assertTrue($Options->getIsHtml5ParserEnabled());
89100

90101
return $Dompdf->output();
91-
}));
102+
});
92103

93104
$Pdf->engine()->output();
94105
}
@@ -113,19 +124,21 @@ public function testOutput()
113124
*/
114125
public function testControlFlow()
115126
{
116-
$engineClass = $this->getMockBuilder(DomPdfEngine::class)
127+
$mock = $this->getMockBuilder(DomPdfEngine::class)
117128
->disableOriginalConstructor()
118129
->onlyMethods([
119130
'_createInstance',
120131
'_render',
121132
'_output',
122133
])
123-
->getMock()::class;
134+
->getMock();
124135

125136
$Pdf = new CakePdf([
126-
'engine' => '\\' . $engineClass,
137+
'engine' => $mock,
127138
]);
128139

140+
$mock->__construct($Pdf);
141+
129142
$DomPDF = new Dompdf();
130143

131144
$Engine = $Pdf->engine();
@@ -151,21 +164,23 @@ public function testControlFlow()
151164
*/
152165
public function testDompdfControlFlow()
153166
{
154-
$engineClass = $this->getMockBuilder(DomPdfEngine::class)
167+
$mock = $this->getMockBuilder(DomPdfEngine::class)
155168
->disableOriginalConstructor()
156169
->onlyMethods(['_createInstance'])
157-
->getMock()::class;
170+
->getMock();
158171

159172
$Pdf = new CakePdf([
160-
'engine' => '\\' . $engineClass,
173+
'engine' =>$mock,
161174
]);
162175

176+
$mock->__construct($Pdf);
177+
163178
$Pdf
164179
->engine()
165180
->expects($this->once())
166181
->method('_createInstance')
167-
->will($this->returnCallback(function ($options) {
168-
$Dompdf = $this->getMockBuilder('\Dompdf\Dompdf')
182+
->willReturnCallback(function ($options) {
183+
$Dompdf = $this->getMockBuilder(Dompdf::class)
169184
->onlyMethods(['setPaper', 'loadHtml', 'render', 'output'])
170185
->setConstructorArgs([$options])
171186
->getMock();
@@ -185,7 +200,7 @@ public function testDompdfControlFlow()
185200
->method('output');
186201

187202
return $Dompdf;
188-
}));
203+
});
189204

190205
$Pdf->engine()->output();
191206
}

tests/TestCase/Pdf/Engine/MpdfEngineTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,35 @@ public function setUp(): void
2727
*/
2828
public function testSetOptions()
2929
{
30-
$engineClass = $this->getMockBuilder(MpdfEngine::class)
30+
$mock = $this->getMockBuilder(MpdfEngine::class)
3131
->disableOriginalConstructor()
3232
->onlyMethods(['_createInstance'])
33-
->getMock()::class;
33+
->getMock();
3434

3535
$Pdf = new CakePdf([
3636
'engine' => [
37-
'className' => '\\' . $engineClass,
37+
'className' => $mock,
3838
],
3939
'pageSize' => 'A4',
4040
'orientation' => 'landscape',
4141
'tempDir' => TMP,
4242
]);
4343
$Pdf->html('');
4444

45+
$mock->__construct($Pdf);
46+
4547
$Pdf
4648
->engine()
4749
->expects($this->once())
4850
->method('_createInstance')
49-
->will($this->returnCallback(function ($config) {
51+
->willReturnCallback(function ($config) {
5052
$Mpdf = new Mpdf($config);
5153

5254
$this->assertSame(TMP, $Mpdf->tempDir);
5355
$this->assertSame('L', $Mpdf->CurOrientation);
5456

5557
return $Mpdf;
56-
}));
58+
});
5759

5860
$Pdf->engine()->output();
5961
}

0 commit comments

Comments
 (0)