Skip to content

Commit fe22c95

Browse files
committed
support PHP8.0, phpunit ^8.5 & ^9.3
1 parent 753c64d commit fe22c95

File tree

8 files changed

+68
-154
lines changed

8 files changed

+68
-154
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI
33
on:
44
push:
55
branches:
6-
- '2.x'
6+
- '2.0'
77
pull_request:
88
branches:
99
- '*'
@@ -19,10 +19,7 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
php-version:
22-
- '8.1'
23-
- '8.2'
24-
- '8.3'
25-
- '8.4'
22+
- '8.0'
2623

2724
steps:
2825
- uses: actions/checkout@v4
@@ -45,16 +42,38 @@ jobs:
4542
env:
4643
XDEBUG_MODE: coverage
4744
run: |
48-
if [[ '${{ matrix.php-version }}' == '8.1' ]]; then
45+
if [[ '${{ matrix.php-version }}' == '8.0' ]]; then
4946
export CODECOVERAGE=1
5047
vendor/bin/phpunit --coverage-clover=coverage.xml
5148
else
5249
vendor/bin/phpunit
5350
fi
5451
5552
- name: Submit code coverage
56-
if: matrix.php-version == '8.1'
53+
if: matrix.php-version == '8.0'
5754
uses: codecov/codecov-action@v5
5855
with:
5956
files: coverage.xml
6057
token: ${{ secrets.CODECOV_TOKEN }}
58+
59+
cs-stan:
60+
name: Coding Standard & Static Analysis
61+
runs-on: ubuntu-24.04
62+
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Setup PHP
67+
uses: shivammathur/setup-php@v2
68+
with:
69+
php-version: '8.0'
70+
extensions: mbstring, intl
71+
coverage: none
72+
tools: phive, cs2pr
73+
74+
- name: Composer install
75+
run: composer update
76+
77+
- name: Run phpcs
78+
if: always()
79+
run: vendor/bin/phpcs --report=checkstyle src/ tests/ | cs2pr

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
44
[![codecov](https://codecov.io/gh/Erwane/phpunit-resource-helper/branch/2.x/graph/badge.svg?token=hF5HhETnkg)](https://codecov.io/gh/Erwane/phpunit-resource-helper)
5-
[![Build Status](https://github.com/Erwane/phpunit-resource-helper/actions/workflows/ci.yml/badge.svg?branch=2.x)](https://github.com/Erwane/phpunit-resource-helper/actions)
5+
[![Build Status](https://github.com/Erwane/phpunit-resource-helper/actions/workflows/ci.yml/badge.svg?branch=2.0)](https://github.com/Erwane/phpunit-resource-helper/actions)
66
[![Packagist Downloads](https://img.shields.io/packagist/dt/Erwane/phpunit-resource-helper)](https://packagist.org/packages/Erwane/phpunit-resource-helper)
77
[![Packagist Version](https://img.shields.io/packagist/v/Erwane/phpunit-resource-helper)](https://packagist.org/packages/Erwane/phpunit-resource-helper)
88

@@ -12,10 +12,10 @@ Help your phpunit tests to load resources from files, like, json content, raw e-
1212

1313
## Version map
1414

15-
| branch | This package version | PHP min |
16-
|:------:|----------------------|:-------:|
17-
| 1.x | ^1.0 | PHP 7.2 |
18-
| 2.x | ^2.0 | PHP 8.1 |
15+
| branch | This package version | PHP min | PHPUnit |
16+
|:------:|----------------------|:-------:|:------------:|
17+
| 1.x | ^1.0 | PHP 7.2 | ^8.0 |
18+
| 2.0 | ^2.0 | PHP 8.0 | ^8.5 \| ^9.3 |
1919

2020
## Usage
2121

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^8.1",
25-
"ext-json": "*"
24+
"php": "8.0.*",
25+
"ext-json": "*",
26+
"phpunit/phpunit":"^8.5 | ^9.3"
2627
},
2728
"require-dev": {
28-
"cakephp/cakephp-codesniffer": "^5.0",
29-
"phpunit/phpunit": "^10.5",
29+
"cakephp/cakephp-codesniffer": "^4.0",
3030
"symfony/var-dumper": "^v6.0"
3131
},
3232
"autoload": {

phpunit.xml.dist

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4-
bootstrap="tests/bootstrap.php"
5-
colors="true"
6-
cacheDirectory="tmp/phpunit.cache"
7-
displayDetailsOnPhpunitDeprecations="true"
8-
displayDetailsOnTestsThatTriggerDeprecations="true"
9-
displayDetailsOnTestsThatTriggerErrors="true"
10-
displayDetailsOnTestsThatTriggerWarnings="true">
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" bootstrap="tests/bootstrap.php"
4+
colors="true">
5+
<coverage>
6+
<include>
7+
<directory suffix=".php">src/</directory>
8+
</include>
9+
</coverage>
1110
<testsuites>
1211
<testsuite name="all">
1312
<directory>./tests</directory>
1413
</testsuite>
1514
</testsuites>
1615

17-
<source>
18-
<include>
19-
<directory suffix=".php">src/</directory>
20-
</include>
21-
</source>
22-
2316
<extensions>
24-
<bootstrap class="ResourceHelper\PHPUnitExtension"></bootstrap>
17+
<extension class="ResourceHelper\PHPUnitExtension"></extension>
2518
</extensions>
2619
</phpunit>

src/Extension/CleanupSubscriber.php

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

src/PHPUnitExtension.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@
1010

1111
namespace ResourceHelper;
1212

13-
use PHPUnit\Runner\Extension\Extension;
14-
use PHPUnit\Runner\Extension\Facade;
15-
use PHPUnit\Runner\Extension\ParameterCollection;
16-
use PHPUnit\TextUI\Configuration\Configuration;
17-
use ResourceHelper\Extension\CleanupSubscriber;
13+
use PHPUnit\Runner\AfterSuccessfulTestHook;
1814

1915
/**
20-
* PHPUnit extension.
21-
*
22-
* @codeCoverageIgnore
16+
* PHPUnit extension to clean up temp files.
2317
*/
24-
class PHPUnitExtension implements Extension
18+
class PHPUnitExtension implements AfterSuccessfulTestHook
2519
{
26-
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
20+
/**
21+
* Cleanup test files if case of successful result.
22+
*
23+
* @param string $test Test name with namespace
24+
* @param float $time Test duration time
25+
* @return void
26+
*/
27+
public function executeAfterSuccessfulTest(string $test, float $time): void
2728
{
28-
$facade->registerSubscriber(new CleanupSubscriber());
29+
ResourceHelper::destroyTmpTestDir($test);
2930
}
3031
}

tests/TestCase/Extension/CleanupSubscriberTest.php

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

tests/TestCase/PHPUnitExtensionTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,26 @@
1010

1111
namespace ResourceHelper\Test\TestCase;
1212

13-
use PHPUnit\Framework\Attributes\CoversClass;
1413
use PHPUnit\Framework\TestCase;
1514
use ResourceHelper\PHPUnitExtension;
15+
use ResourceHelper\ResourceHelper;
1616

17-
#[CoversClass(PHPUnitExtension::class)]
17+
/**
18+
* @uses \ResourceHelper\PHPUnitExtension
19+
* @covers \ResourceHelper\PHPUnitExtension
20+
*/
1821
class PHPUnitExtensionTest extends TestCase
1922
{
2023
public function testAfterSuccessfulTest(): void
2124
{
2225
$ext = new PHPUnitExtension();
23-
$this->assertTrue(method_exists($ext, 'bootstrap'));
26+
$this->assertTrue(method_exists($ext, 'executeAfterSuccessfulTest'));
27+
28+
// Create tmp test dir
29+
ResourceHelper::createTmpTestDir($this);
30+
31+
$ext->executeAfterSuccessfulTest($this->toString(), 0.3);
32+
33+
$this->assertDirectoryDoesNotExist(ResourceHelper::getTmpTestPath($this));
2434
}
2535
}

0 commit comments

Comments
 (0)