Skip to content

Commit 2ab6d38

Browse files
authored
Modernize code and test setup, prepare for Symfony 5.x and PHP 8.x (#4)
1 parent b3352f1 commit 2ab6d38

15 files changed

+231
-135
lines changed

.github/workflows/dependencies.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Dependencies
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
pull_request:
11+
12+
env:
13+
PHP_VERSION: 7.4
14+
15+
jobs:
16+
composer-require-checker:
17+
name: Check missing composer requirements
18+
runs-on: ubuntu-20.04
19+
steps:
20+
- uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ env.PHP_VERSION }}
23+
tools: composer:v2
24+
- uses: actions/checkout@v2
25+
- uses: actions/cache@v2
26+
with:
27+
path: vendor
28+
key: composer-${{ runner.os }}-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }}
29+
restore-keys: |
30+
composer-${{ runner.os }}-${{ env.PHP_VERSION }}-
31+
composer-${{ runner.os }}-
32+
- run: |
33+
composer install --no-interaction --no-progress --ansi --no-scripts
34+
composer show
35+
- uses: docker://webfactory/composer-require-checker:3.2.0

.github/workflows/fix-cs-php.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Update this by running
2-
# curl https://gist.githubusercontent.com/mpdude/ca93a185bcbf56eb7e341632ad4f8263/raw/fix-cs-php.yml > .github/workflows/fix-cs-php.yml
3-
41
on:
52
push:
63
branches:
@@ -13,7 +10,6 @@ jobs:
1310
open-pr-for-cs-violations:
1411
name: PHP-CS-Fixer
1512
runs-on: ubuntu-20.04
16-
if: github.actor != 'dependabot[bot]'
1713
steps:
1814
- name: Checkout code
1915
uses: actions/checkout@v2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
cat <<< $(jq --arg version $VERSION '.require |= with_entries(if ((.key|test("^symfony/"))) then .value=$version else . end)' < composer.json) > composer.json

.github/workflows/tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
env:
10+
SYMFONY_DEPRECATIONS_HELPER: weak
11+
12+
jobs:
13+
PHPUnit:
14+
runs-on: ubuntu-20.04
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- { php-version: 7.2, symfony-locked-version: none, dependency-version: prefer-lowest }
20+
- { php-version: 7.4, symfony-locked-version: none, dependency-version: prefer-lowest }
21+
- { php-version: 7.4, symfony-locked-version: none, dependency-version: prefer-stable }
22+
- { php-version: 8.1, symfony-locked-version: none, dependency-version: prefer-stable }
23+
name: PHPUnit (PHP ${{matrix.php-version}}, Symfony Version Lock ${{ matrix.symfony-locked-version }}, ${{ matrix.dependency-version }})
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: ${{ matrix.php-version }}
29+
tools: composer:v2
30+
- uses: actions/cache@v2
31+
with:
32+
path: vendor
33+
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.symfony-locked-version }}-${{ matrix.dependency-version }}-${{ hashFiles('composer.json') }}
34+
restore-keys: |
35+
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.symfony-locked-version }}-${{ matrix.dependency-version }}-
36+
- run: VERSION=${{ matrix.symfony-locked-version }} .github/workflows/lock-symfony-version.sh
37+
if: matrix.symfony-locked-version != 'none'
38+
- run: composer update --${{ matrix.dependency-version }} --no-interaction --no-scripts --no-progress --ansi
39+
- run: composer show
40+
- run: vendor/bin/phpunit

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
vendor/
22
.php_cs.cache
3+
.phpunit.result.cache
4+
composer.lock

composer.json

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
11
{
2-
"name": "webfactory/http-cache-bundle",
3-
"description": "Symfony bundle to ease HTTP cache validation via last modified header",
4-
"keywords": [
5-
"caching",
6-
"http",
7-
"304",
8-
"notmodified",
9-
"ifnotmodifiedsince"
10-
],
11-
"license": "MIT",
12-
"authors": [
13-
{
14-
"name": "webfactory GmbH",
15-
"email": "[email protected]",
16-
"homepage": "http://www.webfactory.de",
17-
"role": "Developer"
18-
}
19-
],
2+
"name": "webfactory/http-cache-bundle",
3+
"description": "Symfony bundle to ease HTTP cache validation via last modified header",
4+
"keywords": [
5+
"caching",
6+
"http",
7+
"304",
8+
"notmodified",
9+
"ifnotmodifiedsince"
10+
],
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "webfactory GmbH",
15+
"email": "[email protected]",
16+
"homepage": "http://www.webfactory.de",
17+
"role": "Developer"
18+
}
19+
],
2020

