Skip to content

Commit 1f659bd

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 298150c commit 1f659bd

File tree

4 files changed

+64
-2
lines changed

4 files changed

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

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)