Skip to content

Commit a08e7b6

Browse files
authored
ci: setup GitHub Actions (symfony#8)
1 parent a90d68c commit a08e7b6

File tree

9 files changed

+233
-21
lines changed

9 files changed

+233
-21
lines changed

.github/workflows/ci.yml

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
php-cs-fixer:
9+
runs-on: ubuntu-latest
10+
name: Coding Standards
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: '7.4' # PHP CS Fixer isn't compatible with PHP 8 yet https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4702
19+
tools: cs2pr
20+
21+
- name: Get composer cache directory
22+
id: composercache
23+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
24+
25+
- name: Cache dependencies
26+
uses: actions/cache@v2
27+
with:
28+
path: ${{ steps.composercache.outputs.dir }}
29+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
30+
restore-keys: ${{ runner.os }}-composer-
31+
32+
- name: Install dependencies
33+
run: composer install --prefer-dist
34+
35+
- name: PHP Coding Standards Fixer
36+
run: vendor/bin/php-cs-fixer fix --dry-run --format checkstyle | cs2pr
37+
38+
phpstan:
39+
runs-on: ubuntu-latest
40+
name: Static Analysis
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v2
44+
45+
- name: Setup PHP
46+
uses: shivammathur/setup-php@v2
47+
with:
48+
php-version: '8.0'
49+
50+
- name: Get composer cache directory
51+
id: composercache
52+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
53+
54+
- name: Cache dependencies
55+
uses: actions/cache@v2
56+
with:
57+
path: ${{ steps.composercache.outputs.dir }}
58+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
59+
restore-keys: ${{ runner.os }}-composer-
60+
61+
- name: Install dependencies
62+
run: composer install --prefer-dist
63+
64+
- name: Install PHPUnit dependencies
65+
run: vendor/bin/simple-phpunit --version
66+
67+
- name: PHPStan
68+
run: vendor/bin/phpstan analyse --no-progress
69+
70+
phpunit:
71+
runs-on: ubuntu-latest
72+
strategy:
73+
matrix:
74+
php-versions: ['7.2', '7.3', '7.4', '8.0']
75+
fail-fast: false
76+
name: PHP ${{ matrix.php-versions }} Test on ubuntu-latest
77+
78+
services:
79+
mercure:
80+
image: dunglas/mercure
81+
env:
82+
SERVER_NAME: :3000
83+
MERCURE_PUBLISHER_JWT_KEY: '!ChangeMe!'
84+
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeMe!'
85+
MERCURE_EXTRA_DIRECTIVES: |
86+
anonymous
87+
cors_origins *
88+
ports:
89+
- 3000:3000
90+
91+
steps:
92+
- name: Checkout
93+
uses: actions/checkout@v2
94+
95+
- name: Setup PHP
96+
uses: shivammathur/setup-php@v2
97+
with:
98+
php-version: ${{ matrix.php-versions }}
99+
100+
- name: Get composer cache directory
101+
id: composercache
102+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
103+
104+
- name: Cache PHP dependencies
105+
uses: actions/cache@v2
106+
with:
107+
path: ${{ steps.composercache.outputs.dir }}
108+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
109+
restore-keys: ${{ runner.os }}-composer-
110+
111+
- name: Install PHP dependencies
112+
run: composer install --prefer-dist
113+
114+
- name: Get yarn cache directory path
115+
id: yarn-cache-dir-path
116+
run: echo "::set-output name=dir::$(yarn cache dir)"
117+
118+
- uses: actions/cache@v2
119+
id: yarn-cache
120+
with:
121+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
122+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
123+
restore-keys: |
124+
${{ runner.os }}-yarn-
125+
126+
- name: Install JavaScript dependencies
127+
run: yarn install
128+
working-directory: tests/app
129+
130+
- name: Build JavaScript
131+
run: yarn build
132+
working-directory: tests/app
133+
134+
- name: Create DB
135+
run: php tests/app/public/index.php doctrine:schema:create
136+
137+
- name: Run tests
138+
run: vendor/bin/simple-phpunit
139+
140+
phpunit-lowest:
141+
runs-on: ubuntu-latest
142+
name: PHP 8.0 (lowest) Test on ubuntu-latest
143+
144+
services:
145+
mercure:
146+
image: dunglas/mercure
147+
env:
148+
SERVER_NAME: :3000
149+
MERCURE_PUBLISHER_JWT_KEY: '!ChangeMe!'
150+
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeMe!'
151+
MERCURE_EXTRA_DIRECTIVES: |
152+
anonymous
153+
cors_origins *
154+
ports:
155+
- 3000:3000
156+
157+
steps:
158+
- name: Checkout
159+
uses: actions/checkout@v2
160+
161+
- name: Setup PHP
162+
uses: shivammathur/setup-php@v2
163+
with:
164+
php-version: '8.0'
165+
166+
- name: Get composer cache directory
167+
id: composercache
168+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
169+
170+
- name: Cache PHP dependencies
171+
uses: actions/cache@v2
172+
with:
173+
path: ${{ steps.composercache.outputs.dir }}
174+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
175+
restore-keys: ${{ runner.os }}-composer-
176+
177+
- name: Install PHP dependencies
178+
run: composer update --prefer-dist --prefer-lowest
179+
180+
- name: Get yarn cache directory path
181+
id: yarn-cache-dir-path
182+
run: echo "::set-output name=dir::$(yarn cache dir)"
183+
184+
- uses: actions/cache@v2
185+
id: yarn-cache
186+
with:
187+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
188+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
189+
restore-keys: |
190+
${{ runner.os }}-yarn-
191+
192+
- name: Install JavaScript dependencies
193+
run: yarn install
194+
working-directory: tests/app
195+
196+
- name: Build JavaScript
197+
run: yarn build
198+
working-directory: tests/app
199+
200+
- name: Create DB
201+
run: php tests/app/public/index.php doctrine:schema:create
202+
203+
- name: Run tests
204+
env:
205+
SYMFONY_DEPRECATIONS_HELPER: max[total]=9223372036854775807 # PHP_INT_MAX
206+
run: vendor/bin/simple-phpunit

composer.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
],
1818
"require": {
1919
"php": ">=7.2.5",
20-
"symfony/config": "^4.4|^5.2",
21-
"symfony/dependency-injection": "^4.4|^5.2",
22-
"symfony/http-kernel": "^4.4|^5.2"
20+
"symfony/config": "^5.2",
21+
"symfony/dependency-injection": "^5.2",
22+
"symfony/http-kernel": "^5.2"
2323
},
2424
"autoload": {
2525
"psr-4": { "Symfony\\UX\\Turbo\\": "src/" }
@@ -43,18 +43,18 @@
4343
"doctrine/orm": "^2.8",
4444
"friendsofphp/php-cs-fixer": "^2.17",
4545
"phpstan/phpstan": "^0.12",
46-
"symfony/debug-bundle": "^4.4|^5.2",
47-
"symfony/expression-language": "^4.4|^5.2",
48-
"symfony/form": "^4.4|^5.2",
49-
"symfony/framework-bundle": "^4.4|^5.2",
46+
"symfony/debug-bundle": "^5.2",
47+
"symfony/expression-language": "^5.2",
48+
"symfony/form": "^5.2",
49+
"symfony/framework-bundle": "^5.2",
5050
"symfony/mercure-bundle": "^0.2.6",
51-
"symfony/messenger": "^4.4|^5.2",
51+
"symfony/messenger": "^5.2",
5252
"symfony/panther": "^0.9",
53-
"symfony/phpunit-bridge": "^4.4|^5.2",
53+
"symfony/phpunit-bridge": "^5.2.1",
5454
"symfony/security-core": "5.x-dev",
55-
"symfony/stopwatch": "^4.4|^5.2",
56-
"symfony/twig-bundle": "^4.4|^5.2",
57-
"symfony/web-profiler-bundle": "^4.4|^5.2",
55+
"symfony/stopwatch": "^5.2",
56+
"symfony/twig-bundle": "^5.2",
57+
"symfony/web-profiler-bundle": "^5.2",
5858
"symfony/webpack-encore-bundle": "^1.8"
5959
},
6060
"minimum-stability": "dev"

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
5-
backupGlobals="false"
65
colors="true"
76
bootstrap="vendor/autoload.php"
87
failOnRisky="true"
@@ -11,6 +10,7 @@
1110
<php>
1211
<ini name="error_reporting" value="-1" />
1312
<server name="APP_ENV" value="test" force="true" />
13+
<server name="APP_DEBUG" value="false" force="true" />
1414
<server name="SHELL_VERBOSITY" value="-1" />
1515
<server name="KERNEL_CLASS" value="App\Kernel" />
1616
<server name="PANTHER_WEB_SERVER_DIR" value="./tests/app/public" />

