Skip to content

Commit 109eefe

Browse files
committed
Migrate to GitHub Actions
1 parent 0e97c2e commit 109eefe

File tree

9 files changed

+198
-41
lines changed

9 files changed

+198
-41
lines changed

.github/workflows/tests.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Tests
2+
on: pull_request
3+
jobs:
4+
phpunit:
5+
name: PHP ${{ matrix.php }}
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
php:
10+
- "5.3"
11+
- "5.4"
12+
- "5.5"
13+
- "5.6"
14+
- "7.0"
15+
- "7.1"
16+
- "7.2"
17+
- "7.3"
18+
- "7.4"
19+
- "8.0"
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
24+
- name: Install xvfb
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install xvfb
28+
29+
- name: Install wkhtmltopdf
30+
run: |
31+
cd /tmp
32+
sudo wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
33+
sudo apt install -y -q ./wkhtmltox_0.12.6-1.focal_amd64.deb
34+
wkhtmltopdf --version
35+
36+
- name: Install PHP
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php }}
40+
tools: composer:v2
41+
42+
- name: Update composer
43+
run: composer self-update
44+
45+
- name: Get composer cache directory
46+
id: composer-cache
47+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
48+
49+
- name: Cache composer cache
50+
uses: actions/cache@v2
51+
with:
52+
path: ${{ steps.composer-cache.outputs.dir }}
53+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
54+
restore-keys: ${{ runner.os }}-composer-
55+
56+
- name: Install composer packages
57+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
58+
59+
- name: Run phpunit
60+
run: vendor/bin/phpunit --color=always

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ composer.lock
22
phpunit.xml
33
/vendor/
44
*.swp
5+
.phpunit.result.cache

.travis.yml

-19
This file was deleted.

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
PHP WkHtmlToPdf
22
===============
33

