Skip to content

Commit 3d5275f

Browse files
committed
Move phpunit tests for postgres and mysql to CI workflow on GitHub Actions
1 parent b81ca8d commit 3d5275f

File tree

6 files changed

+162
-34
lines changed

6 files changed

+162
-34
lines changed

.github/workflows/ci.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,134 @@ jobs:
101101
- name: Run PHPUnit tests
102102
run: vendor/bin/phpunit --colors=always
103103

104+
phpunit-postgresql:
105+
name: PHPUnit (PHP ${{ matrix.php }}) (PostgreSQL)
106+
runs-on: ubuntu-latest
107+
container:
108+
image: php:${{ matrix.php }}-alpine
109+
services:
110+
postgres:
111+
image: postgres:10-alpine
112+
env:
113+
POSTGRES_DB: api_platform_test
114+
POSTGRES_PASSWORD: hk7dFAByeQVVxpLtmZ6GVUzP
115+
POSTGRES_USER: api-platform
116+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
117+
strategy:
118+
matrix:
119+
php:
120+
- '7.3'
121+
fail-fast: false
122+
env:
123+
APP_ENV: postgres
124+
DATABASE_URL: postgres://api-platform:hk7dFAByeQVVxpLtmZ6GVUzP@postgres/api_platform_test
125+
steps:
126+
- name: Checkout
127+
uses: actions/checkout@v1
128+
- name: Install system packages
129+
run: |
130+
apk add \
131+
unzip \
132+
- name: Install PHP extensions
133+
run: |
134+
apk add \
135+
$PHPIZE_DEPS \
136+
postgresql-dev \
137+
;
138+
docker-php-ext-install -j$(nproc) \
139+
pdo_pgsql \
140+
;
141+
- name: Install mongodb PHP extension
142+
if: matrix.php != '7.1'
143+
run: |
144+
apk add $PHPIZE_DEPS
145+
pecl install mongodb-1.5.5
146+
docker-php-ext-enable mongodb
147+
- name: Disable PHP memory limit
148+
run: echo 'memory_limit=-1' >> /usr/local/etc/php/php.ini
149+
- name: Install Composer
150+
run: wget -qO - https://raw.githubusercontent.com/composer/getcomposer.org/fb22b78362d31c0d2bf516d1f8cdfd2745caa431/web/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
151+
- name: Install Symfony Flex
152+
run: |
153+
composer global require --prefer-dist --no-progress --no-suggest --ansi \
154+
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 \
161+
- name: Update project dependencies
162+
run: composer update --no-progress --no-suggest --ansi
163+
- name: Clear test app cache
164+
run: tests/Fixtures/app/console cache:clear --ansi
165+
- name: Run PHPUnit tests
166+
run: vendor/bin/phpunit --colors=always
167+
168+
phpunit-mysql:
169+
name: PHPUnit (PHP ${{ matrix.php }}) (MySQL)
170+
runs-on: ubuntu-latest
171+
container:
172+
image: php:${{ matrix.php }}-alpine
173+
services:
174+
mysql:
175+
image: mysql:5.7
176+
env:
177+
MYSQL_DATABASE: api_platform_test
178+
MYSQL_PASSWORD: LUhGR5tJ7WA2gbGumknCYBcB
179+
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
180+
MYSQL_USER: api-platform
181+
options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 5
182+
strategy:
183+
matrix:
184+
php:
185+
- '7.3'
186+
fail-fast: false
187+
env:
188+
APP_ENV: mysql
189+
DATABASE_URL: mysql://api-platform:LUhGR5tJ7WA2gbGumknCYBcB@mysql/api_platform_test
190+
steps:
191+
- name: Checkout
192+
uses: actions/checkout@v1
193+
- name: Install system packages
194+
run: |
195+
apk add \
196+
unzip \
197+
- name: Install PHP extensions
198+
run: |
199+
apk add \
200+
$PHPIZE_DEPS \
201+
;
202+
docker-php-ext-install -j$(nproc) \
203+
pdo_mysql \
204+
;
205+
- name: Install mongodb PHP extension
206+
if: matrix.php != '7.1'
207+
run: |
208+
apk add $PHPIZE_DEPS
209+
pecl install mongodb-1.5.5
210+
docker-php-ext-enable mongodb
211+
- name: Disable PHP memory limit
212+
run: echo 'memory_limit=-1' >> /usr/local/etc/php/php.ini
213+
- name: Install Composer
214+
run: wget -qO - https://raw.githubusercontent.com/composer/getcomposer.org/fb22b78362d31c0d2bf516d1f8cdfd2745caa431/web/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
215+
- name: Install Symfony Flex
216+
run: |
217+
composer global require --prefer-dist --no-progress --no-suggest --ansi \
218+
symfony/flex
219+
- name: Remove Doctrine MongoDB ODM
220+
if: matrix.php == '7.1'
221+
run: |
222+
composer remove --dev --no-progress --no-update --ansi \
223+
doctrine/mongodb-odm \
224+
doctrine/mongodb-odm-bundle \
225+
- name: Update project dependencies
226+
run: composer update --no-progress --no-suggest --ansi
227+
- name: Clear test app cache
228+
run: tests/Fixtures/app/console cache:clear --ansi
229+
- name: Run PHPUnit tests
230+
run: vendor/bin/phpunit --colors=always
231+
104232
phpunit-no-deprecations:
105233
name: PHPUnit (PHP ${{ matrix.php }}) (no deprecations)
106234
runs-on: ubuntu-latest