src/Broadcaster/TwigMercureBroadcaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function broadcast(object $entity, string $action): void
9898
$options['private'] ?? false,
9999
$options['id'] ?? null,
100100
$options['type'] ?? null,
101-
$options['retry'] ?? null,
101+
$options['retry'] ?? null
102102
);
103103

104104
$this->messageBus ? $this->messageBus->dispatch($update) : ($this->publisher)($update); // @phpstan-ignore-line

tests/BroadcastTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class BroadcastTest extends PantherTestCase
2929
public function testBroadcast(): void
3030
{
3131
($client = self::createPantherClient())->request('GET', '/books');
32+
3233
$crawler = $client->submitForm('Submit', ['title' => self::BOOK_TITLE]);
3334

3435
$client->waitForElementToContain('#books', self::BOOK_TITLE);
35-
36-
if (!preg_match('/\(#([0-9]+)\)/', $crawler->filter('#books div')->text(), $matches)) {
36+
if (!preg_match('/\(#(\d+)\)/', $crawler->filter('#books div')->text(), $matches)) {
3737
$this->fail('ID not found');
3838
}
3939

tests/app/Entity/Book.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ class Book
2626
* @ORM\Column(type="integer")
2727
* @ORM\Id
2828
* @ORM\GeneratedValue(strategy="AUTO")
29+
*
30+
* @var int|null
2931
*/
30-
public ?int $id = null;
32+
public $id;
3133

3234
/**
3335
* @ORM\Column
36+
*
37+
* @var string
3438
*/
35-
public string $title = '';
39+
public $title = '';
3640
}

tests/app/Kernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ protected function configureContainer(ContainerConfigurator $container): void
9797
'enable_profiler' => '%kernel.debug%',
9898
'hubs' => [
9999
'default' => [
100-
'url' => $_SERVER['MERCURE_PUBLISH_URL'] ?? 'http://localhost:3000/.well-known/mercure',
100+
'url' => $_SERVER['MERCURE_PUBLISH_URL'] ?? 'http://127.0.0.1:3000/.well-known/mercure',
101101
'jwt' => $_SERVER['MERCURE_JWT_TOKEN'] ?? 'eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdfX0.vhMwOaN5K68BTIhWokMLOeOJO4EPfT64brd8euJOA4M',
102102
],
103103
],
104104
]);
105105

106106
$container->extension('turbo', [
107107
'mercure' => [
108-
'subscribe_url' => $_SERVER['MERCURE_SUBSCRIBE_URL'] ?? 'http://localhost:3000/.well-known/mercure',
108+
'subscribe_url' => $_SERVER['MERCURE_SUBSCRIBE_URL'] ?? 'http://127.0.0.1:3000/.well-known/mercure',
109109
],
110110
]);
111111
}

tests/app/assets/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ import TurboStreamController from "@symfony/ux-turbo/dist/turbo_stream_controlle
1212

1313
const application = Application.start();
1414
application.register("turbo-stream", TurboStreamController);
15+
16+
console.log('test app initialized');

tests/app/public/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
require __DIR__.'/../../../vendor/autoload.php';
1717

18-
$app = new Kernel('dev', true);
18+
$app = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? true);
1919

2020
if (PHP_SAPI === 'cli') {
2121
$application = new Application($app);

0 commit comments

Comments
 (0)