Skip to content

Commit 2068ac9

Browse files
committed
Move phpunit tests for mongodb and elasticsearch to CI workflow on GitHub Actions
1 parent b959c6a commit 2068ac9

File tree

7 files changed

+116
-48
lines changed

7 files changed

+116
-48
lines changed

.github/workflows/ci.yml

Lines changed: 97 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ jobs:
7575
apk add \
7676
unzip \
7777
- name: Install mongodb PHP extension
78-
if: matrix.php != '7.1'
7978
run: |
8079
apk add $PHPIZE_DEPS
8180
pecl install mongodb-1.5.5
@@ -88,12 +87,6 @@ jobs:
8887
run: |
8988
composer global require --prefer-dist --no-progress --no-suggest --ansi \
9089
symfony/flex
91-
- name: Remove Doctrine MongoDB ODM
92-
if: matrix.php == '7.1'
93-
run: |
94-
composer remove --dev --no-progress --no-update --ansi \
95-
doctrine/mongodb-odm \
96-
doctrine/mongodb-odm-bundle \
9790
- name: Update project dependencies
9891
run: composer update --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi
9992
- name: Clear test app cache
@@ -139,7 +132,6 @@ jobs:
139132
pdo_pgsql \
140133
;
141134
- name: Install mongodb PHP extension
142-
if: matrix.php != '7.1'
143135
run: |
144136
apk add $PHPIZE_DEPS
145137
pecl install mongodb-1.5.5
@@ -152,12 +144,6 @@ jobs:
152144
run: |
153145
composer global require --prefer-dist --no-progress --no-suggest --ansi \
154146
symfony/flex
155-
- name: Remove Doctrine MongoDB ODM
156-
if: matrix.php == '7.1'
157-
run: |
158-
composer remove --dev --no-progress --no-update --ansi \
159-
doctrine/mongodb-odm \
160-
doctrine/mongodb-odm-bundle \
161147
- name: Update project dependencies
162148
run: composer update --no-progress --no-suggest --ansi
163149
- name: Clear test app cache
@@ -203,7 +189,6 @@ jobs:
203189
pdo_mysql \
204190
;
205191
- name: Install mongodb PHP extension
206-
if: matrix.php != '7.1'
207192
run: |
208193
apk add $PHPIZE_DEPS
209194
pecl install mongodb-1.5.5
@@ -216,12 +201,104 @@ jobs:
216201
run: |
217202
composer global require --prefer-dist --no-progress --no-suggest --ansi \
218203
symfony/flex
219-
- name: Remove Doctrine MongoDB ODM
220-
if: matrix.php == '7.1'
204+
- name: Update project dependencies
205+
run: composer update --no-progress --no-suggest --ansi
206+
- name: Clear test app cache
207+
run: tests/Fixtures/app/console cache:clear --ansi
208+
- name: Run PHPUnit tests
209+
run: vendor/bin/phpunit --colors=always
210+
211+
phpunit-mongodb:
212+
name: PHPUnit (PHP ${{ matrix.php }}) (MongoDB)
213+
runs-on: ubuntu-latest
214+
container:
215+
image: php:${{ matrix.php }}-alpine
216+
services:
217+
mongo:
218+
image: mongo:4
219+
options: >-
220+
--health-cmd "mongo --quiet --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'"
221+
--health-interval 10s
222+
--health-timeout 5s
223+
--health-retries 5
224+
strategy:
225+
matrix:
226+
php:
227+
- '7.3'
228+
fail-fast: false
229+
env:
230+
APP_ENV: mongodb
231+
MONGODB_URL: mongodb://mongo:27017
232+
steps:
233+
- name: Checkout
234+
uses: actions/checkout@v1
235+
- name: Install system packages
221236
run: |
222-
composer remove --dev --no-progress --no-update --ansi \
223-
doctrine/mongodb-odm \
224-
doctrine/mongodb-odm-bundle \
237+
apk add \
238+
unzip \
239+
- name: Install mongodb PHP extension
240+
run: |
241+
apk add $PHPIZE_DEPS
242+
pecl install mongodb-1.5.5
243+
docker-php-ext-enable mongodb
244+
- name: Disable PHP memory limit
245+
run: echo 'memory_limit=-1' >> /usr/local/etc/php/php.ini
246+
- name: Install Composer
247+
run: wget -qO - https://raw.githubusercontent.com/composer/getcomposer.org/fb22b78362d31c0d2bf516d1f8cdfd2745caa431/web/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
248+
- name: Install Symfony Flex
249+
run: |
250+
composer global require --prefer-dist --no-progress --no-suggest --ansi \
251+
symfony/flex
252+
- name: Update project dependencies
253+
run: composer update --no-progress --no-suggest --ansi
254+
- name: Clear test app cache
255+
run: tests/Fixtures/app/console cache:clear --ansi
256+
- name: Run PHPUnit tests
257+
run: vendor/bin/phpunit --colors=always --configuration phpunit_mongodb.xml
258+
259+
phpunit-elasticsearch:
260+
name: PHPUnit (PHP ${{ matrix.php }}) (Elasticsearch)
261+
runs-on: ubuntu-latest
262+
container:
263+
image: php:${{ matrix.php }}-alpine
264+
services:
265+
elasticsearch:
266+
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.3 # https://github.com/elastic/elasticsearch/issues/43627
267+
env:
268+
discovery.type: single-node
269+
options: >-
270+
--health-cmd "host=\"\$(hostname --ip-address || echo '127.0.0.1')\"; if health=\"\$(curl -fsSL \"http://$host:9200/_cat/health?h=status\")\"; then health=\"\$(echo \"\$health\" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')\"; if [ \"\$health\" = 'green' ]; then exit 0; fi; echo >&2 \"unexpected health status: \$health\"; fi; exit 1;"
271+
--health-interval 10s
272+
--health-timeout 5s
273+
--health-retries 5
274+
strategy:
275+
matrix:
276+
php:
277+
- '7.3'
278+
fail-fast: false
279+
env:
280+
APP_ENV: elasticsearch
281+
ELASTICSEARCH_URL: http://elasticsearch:9200
282+
steps:
283+
- name: Checkout
284+
uses: actions/checkout@v1
285+
- name: Install system packages
286+
run: |
287+
apk add \
288+
unzip \
289+
- name: Install mongodb PHP extension
290+
run: |
291+
apk add $PHPIZE_DEPS
292+
pecl install mongodb-1.5.5
293+
docker-php-ext-enable mongodb
294+
- name: Disable PHP memory limit
295+
run: echo 'memory_limit=-1' >> /usr/local/etc/php/php.ini
296+
- name: Install Composer
297+
run: wget -qO - https://raw.githubusercontent.com/composer/getcomposer.org/fb22b78362d31c0d2bf516d1f8cdfd2745caa431/web/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
298+
- name: Install Symfony Flex
299+
run: |
300+
composer global require --prefer-dist --no-progress --no-suggest --ansi \
301+
symfony/flex
225302
- name: Update project dependencies
226303
run: composer update --no-progress --no-suggest --ansi
227304
- name: Clear test app cache
@@ -249,7 +326,6 @@ jobs:
249326
apk add \
250327
unzip \
251328
- name: Install mongodb PHP extension
252-
if: matrix.php != '7.1'
253329
run: |
254330
apk add $PHPIZE_DEPS
255331
pecl install mongodb-1.5.5
@@ -262,12 +338,6 @@ jobs:
262338
run: |
263339
composer global require --prefer-dist --no-progress --no-suggest --ansi \
264340
symfony/flex
265-
- name: Remove Doctrine MongoDB ODM
266-
if: matrix.php == '7.1'
267-
run: |
268-
composer remove --dev --no-progress --no-update --ansi \
269-
doctrine/mongodb-odm \
270-
doctrine/mongodb-odm-bundle \
271341
- name: Update project dependencies
272342
run: composer update --no-progress --no-suggest --ansi
273343
- name: Clear test app cache