.travis.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ cache:
1212
.steps:
1313
- &clear-test-app-cache |
1414
tests/Fixtures/app/console cache:clear
15+
- &create-test-database |
16+
tests/Fixtures/app/console doctrine:database:create
1517
- &disable-php-memory-limit |
1618
echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
1719
- &disable-xdebug-php-extension |
@@ -151,8 +153,13 @@ jobs:
151153
- *validate-openapi-v3-json
152154
- *validate-openapi-v3-yaml
153155

154-
- php: '7.3'
155-
env: APP_ENV=postgres
156+
- name: 'Behat (PHP 7.3) (PostgreSQL)'
157+
php: '7.3'
158+
env: >-
159+
APP_ENV=postgres
160+
DATABASE_URL=postgres://postgres:@localhost/api_platform_test
161+
addons:
162+
postgresql: '10'
156163
services:
157164
- postgresql
158165
before_install:
@@ -164,18 +171,19 @@ jobs:
164171
- *update-project-dependencies
165172
before_script:
166173
- *clear-test-app-cache
167-
- psql --command 'CREATE DATABASE api_platform_test;' --username postgres
174+
- *create-test-database
168175
script:
169-
- *run-phpunit-tests
170-
- *clear-test-app-cache
171176
- vendor/bin/behat --format=progress --profile=postgres --no-interaction
172177
- *validate-openapi-v2-json
173178
- *validate-openapi-v2-yaml
174179
- *validate-openapi-v3-json
175180
- *validate-openapi-v3-yaml
176181

177-
- php: '7.3'
178-
env: APP_ENV=mysql
182+
- name: 'Behat (PHP 7.3) (MySQL)'
183+
php: '7.3'
184+
env: >-
185+
APP_ENV=mysql
186+
DATABASE_URL=mysql://travis:@localhost/api_platform_test
179187
services:
180188
- mysql
181189
before_install:
@@ -187,10 +195,8 @@ jobs:
187195
- *update-project-dependencies
188196
before_script:
189197
- *clear-test-app-cache
190-
- mysql --execute 'CREATE DATABASE api_platform_test;'
198+
- *create-test-database
191199
script:
192-
- *run-phpunit-tests
193-
- *clear-test-app-cache
194200
- *run-behat-tests
195201
- *validate-openapi-v2-json
196202
- *validate-openapi-v2-yaml
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
imports:
2-
- { resource: parameters_mysql.yml }
32
- { resource: config_test.yml }
43

4+
parameters:
5+
env(DATABASE_URL): mysql://root:@localhost/api_platform_test
6+
env(MYSQL_VERSION): '5.7'
7+
58
doctrine:
69
dbal:
7-
driver: 'pdo_mysql'
8-
dbname: '%dbname%'
9-
user: '%user%'
10-
password: '%password%'
11-
host: '%host%'
10+
driver: pdo_mysql
11+
url: '%env(DATABASE_URL)%'
12+
path: ~
13+
server_version: '%env(MYSQL_VERSION)%'
1214
types:
13-
uuid: Ramsey\Uuid\Doctrine\UuidType
15+
uuid: Ramsey\Uuid\Doctrine\UuidType
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
imports:
2-
- { resource: parameters_postgres.yml }
32
- { resource: config_test.yml }
43

4+
parameters:
5+
env(DATABASE_URL): postgres://postgres:@localhost/api_platform_test
6+
env(POSTGRES_VERSION): '10'
7+
58
doctrine:
69
dbal:
7-
driver: 'pdo_pgsql'
8-
dbname: '%dbname%'
9-
user: '%user%'
10-
password: '%password%'
11-
host: '%host%'
10+
driver: pdo_pgsql
11+
url: '%env(DATABASE_URL)%'
12+
path: ~
13+
server_version: '%env(POSTGRES_VERSION)%'
1214
types:
13-
uuid: Ramsey\Uuid\Doctrine\UuidType
15+
uuid: Ramsey\Uuid\Doctrine\UuidType

tests/Fixtures/app/config/parameters_mysql.yml

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

tests/Fixtures/app/config/parameters_postgres.yml

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

0 commit comments

Comments
 (0)