Skip to content

Commit

Permalink
Merge pull request #31 from dunglas/mysql
Browse files Browse the repository at this point in the history
Add functionnal tests for MySQL
  • Loading branch information
dunglas committed Nov 19, 2017
2 parents 0f3d431 + a772e61 commit 2de29f7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ cache:

services:
- postgresql
- mysql

env:
global:
- POSTGRESQL_HOST="127.0.0.1"
- POSTGRESQL_USER="postgres"
- POSTGRESQL_PASSWORD=""
- POSTGRESQL_DBNAME="travis_ci_test"
- MYSQL_HOST="127.0.0.1"
- MYSQL_USER="root"
- MYSQL_PASSWORD=""
- MYSQL_=DBNAME="travis_ci_test"

php:
- 5.5
Expand All @@ -31,6 +36,7 @@ matrix:
before_install:
- phpenv config-rm xdebug.ini || echo "xdebug not available"
- psql -c 'create database travis_ci_test;' -U postgres
- mysql -e 'CREATE DATABASE travis_ci_test;'

install:
- composer update --no-interaction --prefer-dist
Expand All @@ -39,4 +45,5 @@ install:
- if [[ $deps = 'low' ]]; then composer update --prefer-dist --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi; fi

script:
- vendor/bin/phpunit
- DB=POSTGRESQL vendor/bin/phpunit
- DB=MYSQL vendor/bin/phpunit
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,22 @@ var_dump($foo->misc); // Same as what we set earlier
```

You can execute complex queries using [native queries](http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/native-sql.html).
Checkout [the PostgreSQL documentation](http://www.postgresql.org/docs/current/static/datatype-json.html) to learn how to query the stored JSON document.

MySQL support is coming (see the FAQ).
Checkout [the PostgreSQL documentation](http://www.postgresql.org/docs/current/static/datatype-json.html) or [the MySQL](https://dev.mysql.com/doc/refman/en/json.html)
one to learn how to query the stored JSON document.

## FAQ

**What DBMS are supported?**

PostgreSQL and MySQL are supported.
PostgreSQL 9.4+ and MySQL 5.7+ are supported.

**Which versions of Doctrine are supported?**

Doctrine ORM 2.6+ and DBAL 2.6+ are supported.


**How to use [the JSONB type of PostgreSQL](http://www.postgresql.org/docs/current/static/datatype-json.html)?**

First, be sure to use Postgres >= 9.4, Doctrine ORM >= 2.6 (dev) and DBAL >= 2.6 (dev).
Then, you need to set an option of in the column mapping:

```php
Expand All @@ -189,16 +192,22 @@ Yes.

## Run tests

To execute the test suite, you need running PostgreSQL and MySQL servers.
Run the following commands in your shell to set mandatory environment variables:

export SYMFONY__POSTGRESQL_HOST=127.0.0.1
export SYMFONY__POSTGRESQL_USER=dunglas
export SYMFONY__POSTGRESQL_PASSWORD=
export SYMFONY__POSTGRESQL_DBNAME=my_test_db
export POSTGRESQL_HOST=127.0.0.1
export POSTGRESQL_USER=dunglas
export POSTGRESQL_PASSWORD=
export POSTGRESQL_DBNAME=my_test_db

export MYSQL_HOST=127.0.0.1
export MYSQL_USER=dunglas
export MYSQL_PASSWORD=
export MYSQL_=DBNAME="my_test_db

The database must exist. Be careful, its content may be deleted.
Databases must exist. Be careful, its content may be deleted.

Run the test suite using [PHPUnit](https://phpunit.de/):
Run the test suite, execute [PHPUnit](https://phpunit.de/):

phpunit

Expand Down
11 changes: 6 additions & 5 deletions tests/Fixtures/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
'test' => null,
]);

$db = getenv('DB');
$c->loadFromExtension('doctrine', [
'dbal' => [
'driver' => 'pdo_pgsql',
'host' => getenv('POSTGRESQL_HOST'),
'dbname' => getenv('POSTGRESQL_DBNAME'),
'user' => getenv('POSTGRESQL_USER'),
'password' => getenv('POSTGRESQL_PASSWORD'),
'driver' => 'MYSQL' === $db ? 'pdo_mysql' : 'pdo_pgsql',
'host' => getenv("{$db}_HOST"),
'dbname' => getenv("{$db}_DBNAME"),
'user' => getenv("{$db}_USER"),
'password' => getenv("{$db}_PASSWORD"),
'charset' => 'UTF8',
],
'orm' => [
Expand Down

0 comments on commit 2de29f7

Please sign in to comment.