Skip to content

Commit cf3b77e

Browse files
add Dockerfiles and docker-compose for local testing
* add Dockerfiles and docker-compose for local testing * fix: env defaults * fix: populator requires config * fix: use cli base image and import composer from official image * fix: key check triggering warning * fix: exclude Dockerfiles from git archives Co-authored-by: Gintautas Miselis <[email protected]>
1 parent 32afb4b commit cf3b77e

File tree

5 files changed

+113
-2
lines changed

5 files changed

+113
-2
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/Robofile.php export-ignore
66
/*.md export-ignore
77
/*.yml export-ignore
8+
/*.Dockerfile export-ignore

docker-compose.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: "3.9"
2+
3+
services:
4+
5+
php74:
6+
image: codeception-module-db-php74:2.2.0
7+
build:
8+
context: .
9+
dockerfile: ./php74.Dockerfile
10+
environment:
11+
MYSQL_DSN: "mysql:host=host.docker.internal;port=3102;dbname=codeception"
12+
MYSQL_USER: root
13+
MYSQL_PASSWORD: codeception
14+
XDEBUG_MODE: "debug"
15+
XDEBUG_CONFIG: "client_host=host.docker.internal; client_port=9000; mode=debug; start_wih_request=1"
16+
PHP_IDE_CONFIG: "serverName=codeception-module-db" # the name must be the same as in your PHP -> Server -> "name" field
17+
volumes:
18+
- ".:/var/www/html"
19+
20+
php81:
21+
image: codeception-module-db-php81:2.2.0
22+
build:
23+
context: .
24+
dockerfile: ./php81.Dockerfile
25+
environment:
26+
MYSQL_DSN: "mysql:host=host.docker.internal;port=3102;dbname=codeception"
27+
MYSQL_USER: root
28+
MYSQL_PASSWORD: codeception
29+
XDEBUG_MODE: "debug"
30+
XDEBUG_CONFIG: "client_host=host.docker.internal; client_port=9000; mode=debug; start_wih_request=1"
31+
PHP_IDE_CONFIG: "serverName=codeception-module-db" # the name must be the same as in your PHP -> Server -> "name" field
32+
volumes:
33+
- ".:/var/www/html"
34+
35+
mariadb105:
36+
image: mariadb:10.5
37+
environment:
38+
MARIADB_ROOT_PASSWORD: codeception
39+
MARIADB_DATABASE: codeception
40+
ports:
41+
- "3102:3306"
42+

php74.Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM php:7.4-cli
2+
3+
RUN apt-get update && \
4+
apt-get install -y \
5+
unzip \
6+
wget \
7+
git \
8+
zlib1g-dev \
9+
libzip-dev \
10+
mariadb-client-10.5
11+
12+
RUN docker-php-ext-install pdo pdo_mysql && docker-php-ext-enable pdo pdo_mysql
13+
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
14+
RUN docker-php-ext-install zip
15+
16+
RUN pecl install xdebug-3.1.5 && \
17+
echo zend_extension=xdebug.so > $PHP_INI_DIR/conf.d/xdebug.ini
18+
19+
COPY --from=composer /usr/bin/composer /usr/bin/composer
20+
21+
WORKDIR /var/www/html
22+
23+
COPY composer.json .
24+
COPY composer.lock .
25+
26+
RUN composer install --no-autoloader
27+
28+
COPY . .
29+
30+
RUN composer dump-autoload -o
31+
32+
ENTRYPOINT ["tail"]
33+
CMD ["-f", "/dev/null"]

php81.Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM php:8.1-cli
2+
3+
RUN apt-get update && \
4+
apt-get install -y \
5+
unzip \
6+
wget \
7+
git \
8+
zlib1g-dev \
9+
libzip-dev \
10+
mariadb-client-10.5
11+
12+
RUN docker-php-ext-install pdo pdo_mysql && docker-php-ext-enable pdo pdo_mysql
13+
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
14+
RUN docker-php-ext-install zip
15+
16+
RUN pecl install xdebug-3.1.5 && \
17+
echo zend_extension=xdebug.so > $PHP_INI_DIR/conf.d/xdebug.ini
18+
19+
COPY --from=composer /usr/bin/composer /usr/bin/composer
20+
21+
WORKDIR /var/www/html
22+
23+
COPY composer.json .
24+
COPY composer.lock .
25+
26+
RUN composer install --no-autoloader
27+
28+
COPY . .
29+
30+
RUN composer dump-autoload -o
31+
32+
ENTRYPOINT ["tail"]
33+
CMD ["-f", "/dev/null"]

tests/unit/Codeception/Module/Db/MySqlDbTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ public function getPopulator(): string
2323
public function getConfig(): array
2424
{
2525
$host = getenv('MYSQL_HOST') ? getenv('MYSQL_HOST') : 'localhost';
26+
$user = getenv('MYSQL_USER') ? getenv('MYSQL_USER') : 'root';
2627
$password = getenv('MYSQL_PASSWORD') ? getenv('MYSQL_PASSWORD') : '';
28+
$dsn = getenv('MYSQL_DSN') ? getenv('MYSQL_DSN') : 'mysql:host='.$host.';dbname=codeception_test';
2729

2830
return [
29-
'dsn' => 'mysql:host='.$host.';dbname=codeception_test',
30-
'user' => 'root',
31+
'dsn' => $dsn,
32+
'user' => $user,
3133
'password' => $password,
3234
'dump' => 'tests/data/dumps/mysql.sql',
3335
'reconnect' => true,

0 commit comments

Comments
 (0)