Skip to content

Commit df91859

Browse files
authored
Merge pull request #18 from pontedilana/feature/more_tests
Split GitHub workflow
2 parents 60533b8 + ac49fff commit df91859

File tree

3 files changed

+64
-9
lines changed

3 files changed

+64
-9
lines changed

.github/workflows/ci.yaml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
name: CI
2+
23
on:
34
- push
45
- pull_request
6+
7+
permissions:
8+
contents: read
9+
510
jobs:
6-
test:
7-
runs-on: ubuntu-latest
11+
phpstan:
12+
runs-on: ubuntu-24.04
13+
name: PHPStan
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v5
18+
19+
- name: Setup PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: "8.1"
23+
tools: phpstan
24+
25+
- name: Get composer cache directory
26+
id: composer-cache
27+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
28+
29+
- name: Cache composer dependencies
30+
uses: actions/cache@v3
31+
with:
32+
path: ${{ steps.composer-cache.outputs.dir }}
33+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
34+
restore-keys: ${{ runner.os }}-composer-
35+
36+
- name: Install dependencies
37+
run: composer install --no-progress --prefer-dist --optimize-autoloader
38+
39+
- name: Run PHPStan
40+
run: phpstan analyse src
41+
42+
phpunit:
43+
runs-on: ubuntu-24.04
844
strategy:
945
matrix:
1046
php-version:
@@ -16,17 +52,16 @@ jobs:
1652
- "8.4"
1753
- "8.5"
1854

19-
name: PHP ${{ matrix.php-version }}
55+
name: PHPUnit - PHP ${{ matrix.php-version }}
2056

2157
steps:
2258
- name: Checkout
23-
uses: actions/checkout@v4
59+
uses: actions/checkout@v5
2460

25-
- name: Setup PHP, with composer and extensions
61+
- name: Setup PHP
2662
uses: shivammathur/setup-php@v2
2763
with:
2864
php-version: ${{ matrix.php-version }}
29-
tools: phpstan
3065

3166
- name: Setup problem matchers for PHP
3267
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
@@ -48,8 +83,5 @@ jobs:
4883
- name: Install dependencies
4984
run: composer install --no-progress --prefer-dist --optimize-autoloader
5085

51-
- name: Run PHPStan
52-
run: phpstan analyse src
53-
5486
- name: Test with PHPUnit
5587
run: ./vendor/bin/phpunit

tests/Unit/AbstractGeneratorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,4 +926,17 @@ public function testFailingGenerateWithOutputContainingPharPrefix(): void
926926

927927
$media->generate('the_input_file', 'phar://the_output_file', ['foo' => 'bar']);
928928
}
929+
930+
/**
931+
* @covers \Pontedilana\PhpWeasyPrint\AbstractGenerator::getCommand
932+
*/
933+
public function testGetCommandThrowsExceptionWhenBinaryNotSet(): void
934+
{
935+
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);
936+
937+
$this->expectException(\LogicException::class);
938+
$this->expectExceptionMessage('You must define a binary prior to conversion.');
939+
940+
$media->getCommand('input.html', 'output.pdf');
941+
}
929942
}

tests/Unit/PdfTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ public function dataOptions(): array
161161
];
162162
}
163163

164+
public function testSetTimeoutConfiguresBothProcessAndWeasyPrintTimeout(): void
165+
{
166+
$testObject = new PdfSpy();
167+
$testObject->setTimeout(30);
168+
$testObject->getOutputFromHtml('<html></html>');
169+
170+
// Verify that --timeout 30 is in the command
171+
$this->assertMatchesRegularExpression('/--timeout 30/', $testObject->getLastCommand());
172+
}
173+
164174
public function testDisableTimeout(): void
165175
{
166176
$testObject = new PdfSpy();

0 commit comments

Comments
 (0)