.travis.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ jobs:
203203
- *validate-openapi-v3-json
204204
- *validate-openapi-v3-yaml
205205

206-
- php: '7.3'
206+
- name: 'Behat (PHP 7.3) (MongoDB)'
207+
php: '7.3'
207208
env: APP_ENV=mongodb
208209
services:
209210
- mongodb
@@ -217,23 +218,22 @@ jobs:
217218
before_script:
218219
- *clear-test-app-cache
219220
script:
220-
- vendor/bin/phpunit --configuration phpunit_mongodb.xml
221-
- *clear-test-app-cache
222221
- vendor/bin/behat --format=progress --profile=mongodb --no-interaction
223222
- *validate-openapi-v2-json
224223
- *validate-openapi-v2-yaml
225224
- *validate-openapi-v3-json
226225
- *validate-openapi-v3-yaml
227226

228-
- php: '7.3'
227+
- name: 'Behat (PHP 7.3) (Elasticsearch)'
228+
php: '7.3'
229229
env: APP_ENV=elasticsearch
230230
before_install:
231231
- sudo apt-get purge --auto-remove elasticsearch
232232
- wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
233233
- echo 'deb https://artifacts.elastic.co/packages/6.x/apt stable main' | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list
234234
- sudo apt-get update
235235
- sudo apt-get install elasticsearch
236-
- sudo service elasticsearch start
236+
- sudo systemctl start elasticsearch
237237
- *enable-mongodb-php-extension
238238
- *disable-xdebug-php-extension
239239
- *disable-php-memory-limit
@@ -243,8 +243,6 @@ jobs:
243243
before_script:
244244
- *clear-test-app-cache
245245
script:
246-
- *run-phpunit-tests
247-
- *clear-test-app-cache
248246
- vendor/bin/behat --format=progress --profile=elasticsearch --no-interaction
249247
- *validate-openapi-v2-json
250248
- *validate-openapi-v2-yaml

