Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] #52 Fixed local testing in Docker #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ version: "3.9"

services:
php81:
container_name: codeception-module-db
image: codeception-module-db-php81:2.2.0
build:
context: .
dockerfile: ./php81.Dockerfile
environment:
MYSQL_DSN: "mysql:host=host.docker.internal;port=3102;dbname=codeception"
MYSQL_HOST: "host.docker.internal"
MYSQL_USER: root
MYSQL_PASSWORD: codeception
XDEBUG_MODE: "debug"
XDEBUG_CONFIG: "client_host=host.docker.internal; client_port=9000; mode=debug; start_wih_request=1"
PHP_IDE_CONFIG: "serverName=codeception-module-db" # the name must be the same as in your PHP -> Server -> "name" field
PGDSN: "pgsql:host=host.docker.internal;dbname=codeception_test"
PGPASSWORD: postgres
volumes:
- ".:/var/www/html"
extra_hosts:
- "host.docker.internal:host-gateway"

mariadb105:
image: mariadb:10.5
Expand All @@ -24,3 +30,10 @@ services:
ports:
- "3102:3306"

postgres:
image: postgres
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: codeception_test
ports:
- "5432:5432"
6 changes: 3 additions & 3 deletions php81.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ RUN apt-get update && \
git \
zlib1g-dev \
libzip-dev \
mariadb-client-10.5
libpq-dev \
mariadb-client-10.5

RUN docker-php-ext-install pdo pdo_mysql && docker-php-ext-enable pdo pdo_mysql
RUN docker-php-ext-install pdo pdo_mysql pgsql pdo_pgsql && docker-php-ext-enable pdo pdo_mysql pgsql pdo_pgsql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN docker-php-ext-install zip

Expand All @@ -21,7 +22,6 @@ COPY --from=composer /usr/bin/composer /usr/bin/composer
WORKDIR /var/www/html

COPY composer.json .
COPY composer.lock .

RUN composer install --no-autoloader

Expand Down
31 changes: 31 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Codeception Internal Tests

In case you submit a pull request, you will be asked for writing a test.

## Dockerized testing

### Local testing and development with `docker compose`

Start

docker compose up -d

Install composer dependencies

docker exec -it codeception-module-db bash -c "composer install"

Run suite all tests

docker exec -it codeception-module-db bash -c "php vendor/bin/codecept run"

Development bash

docker exec -it codeception-module-db bash

Cleanup

docker exec -it codeception-module-db bash -c "php vendor/bin/codecept clean"

Stop containers

docker compose stop
3 changes: 2 additions & 1 deletion tests/unit/Codeception/Module/Db/PostgreSqlDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public function getConfig(): array
}

$password = getenv('PGPASSWORD') ? getenv('PGPASSWORD') : null;
$dsn = getenv('PGDSN') ? getenv('PGDSN') : 'pgsql:host=localhost;dbname=codeception_test';

return [
'dsn' => 'pgsql:host=localhost;dbname=codeception_test',
'dsn' => $dsn,
'user' => 'postgres',
'password' => $password,
'dump' => 'tests/data/dumps/postgres.sql',
Expand Down