Skip to content

Commit bd68b05

Browse files
authored
Merge pull request #1 from phug-php/feature/github-actions
Drop Phug < 1
2 parents 9a914b1 + 9175d6d commit bd68b05

6 files changed

Lines changed: 131 additions & 42 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: [ '**' ]
6+
pull_request:
7+
branches: [ '**' ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php: ['7.4']
17+
setup: ['stable']
18+
19+
name: PHP
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
tools: composer:v2
29+
30+
- name: Cache Composer packages
31+
id: composer-cache
32+
uses: actions/cache@v2
33+
with:
34+
path: vendor
35+
key: ${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-
38+
39+
- name: Code Climate Test Reporter Preparation
40+
if: matrix.php == '7.4' && matrix.setup == 'stable'
41+
run: |
42+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
43+
chmod +x ./cc-test-reporter
44+
./cc-test-reporter before-build
45+
env:
46+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
47+
48+
- name: Install dependencies
49+
if: steps.composer-cache.outputs.cache-hit != 'true'
50+
run: composer update --prefer-dist --prefer-${{ matrix.setup }} --no-progress --no-interaction
51+
52+
- name: Run test suite
53+
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
54+
55+
- name: Code Climate Test Reporter
56+
if: ${{ matrix.php == '7.4' && matrix.setup == 'stable' && env.CC_TEST_REPORTER_ID != '' }}
57+
run: |
58+
cp coverage.xml clover.xml
59+
bash <(curl -s https://codecov.io/bash)
60+
./cc-test-reporter after-build --coverage-input-type clover --exit-code 0
61+
env:
62+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

.github/workflows/tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ '**' ]
6+
pull_request:
7+
branches: [ '**' ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
17+
setup: ['lowest', 'stable']
18+
19+
name: PHP ${{ matrix.php }} - ${{ matrix.setup }}
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
tools: composer:v2
29+
30+
- name: Cache Composer packages
31+
id: composer-cache
32+
uses: actions/cache@v2
33+
with:
34+
path: vendor
35+
key: ${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-
38+
39+
- name: Install dependencies
40+
if: steps.composer-cache.outputs.cache-hit != 'true'
41+
run: |
42+
${{ matrix.php >= 8.1 && 'composer require --no-update phpunit/phpunit:^8.5.15 --no-interaction;' || '' }}
43+
composer update --prefer-dist --prefer-${{ matrix.setup }} --no-progress --no-interaction ${{ matrix.php >= 8.1 && '--ignore-platform-req=php' || '' }}
44+
45+
- name: Run test suite
46+
run: vendor/bin/phpunit --no-coverage --verbose

.travis.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
],
1212
"require": {
1313
"php": ">=7.0",
14-
"phug/compiler": "^0.5.0 || ^1.0.0",
15-
"phug/formatter": "^0.5.42 || ^1.0.0"
14+
"phug/compiler": "^1.0.0",
15+
"phug/formatter": "^1.0.0"
1616
},
1717
"require-dev": {
18-
"phug/phug": "^0.3.2 || ^1.0.0",
19-
"phpunit/phpunit": ">=4.8.35 <6.0",
20-
"codeclimate/php-test-reporter": "dev-master",
18+
"phug/phug": "^1.0.0",
19+
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.5",
2120
"machy8/xhtml-formatter": "^1.0",
2221
"js-phpize/js-phpize-phug": "^2.1"
2322
},

src/PhugBemto/PhugBemto.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function __construct(ModuleContainerInterface $container)
1212
parent::__construct($container);
1313

1414
$file = realpath(__DIR__ . '/../../bemto.pug');
15-
$includes = $container->getOption('includes');
15+
$includes = $container->getOption('includes') ?? [];
1616

1717
if (!in_array($file, $includes)) {
1818
$includes[] = $file;

tests/AbstractTestCase.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ abstract class AbstractTestCase extends TestCase
2222
/**
2323
* @throws \Phug\RendererException
2424
*/
25-
protected function setUp()
25+
protected function getRenderer(): Renderer
2626
{
27-
parent::setUp();
28-
$this->renderer = new Renderer([
29-
'debug' => true,
30-
'execution_max_time' => 180000,
31-
'modules' => array_merge([
32-
PhugBemto::class,
33-
], $this->modules),
34-
]);
27+
if (!isset($this->renderer)) {
28+
$this->renderer = new Renderer([
29+
'debug' => true,
30+
'execution_max_time' => 180000,
31+
'modules' => array_merge([
32+
PhugBemto::class,
33+
], $this->modules),
34+
]);
35+
}
36+
37+
return $this->renderer;
3538
}
3639

3740
protected function renderFile($sourceFile)
@@ -40,13 +43,13 @@ protected function renderFile($sourceFile)
4043
$actualOutput = null;
4144

4245
try {
43-
$actualOutput = $this->renderer->renderFile($sourceFile);
46+
$actualOutput = $this->getRenderer()->renderFile($sourceFile);
4447
} catch (\Throwable $exception) {
4548
$error = $exception;
4649

4750
try {
4851
$debugFile = __DIR__ . '/../debug.php';
49-
file_put_contents($debugFile, $this->renderer->compileFile($sourceFile));
52+
file_put_contents($debugFile, $this->getRenderer()->compileFile($sourceFile));
5053
include $debugFile;
5154
} catch (\Throwable $exception) {
5255
throw new \Exception('Error in ' . $sourceFile . "\n" . $exception->getMessage(), 0, $exception);
@@ -72,6 +75,10 @@ protected static function htmlStandardize($html)
7275
$html = preg_replace('/([a-z"\'])\/>/', '$1 />', $html);
7376
$html = preg_replace('/(<[a-z][^>]*)\s\/>/', '$1>', $html);
7477

78+
if (version_compare(PHP_VERSION, '8.1.0-dev', '>=')) {
79+
$html = str_replace('&#039;', "'", $html);
80+
}
81+
7582
return $html;
7683
}
7784

0 commit comments

Comments
 (0)