Skip to content

Commit 979b4e0

Browse files
committed
add tests
1 parent c0b2c95 commit 979b4e0

31 files changed

+1259
-41
lines changed

.github/workflows/backend-ci.yaml

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
name: Backend build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- '[0-9]+.[0-9]+'
8+
pull_request: ~
9+
10+
jobs:
11+
cs-fix:
12+
name: Run code style check
13+
runs-on: "ubuntu-22.04"
14+
strategy:
15+
matrix:
16+
php:
17+
- '8.1'
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Setup PHP Action
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: ${{ matrix.php }}
25+
coverage: none
26+
extensions: 'pdo_sqlite, gd'
27+
tools: cs2pr
28+
29+
- name: Add composer keys for private packagist
30+
run: |
31+
composer config http-basic.updates.ibexa.co $IBEXA_KEY $IBEXA_TOKEN
32+
composer config github-oauth.github.com $GITHUB_TOKEN
33+
env:
34+
IBEXA_KEY: ${{ secrets.IBEXA_KEY }}
35+
IBEXA_TOKEN: ${{ secrets.IBEXA_TOKEN }}
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- uses: ramsey/composer-install@v2
39+
with:
40+
dependency-versions: "highest"
41+
42+
- name: Run code style check
43+
run: composer run-script check-cs -- --format=checkstyle | cs2pr
44+
45+
deptrac:
46+
name: Deptrac
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v4
50+
- name: Deptrac
51+
uses: smoench/deptrac-action@master
52+
53+
tests:
54+
name: Tests
55+
runs-on: "ubuntu-22.04"
56+
timeout-minutes: 10
57+
58+
strategy:
59+
fail-fast: false
60+
matrix:
61+
php:
62+
- '8.2'
63+
- '8.3'
64+
65+
steps:
66+
- uses: actions/checkout@v4
67+
68+
- name: Setup PHP Action
69+
uses: shivammathur/setup-php@v2
70+
with:
71+
php-version: ${{ matrix.php }}
72+
coverage: none
73+
extensions: pdo_sqlite, gd
74+
tools: cs2pr
75+
76+
- name: Add composer keys for private packagist
77+
run: |
78+
composer config http-basic.updates.ibexa.co $IBEXA_KEY $IBEXA_TOKEN
79+
composer config github-oauth.github.com $GITHUB_TOKEN
80+
env:
81+
IBEXA_KEY: ${{ secrets.IBEXA_KEY }}
82+
IBEXA_TOKEN: ${{ secrets.IBEXA_TOKEN }}
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- uses: ramsey/composer-install@v2
86+
87+
- name: Setup problem matchers for PHPUnit
88+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
89+
90+
- name: Run PHPStan analysis
91+
run: composer run-script phpstan
92+
93+
- name: Run test suite
94+
run: composer run-script --timeout=600 test
95+
96+
integration-tests-postgres:
97+
name: PostgreSQL integration tests
98+
needs: tests
99+
services:
100+
postgres:
101+
image: postgres:14
102+
ports:
103+
- 5432
104+
env:
105+
POSTGRES_PASSWORD: postgres
106+
POSTGRES_DB: testdb
107+
options: >-
108+
--health-cmd pg_isready
109+
--health-interval 10s
110+
--health-timeout 5s
111+
--health-retries 5
112+
--tmpfs /var/lib/postgres
113+
runs-on: "ubuntu-22.04"
114+
timeout-minutes: 10
115+
116+
strategy:
117+
fail-fast: false
118+
matrix:
119+
php:
120+
- '8.2'
121+
- '8.3'
122+
123+
steps:
124+
- uses: actions/checkout@v4
125+
126+
- name: Setup PHP Action
127+
uses: shivammathur/setup-php@v2
128+
with:
129+
php-version: ${{ matrix.php }}
130+
coverage: none
131+
extensions: pdo_pgsql, gd
132+
tools: cs2pr
133+
134+
- name: Add composer keys for private packagist
135+
run: |
136+
composer config http-basic.updates.ibexa.co $IBEXA_KEY $IBEXA_TOKEN
137+
composer config github-oauth.github.com $GITHUB_TOKEN
138+
env:
139+
IBEXA_KEY: ${{ secrets.IBEXA_KEY }}
140+
IBEXA_TOKEN: ${{ secrets.IBEXA_TOKEN }}
141+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142+
143+
- uses: ramsey/composer-install@v2
144+
with:
145+
dependency-versions: "highest"
146+
147+
- name: Setup problem matchers for PHPUnit
148+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
149+
150+
- name: Run integration test suite vs Postgresql
151+
run: composer run-script --timeout=600 test-integration
152+
env:
153+
DATABASE_URL: "pgsql://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/testdb?server_version=10"
154+
155+
integration-tests-mysql:
156+
name: MySQL integration tests
157+
needs: tests
158+
services:
159+
mysql:
160+
image: mysql:8
161+
ports:
162+
- 3306/tcp
163+
env:
164+
MYSQL_RANDOM_ROOT_PASSWORD: true
165+
MYSQL_USER: mysql
166+
MYSQL_PASSWORD: mysql
167+
MYSQL_DATABASE: testdb
168+
options: >-
169+
--health-cmd="mysqladmin ping"
170+
--health-interval=10s
171+
--health-timeout=5s
172+
--health-retries=5
173+
--tmpfs=/var/lib/mysql
174+
runs-on: "ubuntu-22.04"
175+
timeout-minutes: 10
176+
177+
strategy:
178+
fail-fast: false
179+
matrix:
180+
php:
181+
- '8.2'
182+
- '8.3'
183+
184+
steps:
185+
- uses: actions/checkout@v4
186+
187+
- name: Setup PHP Action
188+
uses: shivammathur/setup-php@v2
189+
with:
190+
php-version: ${{ matrix.php }}
191+
coverage: none
192+
extensions: pdo_mysql, gd, redis
193+
tools: cs2pr
194+
195+
- name: Add composer keys for private packagist
196+
run: |
197+
composer config http-basic.updates.ibexa.co $IBEXA_KEY $IBEXA_TOKEN
198+
composer config github-oauth.github.com $GITHUB_TOKEN
199+
env:
200+
IBEXA_KEY: ${{ secrets.IBEXA_KEY }}
201+
IBEXA_TOKEN: ${{ secrets.IBEXA_TOKEN }}
202+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
203+
204+
- uses: ramsey/composer-install@v2
205+
with:
206+
dependency-versions: "highest"
207+
208+
- name: Setup problem matchers for PHPUnit
209+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
210+
211+
- name: Run integration test suite vs MySQL
212+
run: composer run-script --timeout=600 test-integration
213+
env:
214+
DATABASE_URL: "mysql://mysql:[email protected]:${{ job.services.mysql.ports[3306] }}/testdb"

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
/package-lock.json
88
/yarn.lock
99
vendor
10-
.idea
10+
.idea
11+
/.deptrac.cache
12+
/.php-version

