From c80699192cedbfb2bcc12005818c5017d15159df Mon Sep 17 00:00:00 2001 From: Matthew Setter Date: Wed, 19 Mar 2025 08:48:24 +1000 Subject: [PATCH 1/2] Add an initial Docker configuration This change adds the initial Docker setup, providing an environment where the tests can be run, regardless of the user's operating system. It provides three services; one for PHP, one for MySQL, and one for PostgreSQL. The PHP environment has all of the dependencies and extensions required to interact with MySQL, PostgreSQL, and SQLite, along with any required binaries. It also updates PHPUnit's configuration, where required, to sync with that configuration. The change also removes the Vagrantfile as it's no longer required. Signed-off-by: Matthew Setter --- README.md | 40 ++++++++++---- Vagrantfile | 74 -------------------------- bin/install-deps.sh | 7 +++ compose.yml | 34 ++++++++++++ docker/databases/mysql/Dockerfile | 3 ++ docker/databases/postgresql/Dockerfile | 4 ++ docker/php/Dockerfile | 26 +++++++++ docker/php/conf.d/error_reporting.ini | 1 + docker/php/conf.d/xdebug.ini | 6 +++ phpunit.xml.dist | 20 +++---- 10 files changed, 121 insertions(+), 94 deletions(-) delete mode 100644 Vagrantfile create mode 100644 bin/install-deps.sh create mode 100644 compose.yml create mode 100644 docker/databases/mysql/Dockerfile create mode 100644 docker/databases/postgresql/Dockerfile create mode 100644 docker/php/Dockerfile create mode 100644 docker/php/conf.d/error_reporting.ini create mode 100644 docker/php/conf.d/xdebug.ini diff --git a/README.md b/README.md index 8516616a0..c20e5fe4b 100644 --- a/README.md +++ b/README.md @@ -40,35 +40,53 @@ $ ./vendor/bin/phpunit --testsuite "integration test" # integration tests only Unit tests do not require additional functionality beyond having the appropriate database extensions present and loaded in your PHP binary. -### Integration tests +#### Integration tests To run the integration tests, you need databases. -The repository includes a `Vagrantfile` which allows you to fire up a [vagrant box](https://app.vagrantup.com) with several of our target databases, including: +So, the repository includes a [Docker Compose][docker-compose] configuration which allows you to start a test environment that provides several of our target databases, including _MySQL_ and _PostgreSQL_, and SQLite. -- MySQL -- PostgreSQL -- SQL Server +To start up the configuration, run the following command: -To start up vagrant: +```bash +$ docker compose up -d +``` + +To test that the environment is up and running, run the following command: ```bash -$ vagrant up +$ docker compose ps ``` -Copy `phpunit.xml.dist` to `phpunit.xml`, and change the following ENV var declaration values to "true": +You should see output similar to the following: + +```bash +docker compose ps +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +laminas-db-mysql-1 docker.io/library/laminas-db-mysql:latest "mysqld" mysql 7 hours ago Up 7 hours +laminas-db-php-1 docker.io/library/laminas-db-php:latest "apache2-foreground" php 7 hours ago Up 7 hours +laminas-db-postgresql-1 docker.io/library/laminas-db-postgresql:latest "postgres" postgresql 7 hours ago Up 7 hours +``` + +If you see three containers listed, then they're all running, and you are ready to run the test suite. +So, copy `phpunit.xml.dist` to `phpunit.xml`, and change the following environment variable to "true" to enable the three databases: - TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL -- TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV - TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL - TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY -From there, you can run the integration tests: +From there, you can run the integration tests by running the following command: ```bash -$ ./vendor/bin/phpunit --testsuite "integration test" +$ docker compose exec php composer test-integration ``` +> [!TIP] +> If you want to grow your Docker Compose knowledge, grab a (free) copy of [Deploy with Docker Compose][deploy-with-docker-compose]. + ----- - File issues at https://github.com/laminas/laminas-db/issues - Documentation is at https://docs.laminas.dev/laminas-db/ + +[docker-compose]: https://docs.docker.com/compose/intro/features-uses/ +[deploy-with-docker-compose]: https://deploywithdockercompose.com \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index ab8f9eeb5..000000000 --- a/Vagrantfile +++ /dev/null @@ -1,74 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -$install_software = <