Skip to content
Merged
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
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line suppose to remain in docs?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 71 is the line I was referencing there.


- 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
74 changes: 0 additions & 74 deletions Vagrantfile

This file was deleted.

7 changes: 7 additions & 0 deletions bin/install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

/usr/bin/composer validate && \
/usr/bin/composer --ignore-platform-reqs install \
--no-ansi --no-progress --no-scripts \
--classmap-authoritative --no-interaction \
--quiet
54 changes: 54 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
services:
php:
build:
context: ./
dockerfile: docker/php/Dockerfile
args:
- PHP_VERSION=${PHP_VERSION:-8.3.19}
volumes:
- ./:/var/www/html
depends_on:
- mysql
- postgresql

mysql:
build:
context: ./
dockerfile: docker/databases/mysql/Dockerfile
args:
- VERSION=${MYSQL_VERSION:-8.0.41}
ports:
- "3306:3306"
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE:-laminasdb_test}
- MYSQL_USER=${MYSQL_USER:-user}
- MYSQL_PASSWORD=${MYSQL_PASSWORD:-password}
- MYSQL_RANDOM_ROOT_PASSWORD=${MYSQL_RANDOM_ROOT_PASSWORD:-yes}
volumes:
- ./test/integration/TestFixtures/mysql.sql:/docker-entrypoint-initdb.d/mysql.sql
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10

postgresql:
build:
context: ./
dockerfile: docker/databases/postgresql/Dockerfile
args:
- VERSION=${VERSION:-17.4}
- ALPINE_VERSION=${ALPINE_VERSION:-3.21}
ports:
- "5432:5432"
volumes:
- ./test/integration/TestFixtures/pgsql.sql:/docker-entrypoint-initdb.d/pgsql.sql
environment:
- POSTGRES_DB=${POSTGRES_DB:-laminasdb_test}
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
healthcheck:
test: ["CMD-SHELL", "sh -c 'pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-laminasdb_test}'"]
interval: 30s
timeout: 60s
retries: 5
start_period: 80s
3 changes: 3 additions & 0 deletions docker/databases/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ARG VERSION=8.4.5

FROM mysql:${VERSION}-bookworm AS base
4 changes: 4 additions & 0 deletions docker/databases/postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARG VERSION=17.4
ARG ALPINE_VERSION=3.21

FROM postgres:${VERSION}-alpine${ALPINE_VERSION} AS base
26 changes: 26 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ARG PHP_VERSION=8.3.19

FROM php:${PHP_VERSION}-apache-bookworm AS base

# Copy Composer from the official Docker Hub repository to the local filesystem
COPY --from=composer:2.8.6 /usr/bin/composer /usr/bin/

# Install the database extensions for MySQL, PostgreSQL, and SQLite, their
# dependencies, and any other tools that are required for the environment to be
# used fully and completely.
RUN apt-get update \
&& apt-get install -y git libpq-dev libsqlite3-dev \
&& docker-php-ext-install mysqli pdo pdo_mysql pdo_pgsql pdo_sqlite pgsql \
&& apt-get clean

# Allow the www-data login so that it can run Composer instead of using root
RUN usermod -s /usr/bin/bash www-data

# Copy all of the files from the context to the current directory setting the
# correct owner
COPY --chown=www-data:www-data . .

RUN chmod +x bin/install-deps.sh

# Validate and install PHP's dependencies
RUN su --preserve-environment www-data --command "bin/install-deps.sh"
1 change: 1 addition & 0 deletions docker/php/conf.d/error_reporting.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error_reporting=E_ALL
6 changes: 6 additions & 0 deletions docker/php/conf.d/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zend_extension=xdebug

[xdebug]
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
20 changes: 11 additions & 9 deletions phpunit.xml.dist

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 23 is most likely why you are getting the listener error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, I'm not sure why unless this was affected by the huge amount of changes to the event system in the newer versions of Phpunit.

Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@
-->
<!-- Integration Test Variables -->
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL" value="false"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME" value="192.168.20.20"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_USERNAME" value="root"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PASSWORD" value="Password123"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME" value="mysql"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_USERNAME" value="user"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PASSWORD" value="password"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_DATABASE" value="laminasdb_test"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL" value="false"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME" value="postgresql"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_USERNAME" value="postgres"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_PASSWORD" value="postgres"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_DATABASE" value="laminasdb_test"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY" value="false"/>
<!--
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV" value="false"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_HOSTNAME" value="192.168.20.20"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_USERNAME" value="sa"/>
Expand All @@ -53,11 +60,6 @@
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_USERNAME" value=""/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_PASSWORD" value=""/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_DATABASE" value=""/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL" value="false"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME" value="192.168.20.20"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_USERNAME" value="postgres"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_PASSWORD" value="postgres"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_DATABASE" value="laminasdb_test"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY" value="true"/>
-->
</php>
</phpunit>
6 changes: 3 additions & 3 deletions test/integration/TestFixtures/mysql.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DROP TABLE IF EXISTS test;
CREATE TABLE test (
CREATE TABLE IF NOT EXISTS test (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
value VARCHAR(255) NOT NULL,
Expand All @@ -13,7 +13,7 @@ INSERT INTO test (name, value) VALUES
('123', 'bar');

DROP TABLE IF EXISTS test_charset;
CREATE TABLE test_charset (
CREATE TABLE IF NOT EXISTS test_charset (
id INT NOT NULL AUTO_INCREMENT,
field$ VARCHAR(255) NOT NULL,
field_ VARCHAR(255) NOT NULL,
Expand All @@ -25,7 +25,7 @@ INSERT INTO test_charset (field$, field_) VALUES
('bar', 'baz');

DROP TABLE IF EXISTS test_audit_trail;
CREATE TABLE test_audit_trail (
CREATE TABLE IF NOT EXISTS test_audit_trail (
id INT NOT NULL AUTO_INCREMENT,
test_id INT NOT NULL,
test_value_old VARCHAR(255) NOT NULL,
Expand Down
8 changes: 6 additions & 2 deletions test/integration/TestFixtures/pgsql.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
DROP TABLE IF EXISTS test;
CREATE TABLE IF NOT EXISTS test (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
value VARCHAR(255) NOT NULL
);

INSERT INTO test (name, value) VALUES
INSERT INTO test (name, value)
VALUES
('foo', 'bar'),
('bar', 'baz');

DROP TABLE IF EXISTS test_charset;
CREATE TABLE IF NOT EXISTS test_charset (
id SERIAL PRIMARY KEY,
field$ VARCHAR(255) NOT NULL,
field_ VARCHAR(255) NOT NULL
);

INSERT INTO test_charset (field$, field_) VALUES
INSERT INTO test_charset (field$, field_)
VALUES
('foo', 'bar'),
('bar', 'baz');

Expand Down