4-
[![Build Status](https://secure.travis-ci.org/mikehaertl/phpwkhtmltopdf.png)](http://travis-ci.org/mikehaertl/phpwkhtmltopdf)
5-
[![Latest Stable Version](https://poser.pugx.org/mikehaertl/phpwkhtmltopdf/v/stable.svg)](https://packagist.org/packages/mikehaertl/phpwkhtmltopdf)
6-
[![Total Downloads](https://poser.pugx.org/mikehaertl/phpwkhtmltopdf/downloads)](https://packagist.org/packages/mikehaertl/phpwkhtmltopdf)
7-
[![License](https://poser.pugx.org/mikehaertl/phpwkhtmltopdf/license.svg)](https://packagist.org/packages/mikehaertl/phpwkhtmltopdf)
4+
[![GitHub Tests](https://github.com/mikehaertl/phpwkhtmltopdf/workflows/Tests/badge.svg)](https://github.com/mikehaertl/phpwkhtmltopdf/actions)
5+
[![Packagist Version](https://img.shields.io/packagist/v/mikehaertl/phpwkhtmltopdf?label=version)](https://packagist.org/packages/mikehaertl/phpwkhtmltopdf)
6+
[![Packagist Downloads](https://img.shields.io/packagist/dt/mikehaertl/phpwkhtmltopdf)](https://packagist.org/packages/mikehaertl/phpwkhtmltopdf)
7+
[![GitHub license](https://img.shields.io/github/license/mikehaertl/phpwkhtmltopdf)](https://github.com/mikehaertl/phpwkhtmltopdf/blob/master/LICENSE)
8+
[![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/mikehaertl/phpwkhtmltopdf)](https://packagist.org/packages/mikehaertl/phpwkhtmltopdf)
89

910
PHP WkHtmlToPdf provides a simple and clean interface to ease PDF and image creation with
1011
[wkhtmltopdf](http://wkhtmltopdf.org). **The `wkhtmltopdf` and - optionally - `wkhtmltoimage`

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
}
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": ">4.0 <8"
30+
"phpunit/phpunit": ">4.0 <9.4"
3131
}
3232
}

phpunit.xml.dist

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
bootstrap="./tests/bootstrap.php"
1312
>
1413
<testsuites>

tests/ImageTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ public function testCanCreateImageFromHtmlString()
3535
$this->assertFileExists($outFile);
3636

3737
$tmpFile = $image->getImageFilename();
38-
$this->assertRegExp("#$binary '[^ ]+' '$tmpFile'#", (string) $image->getCommand());
38+
$regex = "#$binary '[^ ]+' '$tmpFile'#";
39+
$command = (string) $image->getCommand();
40+
if (phpUnitVersion('<', 9)) {
41+
$this->assertRegExp($regex, $command);
42+
} else {
43+
$this->assertMatchesRegularExpression($regex, $command);
44+
}
3945
unlink($outFile);
4046
}
4147
public function testCanCreateImageFromUrl()
@@ -84,7 +90,13 @@ public function testCanSetPageFromHtmlString()
8490
$this->assertFileExists($outFile);
8591

8692
$tmpFile = $image->getImageFilename();
87-
$this->assertRegExp("#$binary '[^ ]+' '$tmpFile'#", (string) $image->getCommand());
93+
$regex = "#$binary '[^ ]+' '$tmpFile'#";
94+
$command = (string) $image->getCommand();
95+
if (phpUnitVersion('<', 9)) {
96+
$this->assertRegExp($regex, $command);
97+
} else {
98+
$this->assertMatchesRegularExpression($regex, $command);
99+
}
88100
unlink($outFile);
89101
}
90102
public function testCanSetPageFromUrl()

tests/PdfTest.php

+98-14
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ public function testCanCreatePdfFromHtmlString()
3636
$this->assertFileExists($outFile);
3737

3838
$tmpFile = $pdf->getPdfFilename();
39-
$this->assertRegExp("#$binary '[^ ]+' '$tmpFile'#", (string) $pdf->getCommand());
39+
$regex = "#$binary '[^ ]+' '$tmpFile'#";
40+
$command = (string) $pdf->getCommand();
41+
if (phpUnitVersion('<', 9)) {
42+
$this->assertRegExp($regex, $command);
43+
} else {
44+
$this->assertMatchesRegularExpression($regex, $command);
45+
}
4046
unlink($outFile);
4147
}
4248
public function testCanCreatePdfFromXmlString()
@@ -50,7 +56,13 @@ public function testCanCreatePdfFromXmlString()
5056
$this->assertFileExists($outFile);
5157

5258
$tmpFile = $pdf->getPdfFilename();
53-
$this->assertRegExp("#$binary '[^ ]+' '$tmpFile'#", (string) $pdf->getCommand());
59+
$regex = "#$binary '[^ ]+' '$tmpFile'#";
60+
$command = (string) $pdf->getCommand();
61+
if (phpUnitVersion('<', 9)) {
62+
$this->assertRegExp($regex, $command);
63+
} else {
64+
$this->assertMatchesRegularExpression($regex, $command);
65+
}
5466
unlink($outFile);
5567
}
5668
public function testCanCreatePdfFromUrl()
@@ -101,7 +113,13 @@ public function testCanAddPagesFromHtmlString()
101113
$this->assertFileExists($outFile);
102114

103115
$tmpFile = $pdf->getPdfFilename();
104-
$this->assertRegExp("#$binary '[^ ]+' '[^ ]+' '$tmpFile'#", (string) $pdf->getCommand());
116+
$regex = "#$binary '[^ ]+' '[^ ]+' '$tmpFile'#";
117+
$command = (string) $pdf->getCommand();
118+
if (phpUnitVersion('<', 9)) {
119+
$this->assertRegExp($regex, $command);
120+
} else {
121+
$this->assertMatchesRegularExpression($regex, $command);
122+
}
105123
unlink($outFile);
106124
}
107125
public function testCanAddPagesFromUrl()
@@ -130,7 +148,13 @@ public function testCanAddPageFromHtmlString()
130148
$pdf->binary = $binary;
131149
$pdf->addPage('<html><h1>test</h1></html>');
132150
$pdf->saveAs($outFile);
133-
$this->assertRegexp('/tmp_wkhtmlto_pdf_.*?\.html/', $pdf->getCommand()->getExecCommand());
151+
$regex = "/tmp_wkhtmlto_pdf_.*?\.html/";
152+
$command = (string) $pdf->getCommand()->getExecCommand();
153+
if (phpUnitVersion('<', 9)) {
154+
$this->assertRegExp($regex, $command);
155+
} else {
156+
$this->assertMatchesRegularExpression($regex, $command);
157+
}
134158
unlink($outFile);
135159
}
136160
public function testCanAddPageFromFileInstance()
@@ -142,7 +166,13 @@ public function testCanAddPageFromFileInstance()
142166
$pdf->binary = $binary;
143167
$pdf->addPage(new File('Some content', '.html'));
144168
$pdf->saveAs($outFile);
145-
$this->assertRegexp('/php_tmpfile_.*?\.html/', $pdf->getCommand()->getExecCommand());
169+
$regex = "/php_tmpfile_.*?\.html/";
170+
$command = (string) $pdf->getCommand()->getExecCommand();
171+
if (phpUnitVersion('<', 9)) {
172+
$this->assertRegExp($regex, $command);
173+
} else {
174+
$this->assertMatchesRegularExpression($regex, $command);
175+
}
146176
unlink($outFile);
147177
}
148178
public function testCanAddPageFromXmlString()
@@ -154,7 +184,13 @@ public function testCanAddPageFromXmlString()
154184
$pdf->binary = $binary;
155185
$pdf->addPage('<xml>test</xml>');
156186
$pdf->saveAs($outFile);
157-
$this->assertRegexp('/tmp_wkhtmlto_pdf_.*?\.xml/', $pdf->getCommand()->getExecCommand());
187+
$regex = "/tmp_wkhtmlto_pdf_.*?\.xml/";
188+
$command = (string) $pdf->getCommand()->getExecCommand();
189+
if (phpUnitVersion('<', 9)) {
190+
$this->assertRegExp($regex, $command);
191+
} else {
192+
$this->assertMatchesRegularExpression($regex, $command);
193+
}
158194
unlink($outFile);
159195
}
160196
public function testCanAddHtmlPageFromStringByType()
@@ -166,7 +202,13 @@ public function testCanAddHtmlPageFromStringByType()
166202
$pdf->binary = $binary;
167203
$pdf->addPage('Test', array(), Pdf::TYPE_HTML);
168204
$pdf->saveAs($outFile);
169-
$this->assertRegexp('/tmp_wkhtmlto_pdf_.*?\.html/', $pdf->getCommand()->getExecCommand());
205+
$regex = "/tmp_wkhtmlto_pdf_.*?\.html/";
206+
$command = (string) $pdf->getCommand()->getExecCommand();
207+
if (phpUnitVersion('<', 9)) {
208+
$this->assertRegExp($regex, $command);
209+
} else {
210+
$this->assertMatchesRegularExpression($regex, $command);
211+
}
170212
unlink($outFile);
171213
}
172214
public function testCanAddXmlPageFromStringByType()
@@ -178,7 +220,13 @@ public function testCanAddXmlPageFromStringByType()
178220
$pdf->binary = $binary;
179221
$pdf->addPage('Test', array(), Pdf::TYPE_XML);
180222
$pdf->saveAs($outFile);
181-
$this->assertRegexp('/tmp_wkhtmlto_pdf_.*?\.xml/', $pdf->getCommand()->getExecCommand());
223+
$regex = "/tmp_wkhtmlto_pdf_.*?\.xml/";
224+
$command = (string) $pdf->getCommand()->getExecCommand();
225+
if (phpUnitVersion('<', 9)) {
226+
$this->assertRegExp($regex, $command);
227+
} else {
228+
$this->assertMatchesRegularExpression($regex, $command);
229+
}
182230
unlink($outFile);
183231
}
184232

@@ -213,7 +261,13 @@ public function testCanAddCoverFromHtmlString()
213261
$this->assertFileExists($outFile);
214262

215263
$tmpFile = $pdf->getPdfFilename();
216-
$this->assertRegExp("#$binary 'cover' '[^ ]+' '$tmpFile'#", (string) $pdf->getCommand());
264+
$regex = "#$binary 'cover' '[^ ]+' '$tmpFile'#";
265+
$command = (string) $pdf->getCommand();
266+
if (phpUnitVersion('<', 9)) {
267+
$this->assertRegExp($regex, $command);
268+
} else {
269+
$this->assertMatchesRegularExpression($regex, $command);
270+
}
217271
unlink($outFile);
218272
}
219273
public function testCanAddCoverFromUrl()
@@ -246,7 +300,13 @@ public function testCanAddToc()
246300
$this->assertFileExists($outFile);
247301

248302
$tmpFile = $pdf->getPdfFilename();
249-
$this->assertRegExp("#$binary '[^ ]+' 'toc' '$tmpFile'#", (string) $pdf->getCommand());
303+
$regex = "#$binary '[^ ]+' 'toc' '$tmpFile'#";
304+
$command = (string) $pdf->getCommand();
305+
if (phpUnitVersion('<', 9)) {
306+
$this->assertRegExp($regex, $command);
307+
} else {
308+
$this->assertMatchesRegularExpression($regex, $command);
309+
}
250310
unlink($outFile);
251311
}
252312

@@ -290,7 +350,13 @@ public function testCanPassGlobalOptionsInConstructor()
290350
$this->assertTrue($pdf->saveAs($outFile));
291351

292352
$this->assertFileExists($outFile);
293-
$this->assertRegExp("#$binary '--header-html' '$tmpDir/tmp_wkhtmlto_pdf_[^ ]+\.html' '--no-outline' '--margin-top' '0' '--allow' '/tmp' '--allow' '/test' '$inFile' '$tmpDir/tmp_wkhtmlto_pdf_[^ ]+\.pdf'#", (string) $pdf->getCommand());
353+
$regex = "#$binary '--header-html' '$tmpDir/tmp_wkhtmlto_pdf_[^ ]+\.html' '--no-outline' '--margin-top' '0' '--allow' '/tmp' '--allow' '/test' '$inFile' '$tmpDir/tmp_wkhtmlto_pdf_[^ ]+\.pdf'#";
354+
$command = (string) $pdf->getCommand();
355+
if (phpUnitVersion('<', 9)) {
356+
$this->assertRegExp($regex, $command);
357+
} else {
358+
$this->assertMatchesRegularExpression($regex, $command);
359+
}
294360
unlink($outFile);
295361
}
296362
public function testCanSetGlobalOptions()
@@ -366,7 +432,13 @@ public function testCanAddHeaderAndFooterAsHtml()
366432
$this->assertFileExists($outFile);
367433

368434
$tmpFile = $pdf->getPdfFilename();
369-
$this->assertRegExp("#$binary '--header-html' '/tmp/[^ ]+' '--footer-html' '/tmp/[^ ]+' '$inFile' '$tmpFile'#", (string) $pdf->getCommand());
435+
$regex = "#$binary '--header-html' '/tmp/[^ ]+' '--footer-html' '/tmp/[^ ]+' '$inFile' '$tmpFile'#";
436+
$command = (string) $pdf->getCommand();
437+
if (phpUnitVersion('<', 9)) {
438+
$this->assertRegExp($regex, $command);
439+
} else {
440+
$this->assertMatchesRegularExpression($regex, $command);
441+
}
370442
unlink($outFile);
371443
}
372444
public function testCanAddHeaderAndFooterAsFile()
@@ -385,7 +457,13 @@ public function testCanAddHeaderAndFooterAsFile()
385457
$this->assertFileExists($outFile);
386458

387459
$tmpFile = $pdf->getPdfFilename();
388-
$this->assertRegExp("#$binary '--header-html' '/tmp/[^ ]+' '--footer-html' '/tmp/[^ ]+' '$inFile' '$tmpFile'#", (string) $pdf->getCommand());
460+
$regex = "#$binary '--header-html' '/tmp/[^ ]+' '--footer-html' '/tmp/[^ ]+' '$inFile' '$tmpFile'#";
461+
$command = (string) $pdf->getCommand();
462+
if (phpUnitVersion('<', 9)) {
463+
$this->assertRegExp($regex, $command);
464+
} else {
465+
$this->assertMatchesRegularExpression($regex, $command);
466+
}
389467
unlink($outFile);
390468
}
391469
public function testCanAddHeaderAndFooterAsHtmlToPagesAndCoverAndToc()
@@ -413,7 +491,13 @@ public function testCanAddHeaderAndFooterAsHtmlToPagesAndCoverAndToc()
413491
$this->assertFileExists($outFile);
414492