tests/Fixtures/app/AppKernel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
137137
],
138138
];
139139

140-
$c->loadFromExtension('security', $securityConfig);
140+
$c->prependExtensionConfig('security', $securityConfig);
141141

142142
if (class_exists(DoctrineMongoDBBundle::class)) {
143-
$c->loadFromExtension('doctrine_mongodb', [
143+
$c->prependExtensionConfig('doctrine_mongodb', [
144144
'connections' => [
145145
'default' => null,
146146
],
@@ -153,7 +153,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
153153
}
154154

155155
if ($_SERVER['LEGACY'] ?? true) {
156-
$c->loadFromExtension('nelmio_api_doc', [
156+
$c->prependExtensionConfig('nelmio_api_doc', [
157157
'sandbox' => [
158158
'accept_type' => 'application/json',
159159
'body_format' => [
@@ -165,7 +165,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
165165
],
166166
],
167167
]);
168-
$c->loadFromExtension('api_platform', ['enable_nelmio_api_doc' => true]);
168+
$c->prependExtensionConfig('api_platform', ['enable_nelmio_api_doc' => true]);
169169
}
170170
}
171171
}

tests/Fixtures/app/config/config_elasticsearch.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
imports:
2-
- { resource: parameters_elasticsearch.yml }
32
- { resource: config_test.yml }
43

4+
parameters:
5+
env(ELASTICSEARCH_URL): http://localhost:9200
6+
57
api_platform:
68
mapping:
79
paths: ['%kernel.project_dir%/../Elasticsearch/Model']
810
elasticsearch:
9-
hosts: '%host%'
11+
hosts: '%env(resolve:ELASTICSEARCH_URL)%'
1012

1113
services:
1214
test.api_platform.elasticsearch.client:

tests/Fixtures/app/config/config_mongodb.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
imports:
2-
- { resource: parameters_mongodb.yml }
32
- { resource: config_common.yml }
43

4+
parameters:
5+
env(MONGODB_DB): api_platform_test
6+
env(MONGODB_URL): mongodb://localhost:27017
7+
58
doctrine_mongodb:
69
connections:
710
default:
8-
server: '%server%'
11+
server: '%env(resolve:MONGODB_URL)%'
912
options: {}
10-
default_database: '%dbname%'
13+
default_database: '%env(resolve:MONGODB_DB)%'
1114
document_managers:
1215
default:
1316
auto_mapping: true

tests/Fixtures/app/config/parameters_elasticsearch.yml

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

tests/Fixtures/app/config/parameters_mongodb.yml

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

0 commit comments

Comments
 (0)