21-
"require": {
22-
"php": "^7.1",
23-
"symfony/config": "^2.8 || ^3.0 || ^4.0",
24-
"symfony/dependency-injection": "^2.8 || ^3.0 || ^4.0",
25-
"symfony/http-foundation": "^2.8 || ^3.0 || ^4.0",
26-
"symfony/http-kernel": "^2.8 || ^3.0 || ^4.0",
27-
"doctrine/annotations": "^1.0"
28-
},
21+
"require": {
22+
"php": "^7.1|8.0.*|8.1.*",
23+
"symfony/config": "^4.4 | ^5.0",
24+
"symfony/dependency-injection": "^4.4 | ^5.0",
25+
"symfony/http-foundation": "^4.4 | ^5.0",
26+
"symfony/http-kernel": "^4.4 | ^5.0",
27+
"doctrine/annotations": "^1.0"
28+
},
2929

30-
"require-dev": {
31-
"phpunit/phpunit": "^4.8.0"
32-
},
30+
"require-dev": {
31+
"phpunit/phpunit": "^8.5|^9.0",
32+
"symfony/phpunit-bridge": ">=5.0"
33+
},
3334

34-
"suggest": {
35-
"webfactory/wfdmeta-bundle": "Invalidate caches based on meta data tracked with wfDynamic"
36-
},
35+
"suggest": {
36+
"webfactory/wfdmeta-bundle": "Invalidate caches based on meta data tracked with wfDynamic"
37+
},
3738

38-
"autoload": {
39-
"psr-4": {
40-
"Webfactory\\HttpCacheBundle\\": ""
39+
"autoload": {
40+
"psr-4": {
41+
"Webfactory\\HttpCacheBundle\\": "src"
42+
}
43+
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"Webfactory\\HttpCacheBundle\\Tests\\": "tests"
47+
}
4148
}
42-
}
4349
}

phpunit.xml.dist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd">
55
<testsuites>
66
<testsuite name="Library Test Suite">
7-
<directory>Tests</directory>
7+
<directory>tests</directory>
88
</testsuite>
99
</testsuites>
1010

1111
<!-- Filter for code coverage -->
1212
<filter>
1313
<whitelist processUncoveredFilesFromWhitelist="true">
1414
<directory suffix=".php">src/</directory>
15-
<exclude>
16-
<directory>vendor</directory>
17-
<directory>Tests</directory>
18-
</exclude>
1915
</whitelist>
2016
</filter>
17+
18+
<listeners>
19+
<listener class="\Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
20+
</listeners>
2121
</phpunit>

NotModified/EventListener.php renamed to src/NotModified/EventListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use SplObjectStorage;
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
1616
use Symfony\Component\HttpFoundation\Response;
17-
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
18-
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
17+
use Symfony\Component\HttpKernel\Event\ControllerEvent;
18+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1919
use Webfactory\HttpCacheBundle\NotModified\Annotation\ReplaceWithNotModifiedResponse;
2020

2121
/**
@@ -58,7 +58,7 @@ public function __construct(Reader $reader, ContainerInterface $container, bool
5858
* header in the request, replace the determined controller action with a minimal action that just returns an
5959
* "empty" response with a 304 Not Modified HTTP status code.
6060
*/
61-
public function onKernelController(FilterControllerEvent $event)
61+
public function onKernelController(ControllerEvent $event)
6262
{
6363
$annotation = $this->findAnnotation($event->getController());
6464
if (!$annotation) {
@@ -94,7 +94,7 @@ public function onKernelController(FilterControllerEvent $event)
9494
* If a last modified date was determined for the current (master or sub) request, set it to the response so the
9595
* client can use it for the "If-Modified-Since" header in subsequent requests.
9696
*/
97-
public function onKernelResponse(FilterResponseEvent $event)
97+
public function onKernelResponse(ResponseEvent $event)
9898
{
9999
$request = $event->getRequest();
100100
$response = $event->getResponse();

0 commit comments

Comments
 (0)