.php-cs-fixer.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
use AdamWojs\PhpCsFixerPhpdocForceFQCN\Fixer\Phpdoc\ForceFQCNFixer;
7+
8+
$finder = PhpCsFixer\Finder::create()
9+
->in(__DIR__ . '/src')
10+
->in(__DIR__ . '/tests')
11+
->files()->name('*.php');
12+
13+
return (new PhpCsFixer\Config())
14+
->registerCustomFixers([
15+
new ForceFQCNFixer(),
16+
])
17+
->setRules([
18+
'AdamWojs/phpdoc_force_fqcn_fixer' => true,
19+
'class_attributes_separation' => [
20+
'elements' => [
21+
'method' => 'one',
22+
'property' => 'one',
23+
],
24+
],
25+
'class_definition' => [
26+
'single_item_single_line' => true,
27+
'inline_constructor_arguments' => false,
28+
],
29+
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
30+
])
31+
->setFinder(
32+
$finder
33+
);
34+

composer.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"symfony/yaml": "^5.4"
4242
},
4343
"require-dev": {
44+
"dama/doctrine-test-bundle": "^v6.7",
4445
"ibexa/admin-ui": "~4.6",
4546
"ibexa/code-style": "~2.0.0",
4647
"ibexa/content-forms": "~4.6",
@@ -54,9 +55,26 @@
5455
"ibexa/personalization": "~4.6",
5556
"ibexa/product-catalog": "~4.6",
5657
"ibexa/rest": "~4.6",
58+
"ibexa/scheduler": "^4.6",
5759
"ibexa/search": "~4.6",
5860
"ibexa/taxonomy": "~4.6",
59-
"ibexa/twig-components": "~4.6"
61+
"ibexa/test-core": "4.6.x-dev",
62+
"ibexa/twig-components": "~4.6",
63+
"ibexa/version-comparison": "^4.6",
64+
"matthiasnoback/symfony-dependency-injection-test": "^4.2",
65+
"phpstan/phpstan": "^2.0",
66+
"phpstan/phpstan-phpunit": "^2.0",
67+
"phpstan/phpstan-symfony": "^2.0",
68+
"phpunit/phpunit": "^9",
69+
"qossmic/deptrac-shim": "^0.24.0 || ^1.0.2"
70+
},
71+
"scripts": {
72+
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php --show-progress=dots --allow-risky=yes",
73+
"check-cs": "@fix-cs --dry-run",
74+
"test": "phpunit -c phpunit.xml.dist",
75+
"test-integration": "phpunit -c phpunit.integration.xml",
76+
"phpstan": "phpstan analyse -c phpstan.neon",
77+
"deptrac": "php vendor/bin/deptrac analyse"
6078
},
6179
"extra": {
6280
"branch-alias": {
@@ -70,6 +88,13 @@
7088
"CodeRhapsodie\\ConnectorGemini\\": "src/lib/"
7189
}
7290
},
91+
"autoload-dev": {
92+
"psr-4": {
93+
"CodeRhapsodie\\Tests\\Bundle\\ConnectorGemini\\": "tests/bundle/",
94+
"CodeRhapsodie\\Tests\\Integration\\ConnectorGemini\\": "tests/integration/",
95+
"CodeRhapsodie\\Tests\\ConnectorGemini\\": "tests/lib/"
96+
}
97+
},
7398
"config": {
7499
"sort-packages": true,
75100
"allow-plugins": {

deptrac.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
deptrac:
2+
paths:
3+
- ./src
4+
layers:
5+
- name: Bundle
6+
collectors:
7+
- type: directory
8+
value: bundle/.*
9+
- name: Contracts
10+
collectors:
11+
- type: directory
12+
value: contracts/.*
13+
- name: Library
14+
collectors:
15+
- type: directory
16+
value: lib/.*
17+
ruleset:
18+
Bundle:
19+
- Bundle
20+
- Contracts
21+
- Library
22+
Contracts:
23+
- Contracts
24+
Library:
25+
- Contracts
26+
- Library

phpstan-baseline.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Class Ibexa\\Bundle\\ConnectorOpenAi\\Form\\Type\\AbstractActionConfigurationOptions extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
5+
identifier: missingType.generics
6+
count: 1
7+
path: src/bundle/Form/Type/AbstractActionConfigurationOptions.php

phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
includes:
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
- vendor/phpstan/phpstan-symfony/extension.neon
4+
- phpstan-baseline.neon
5+
6+
parameters:
7+
level: 8
8+
paths:
9+
- src
10+
- tests

phpunit.integration.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
3+
bootstrap="tests/bootstrap.php"
4+
beStrictAboutOutputDuringTests="true"
5+
beStrictAboutTodoAnnotatedTests="true"
6+
failOnWarning="true"
7+
verbose="true">
8+
<php>
9+
<env name="DATABASE_URL" value="sqlite://i@i/var/test.db" />
10+
<env name="KERNEL_CLASS" value="CodeRhapsodie\Tests\Integration\ConnectorGemini\Kernel" />
11+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=4&amp;max[direct]=0&amp;verbose=0"/>
12+
</php>
13+
<testsuites>
14+
<testsuite name="integration">
15+
<directory>tests/integration/</directory>
16+
</testsuite>
17+
</testsuites>
18+
<extensions>
19+
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
20+
</extensions>
21+
</phpunit>

phpunit.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<phpunit
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
backupGlobals="false"
5+
backupStaticAttributes="false"
6+
bootstrap="vendor/autoload.php"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
failOnWarning="true"
11+
colors="true">
12+
<testsuites>
13+
<testsuite name="bundle">
14+
<directory>tests/bundle</directory>
15+
</testsuite>
16+
<testsuite name="lib">
17+
<directory>tests/lib</directory>
18+
</testsuite>
19+
</testsuites>
20+
</phpunit>

0 commit comments

Comments
 (0)