From cd3ebe98303426200aa81c6904bc843f94ec3bdd Mon Sep 17 00:00:00 2001
From: Szabolcs Hajdu <sabee0418@gmail.com>
Date: Mon, 4 Mar 2024 22:05:59 +0100
Subject: [PATCH 1/2] feat(mssql): add odbc 18 support in mssql tests

---
 tests/unit/Codeception/Module/Db/MssqlSqlSrvDbTest.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/unit/Codeception/Module/Db/MssqlSqlSrvDbTest.php b/tests/unit/Codeception/Module/Db/MssqlSqlSrvDbTest.php
index 58776042..b758a26b 100644
--- a/tests/unit/Codeception/Module/Db/MssqlSqlSrvDbTest.php
+++ b/tests/unit/Codeception/Module/Db/MssqlSqlSrvDbTest.php
@@ -24,7 +24,7 @@ public function getConfig(): array
         $user = getenv('MSSQL_USER') ?: 'sa';
         $password = getenv('MSSQL_PASSWORD') ?: '';
         $database = getenv('MSSQL_DB') ?: 'codeception_test';
-        $dsn = getenv('MSSQL_DSN') ?: 'sqlsrv:Server=' . $host . ';Database=' . $database;
+        $dsn = getenv('MSSQL_DSN') ?: 'sqlsrv:Server=' . $host . ';Database=' . $database . ';Encrypt=no;TrustServerCertificate=yes';
 
         return [
             'dsn' => $dsn,

From 4f0b0f4e6eca318360114cf654b394e49d237642 Mon Sep 17 00:00:00 2001
From: Szabolcs Hajdu <sabee0418@gmail.com>
Date: Mon, 4 Mar 2024 22:06:45 +0100
Subject: [PATCH 2/2] feat(test): add documentation to run tests locally +
 Apple Silicon support

---
 Makefile                 | 40 +++++++++++++++++++++++++++++
 docker-compose.amd64.yml | 17 +++++++++++++
 docker-compose.yml       | 10 +++++---
 php81.Dockerfile         |  4 +--
 tests/README.md          | 54 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 120 insertions(+), 5 deletions(-)
 create mode 100644 Makefile
 create mode 100644 docker-compose.amd64.yml
 create mode 100644 tests/README.md

diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..5d5cdee6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,40 @@
+.PHONY: $(filter-out help, $(MAKECMDGOALS))
+.DEFAULT_GOAL := help
+
+DOCKER_COMPOSE := $(if $(shell command -v docker-compose 2> /dev/null),docker-compose,docker compose) -f docker-compose.yml
+ARCH           := $(shell uname -m)
+CURRENT_USER   := $(shell id -u):$(shell id -g)
+
+# Check if docker-compose.override.yml exists and if so, add it to DOCKER_COMPOSE
+ifneq (,$(wildcard ./docker-compose.override.yml))
+    DOCKER_COMPOSE += -f docker-compose.override.yml
+endif
+
+# Support Apple Silicon
+ifeq ($(ARCH),arm64)
+    DOCKER_COMPOSE += -f docker-compose.amd64.yml
+endif
+
+DOCKER_EXEC_PHP_WITH_USER = $(DOCKER_COMPOSE) exec -u $(CURRENT_USER) php bash -c
+
+help: ## Show this help message
+	@echo "\033[33mUsage:\033[0m\n  make [target] [arg=\"val\"...]\n\n\033[33mTargets:\033[0m"
+	@grep -hE '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[32m%-25s\033[0m %s\n", $$1, $$2}'
+
+start: ## Start the containers for testing
+	$(MAKE) -i stop
+	CURRENT_USER=$(CURRENT_USER) $(DOCKER_COMPOSE) up -d --build --force-recreate --remove-orphans
+	$(DOCKER_COMPOSE) run --rm wait -c mysql:3306,postgres:5432,mssql:1433 -t 60
+	$(MAKE) vendor
+
+stop: ## Stop and remove containers
+	$(DOCKER_COMPOSE) down --remove-orphans --volumes
+
+php-cli: ## Open bash in PHP container
+	$(DOCKER_COMPOSE) exec -u $(CURRENT_USER) php bash
+
+vendor: ## Install dependencies
+	$(DOCKER_EXEC_PHP_WITH_USER) "composer install --no-interaction --prefer-dist"
+
+test: ## Run the tests
+	$(DOCKER_EXEC_PHP_WITH_USER) "php vendor/bin/codecept run"
diff --git a/docker-compose.amd64.yml b/docker-compose.amd64.yml
new file mode 100644
index 00000000..3af4ab83
--- /dev/null
+++ b/docker-compose.amd64.yml
@@ -0,0 +1,17 @@
+version: '3.9'
+
+services:
+  php:
+    platform: linux/amd64
+
+  mysql:
+    platform: linux/amd64
+
+  postgres:
+    platform: linux/amd64
+
+  mssql:
+    platform: linux/amd64
+
+  wait:
+    platform: linux/amd64
diff --git a/docker-compose.yml b/docker-compose.yml
index 21e6d5dc..5bb5a742 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,12 +1,13 @@
 version: "3.9"
 
 services:
-  php81:
-    image: codeception-module-db-php81:2.2.0
+  php:
+    container_name: codeception-module-db
     build:
       context: .
       dockerfile: ./php81.Dockerfile
     environment:
+      COMPOSER_HOME: /tmp/.composer
       MYSQL_HOST: host.docker.internal
       MYSQL_DB: codeception
       MYSQL_PASSWORD: codeception
@@ -20,7 +21,8 @@ services:
       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
     volumes:
-      - ".:/var/www/html"
+      - ${HOME}/.composer:/tmp/.composer
+      - .:/var/www/html
 
   mysql:
     image: mysql:5.7
@@ -50,3 +52,5 @@ services:
       - ./tests/data/scripts:/scripts:ro
     entrypoint: [ "/bin/bash", "-c", "/scripts/mssql.sh" ]
 
+  wait:
+    image: dokku/wait
diff --git a/php81.Dockerfile b/php81.Dockerfile
index ca24ccde..440dfa19 100644
--- a/php81.Dockerfile
+++ b/php81.Dockerfile
@@ -1,4 +1,4 @@
-FROM php:8.1-cli
+FROM php:8.1-fpm
 
 COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
 
@@ -10,7 +10,7 @@ RUN apt-get update && \
         zlib1g-dev \
         libzip-dev \
         libpq-dev \
-        mariadb-client-10.5
+        default-mysql-client
 
 RUN install-php-extensions \
     pdo_mysql-stable \
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 00000000..abab0b5d
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,54 @@
+# Local Test Environment
+
+## Prerequisites
+
+- Docker
+- Docker Compose
+- Make
+
+## Setup
+
+1. Clone the repository to your local machine.
+2. Navigate to the project directory.
+
+## Running the Docker Environment
+
+To start the Docker environment, use the following command:
+
+```bash
+make start
+```
+
+This command will start all the necessary containers for the application. It will also build the Docker images if they are not already built.
+
+## Running Tests
+
+To run the tests, use the following command:
+
+```bash
+make test
+```
+
+This command will execute the tests inside the PHP container.
+
+## Other Commands
+
+- To stop and remove the Docker containers, use the following command:
+
+```bash
+make stop
+```
+
+- To open a bash shell inside the PHP container, use the following command:
+
+```bash
+make php-cli
+```
+
+- To install the dependencies, use the following command:
+
+```bash
+make vendor
+```
+
+Please note that all these commands should be run from the root directory of the project where the `Makefile` is located.
