Skip to content

Commit 6a38fd9

Browse files
committed
Create Github action for PHPUnit tests
1 parent 42b288f commit 6a38fd9

9 files changed

+47
-29
lines changed

.github/workflows/phpunit.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: PHPUnit tests
2+
on:
3+
push
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
php: [ '8.1', '8.2', '8.3', '8.4' ]
15+
name: On PHP ${{ matrix.php }}
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup PHP ${{ matrix.php }}
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php }}
24+
25+
- name: Install dependencies (latest)
26+
run: composer install --prefer-dist --no-progress
27+
28+
- name: Run test suite (latest)
29+
run: ./vendor/bin/phpunit
30+
31+
- name: Install dependencies (lowest)
32+
run: composer update --prefer-lowest --no-progress
33+
34+
- name: Run test suite (lowest)
35+
run: ./vendor/bin/phpunit

.travis.yml

-9
This file was deleted.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"twig/twig": "^2.15.3||^3.4.3"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "~4.3"
25+
"phpunit/phpunit": "~11.5.2"
2626
},
2727
"autoload": {
2828
"psr-4": { "TwigGenerator\\": "src/" }

phpunit.xml.dist

-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
54
bootstrap="tests/bootstrap.php"
65
colors="false"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
106
processIsolation="false"
117
stopOnFailure="false"
12-
syntaxCheck="false"
138
>
149
<testsuites>
1510
<testsuite name="TwigGenerator Test Suite">
1611
<directory>./tests/</directory>
1712
</testsuite>
1813
</testsuites>
19-
20-
<filter>
21-
<whitelist>
22-
<directory>./src/</directory>
23-
</whitelist>
24-
</filter>
2514
</phpunit>
2615

tests/TwigGenerator/Tests/Builder/BaseBuilderTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace TwigGenerator\Tests\Builder;
44

5+
use PHPUnit\Framework\TestCase;
56
use TwigGenerator\Tests\Builder\Fixtures\Builder\DemoBuilder;
67

7-
class BaseBuilderTest extends \PHPUnit_Framework_TestCase
8+
class BaseBuilderTest extends TestCase
89
{
910
public function testGetSimpleClassName(): void
1011
{

tests/TwigGenerator/Tests/Builder/GeneratorTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace TwigGenerator\Tests\Builder;
44

5+
use PHPUnit\Framework\TestCase;
56
use TwigGenerator\Tests\Builder\Fixtures\Builder\DemoBuilder;
67
use TwigGenerator\Builder\Generator;
78

8-
class GeneratorTest extends \PHPUnit_Framework_TestCase
9+
class GeneratorTest extends TestCase
910
{
1011
public function testAddBuilder(): void
1112
{

tests/TwigGenerator/Tests/Extension/BaseExtensionTest.php renamed to tests/TwigGenerator/Tests/Extension/AbstractExtensionTestCase.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace TwigGenerator\Tests\Extension;
33

4+
use PHPUnit\Framework\TestCase;
45
use Twig\Environment;
56
use Twig\Extension\AbstractExtension;
67
use Twig\Loader\ArrayLoader;
@@ -14,7 +15,7 @@
1415
* @package TwigGenerator\Tests\Extension
1516
* @author Stéphane Escandell
1617
*/
17-
abstract class BaseExtensionTest extends \PHPUnit_Framework_TestCase
18+
abstract class AbstractExtensionTestCase extends TestCase
1819
{
1920
/**
2021
* Variables used for templates
@@ -40,16 +41,16 @@ protected function runTwigTests(array $templates, array $returns): void
4041
'Error: invalid test case. Templates and returns keys mismatch: templates:[%s], returns:[%s] => [%s]',
4142
implode(', ', array_keys($templates)),
4243
implode(', ', array_keys($returns)),
43-
implode(', ', array_diff(array_keys($templates), array_keys($returns)))
44+
implode(', ', array_diff(array_keys($templates), array_keys($returns))),
4445
));
4546
}
4647
$twig = $this->getEnvironment($templates);
4748

4849
foreach ($templates as $name => $tpl) {
4950
$this->assertEquals(
5051
$returns[$name][0],
51-
$twig->loadTemplate($name)->render($this->twigVariables),
52-
$returns[$name][1]
52+
$twig->render($name, $this->twigVariables),
53+
$returns[$name][1],
5354
);
5455
}
5556
}

tests/TwigGenerator/Tests/Extension/PHPPrintExtensionTest.php renamed to tests/TwigGenerator/Tests/Extension/PHPPrintExtensionTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Test PHPPrintExtension class
88
*/
9-
class PHPPrintExtensionTest extends BaseExtensionTest
9+
class PHPPrintExtensionTestCase extends AbstractExtensionTestCase
1010
{
1111
protected function getTwigVariables(): array
1212
{

tests/TwigGenerator/Tests/Extension/TwigPrintExtensionTest.php renamed to tests/TwigGenerator/Tests/Extension/TwigPrintExtensionTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Test TwigPrintExtension class
88
*/
9-
class TwigPrintExtensionTest extends BaseExtensionTest
9+
class TwigPrintExtensionTestCase extends AbstractExtensionTestCase
1010
{
1111
protected function getTwigVariables(): array
1212
{

0 commit comments

Comments
 (0)