Skip to content

Commit 0a6e172

Browse files
authored
feat: implement dockerization with documentation for testing (#474)
* feat: implement dockerization with documentation for testing * feat: add Dockerfile and docker compose
1 parent 8bb46ab commit 0a6e172

File tree

7 files changed

+102
-4
lines changed

7 files changed

+102
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor
22
composer.lock
33

44
Tests/app/tmp/
5+
.phpunit.result.cache

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM php:8.4-cli-bullseye
2+
3+
ENV COMPOSER_ALLOW_SUPERUSER=1
4+
5+
RUN apt-get update && apt-get upgrade -y
6+
RUN apt-get update && apt-get upgrade -y && apt-get install --no-install-recommends -y \
7+
git unzip zip curl libicu-dev libonig-dev libxml2-dev \
8+
libzip-dev libpng-dev libjpeg-dev libfreetype6-dev \
9+
libcurl4-openssl-dev pkg-config libssl-dev \
10+
default-libmysqlclient-dev default-mysql-client \
11+
gnupg2 lsb-release apt-transport-https ca-certificates \
12+
&& docker-php-ext-install intl mbstring pdo pdo_mysql zip \
13+
&& apt-get clean \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
RUN pecl install mongodb \
17+
&& docker-php-ext-enable mongodb
18+
19+
# Instalar Composer
20+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
21+
22+
WORKDIR /app
23+
24+
COPY . .
25+
26+
RUN composer install --prefer-dist --no-progress
27+
28+
CMD ["composer", "test"]

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ ___________________
3232
Here is a little screen shot of the edition page :)
3333

3434
![edition page screen](https://github.com/lexik/LexikTranslationBundle/raw/master/Resources/doc/screen/grid.jpg)
35+
36+
TESTING
37+
=======
38+
39+
[Read the documentation for testing ](./testing.md)

Resources/doc/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ Add the bunde to your `composer.json` file:
66
```javascript
77
require: {
88
// ...
9-
"lexik/translation-bundle": "~5.3"
9+
"lexik/translation-bundle": "~7.1"
1010
}
1111
```
1212

1313
Or install directly through composer with:
1414

1515
```shell
1616
# Latest stable
17-
composer require lexik/translation-bundle ~5.3
17+
composer require lexik/translation-bundle ~7.1
1818

1919
# For latest unstable version
2020
composer require lexik/translation-bundle dev-master
@@ -41,7 +41,9 @@ $bundles = [array(]
4141

4242
Then install the required assets:
4343

44+
```bash
4445
./bin/console assets:install
46+
```
4547

4648
___________________
4749

Resources/doc/testing.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,26 @@ Available variables are:
2525
- DB_PASSWD - database user password (default: null)
2626
- DB_ENGINE - database engine (default: pdo_mysql)
2727
- DB_PORT - database port (default: null)
28+
- MONGO_SERVER - mongo server DNS string (default: mongodb://admin:secret@127.0.0.1:27017/admin)
29+
30+
All these variables are injected if not provided under the `Tests/bootstrap.php` file.
31+
32+
## Testing with Docker
33+
34+
Direct execution of test:
35+
36+
``` bash
37+
docker-compose run --rm lexik_translation composer test
38+
```
39+
40+
Building the image:
41+
42+
``` bash
43+
docker-compose build --no-cache
44+
```
45+
46+
Run a test file for a specific test:
47+
48+
``` bash
49+
docker-compose run --rm lexik_translation composer test Tests/Unit/Translation/Manager/TransUnitManagerTest.php --filter testORMAddTranslation
50+
```

Tests/bootstrap.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77
define("ORM_TYPE", getenv("ORM") ?: "doctrine");
88

99
define("DB_ENGINE", getenv("DB_ENGINE") ?: "pdo_mysql");
10-
define("DB_HOST", getenv("DB_HOST") ?: "127.0.0.1");
10+
if (getenv('DOCKER') === 'true') {
11+
define("DB_HOST", getenv("DB_HOST") ?: "mysql");
12+
} else {
13+
define("DB_HOST", getenv("DB_HOST") ?: "127.0.0.1");
14+
}
1115
define("DB_PORT", getenv("DB_PORT") ?: 3306);
1216
define('DB_NAME', getenv("DB_NAME") ?: "lexik_translation_test");
1317
define("DB_USER", getenv("DB_USER") ?: "root");
1418
define("DB_PASSWD", getenv("DB_PASSWD") ?: "");
15-
define("MONGO_SERVER", getenv("MONGO_SERVER") ?: "mongodb://admin:[email protected]:27017/admin");
19+
if (getenv('DOCKER') === 'true') {
20+
define("MONGO_SERVER", getenv("MONGO_SERVER") ?: "mongodb://admin:secret@mongo:27017/admin");
21+
} else {
22+
define("MONGO_SERVER", getenv("MONGO_SERVER") ?: "mongodb://admin:[email protected]:27017/admin");
23+
}
1624

1725
if (file_exists($file = __DIR__.'/autoload.php')) {
1826
require_once $file;

docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3.8'
2+
3+
services:
4+
lexik_translation:
5+
build: .
6+
volumes:
7+
- .:/app
8+
depends_on:
9+
- mysql
10+
- mongo
11+
12+
mysql:
13+
image: mysql:8.0
14+
environment:
15+
MYSQL_DATABASE: lexik_translation_test
16+
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
17+
ports:
18+
- "3306:3306"
19+
healthcheck:
20+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
21+
interval: 10s
22+
timeout: 5s
23+
retries: 3
24+
25+
mongo:
26+
image: mongo:4.0
27+
environment:
28+
MONGO_INITDB_ROOT_USERNAME: admin
29+
MONGO_INITDB_ROOT_PASSWORD: secret
30+
ports:
31+
- "27017:27017"

0 commit comments

Comments
 (0)