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

Replace Vagrant VM with Docker containers #217

Open
wants to merge 1 commit into
base: 2.14.x
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
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,36 @@ Unit tests do not require additional functionality beyond having the appropriate
### 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:
The repository includes a `docker-compose.yml` which allows you to fire up [Docker](https://www.docker.com) containers with several of our target databases, including:

- MySQL
- PostgreSQL
- SQL Server

To start up vagrant:
To start the Docker containers and wait till the containers are ready:

```bash
$ vagrant up
$ docker-compose up -d
```

Copy `phpunit.xml.dist` to `phpunit.xml`, and change the following ENV var declaration values to "true":
Set the following environment variables to run the integration test for that platform:

- 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
- TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL=true
- TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV=true
- TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL=true
- TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY=true

On Linux:

```bash
export TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL=true
```

On Windows (cmd):

```
set TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL=true
```

From there, you can run the integration tests:

Expand Down
74 changes: 0 additions & 74 deletions Vagrantfile

This file was deleted.

26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3'
services:
mysql:
image: mysql:${MYSQL_VERSION:-5.7}
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=${TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PASSWORD:-Password123}
- MYSQL_DATABASE=${TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_DATABASE:-laminasdb_test}

postgres:
image: postgres:${POSTGRES_VERSION:-13}
ports:
- "5432:5432"
environment:
- POSTGRES_USER=${TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_USERNAME:-postgres}
- POSTGRES_PASSWORD=${TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_PASSWORD:-postgres}
- POSTGRES_DB=${TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_DATABASE:-laminasdb_test}

sqlsrv:
image: mcr.microsoft.com/mssql/server:${SQLSRV_VERSION:-2019-latest}
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=${TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD:-Password123%}
12 changes: 8 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@
values specific to your test environment.
-->
<!-- Integration Test Variables -->
<ini name="error_reporting" value="-1" />
<ini name="display_errors" value="on" />

<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL" value="false"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME" value="192.168.20.20"/>
<!-- Use IP, overwise it fails -->
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME" value="127.0.0.1"/>
<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_DATABASE" value="laminasdb_test"/>
<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_HOSTNAME" value="localhost"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_USERNAME" value="sa"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD" value="Password123"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD" value="Password123%"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_DATABASE" value="laminasdb_test"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8" value="false"/>
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_HOSTNAME" value=""/>
Expand All @@ -54,7 +58,7 @@
<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_HOSTNAME" value="localhost"/>
<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"/>
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Adapter/Driver/Mysqli/TraitSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait TraitSetup
*/
protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) {
if (!filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped('Mysqli integration test disabled');
}

Expand Down
7 changes: 6 additions & 1 deletion test/integration/Adapter/Driver/Pdo/Mysql/AdapterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@

trait AdapterTrait
{
/**
* @var Adapter
*/
protected $adapter;

protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) {
if (!filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped('pdo_mysql integration tests are not enabled!');
}

Expand Down
2 changes: 2 additions & 0 deletions test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class QueryTest extends TestCase
{

use AdapterTrait;

/**
Expand Down Expand Up @@ -103,4 +104,5 @@ public function testNamedParameters()
'value' => 'bar',
]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@

trait AdapterTrait
{
/**
* @var Adapter
*/
protected $adapter;

protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL')) {
if (!filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped('pdo_pgsql integration tests are not enabled!');
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/Adapter/Platform/MysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MysqlTest extends TestCase

protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) {
if (!filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped(self::class . ' integration tests are not enabled!');
}
if (extension_loaded('mysqli')) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Adapter/Platform/PostgresqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PostgresqlTest extends TestCase

protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL')) {
if (!filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped(self::class . ' integration tests are not enabled!');
}
if (extension_loaded('pgsql')) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Adapter/Platform/SqlServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SqlServerTest extends TestCase

protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV')) {
if (!filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped(self::class . ' integration tests are not enabled!');
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/Adapter/Platform/SqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SqliteTest extends TestCase

protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY')) {
if (!filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped(self::class . ' integration tests are not enabled!');
}
if (extension_loaded('pdo')) {
Expand Down
12 changes: 8 additions & 4 deletions test/integration/IntegrationTestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public function startTestSuite(TestSuite $suite): void
return;
}

if (getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) {
if (filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL'), FILTER_VALIDATE_BOOLEAN)) {
$this->fixtureLoaders[] = new MysqlFixtureLoader();
}

if (getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL')) {
if (filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL'), FILTER_VALIDATE_BOOLEAN)) {
$this->fixtureLoaders[] = new PgsqlFixtureLoader();
}

if (getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV')) {
if (filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV'), FILTER_VALIDATE_BOOLEAN)) {
$this->fixtureLoaders[] = new SqlServerFixtureLoader();
}

Expand All @@ -46,7 +46,11 @@ public function startTestSuite(TestSuite $suite): void
printf("\nIntegration test started.\n");

foreach ($this->fixtureLoaders as $fixtureLoader) {
$fixtureLoader->createDatabase();
try {
$fixtureLoader->createDatabase();
} catch (\Exception $ex) {
trigger_error($ex->getMessage(), E_USER_WARNING);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/Adapter/Driver/Mysqli/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ConnectionTest extends TestCase
*/
protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) {
if (!filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped('Mysqli test disabled');
}
$this->connection = new Connection([]);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ abstract class AbstractIntegrationTest extends TestCase
*/
protected function setUp(): void
{
if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV')) {
if (!filter_var(getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV'), FILTER_VALIDATE_BOOLEAN)) {
$this->markTestSkipped('SQLSRV tests are not enabled');
}

foreach ($this->variables as $name => $value) {
if (! getenv($value)) {
$this->markTestSkipped(
Expand Down