415493
$tmpFile = $pdf->getPdfFilename();
416-
$this->assertRegExp("#$binary '/tmp/[^ ]+\.html' '--header-html' '/tmp/[^ ]+\.html' '--footer-html' '/tmp/[^ ]+\.html' 'cover' '$inFile' '--header-html' '/tmp/[^ ]+\.html' '--footer-html' '/tmp/[^ ]+\.html' 'toc' '--header-html' '/tmp/[^ ]+\.html' '--footer-html' '/tmp/[^ ]+\.html' '$tmpFile'#", (string) $pdf->getCommand());
494+
$regex = "#$binary '/tmp/[^ ]+\.html' '--header-html' '/tmp/[^ ]+\.html' '--footer-html' '/tmp/[^ ]+\.html' 'cover' '$inFile' '--header-html' '/tmp/[^ ]+\.html' '--footer-html' '/tmp/[^ ]+\.html' 'toc' '--header-html' '/tmp/[^ ]+\.html' '--footer-html' '/tmp/[^ ]+\.html' '$tmpFile'#";
495+
$command = (string) $pdf->getCommand();
496+
if (phpUnitVersion('<', 9)) {
497+
$this->assertRegExp($regex, $command);
498+
} else {
499+
$this->assertMatchesRegularExpression($regex, $command);
500+
}
417501
unlink($outFile);
418502
}
419503

tests/bootstrap.php

+19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
<?php
2+
/*
23
// Some travis environments use phpunit > 6
34
$newClass = '\PHPUnit\Framework\TestCase';
45
$oldClass = '\PHPUnit_Framework_TestCase';
56
if (!class_exists($newClass) && class_exists($oldClass)) {
67
class_alias($oldClass, $newClass);
78
}
9+
*/
10+
11+
/**
12+
* Utility method to check the version of PHPUnit.
13+
*
14+
* Example: phpUnitVersion('<', '8.3'); // true e.g. for 8.2.1
15+
*
16+
* @param string $operator an operator like '>', '<', etc.
17+
* @param string $version the version to check against
18+
* @return bool whether PHPUnit matches the version to check
19+
*/
20+
function phpUnitVersion($operator, $version)
21+
{
22+
$phpUnitVersion = class_exists('\PHPUnit\Runner\Version') ?
23+
call_user_func(array('\PHPUnit\Runner\Version', 'id')) :
24+
call_user_func(array('\PHPUnit_Runner_Version', 'id'));
25+
return version_compare($phpUnitVersion, $version, $operator);
26+
}
827

928
require __DIR__ . '/../vendor/autoload.php';
1029

0 commit comments

Comments
 (0)