Skip to content

Commit

Permalink
test: use phpunit env
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed Jul 25, 2018
1 parent acf8715 commit 2fb7d59
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
config/*
!config/migrations.php
!config/api_sample.php
phpunit.xml

public/core/

Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ before_install:
- sudo service apache2 restart

before_script:
- cp phpunit.xml.dist phpunit.xml
- mysql -uroot $DIRECTUS_DB_NAME < tests/db.sql
- composer install
- bin/directus install:config -h "localhost" -P 3306 -n "$DIRECTUS_DB_NAME" -u "$DIRECTUS_DB_USER" -e "$DIRECTUS_ADMIN_EMAIL"
Expand Down
16 changes: 0 additions & 16 deletions phpunit.xml

This file was deleted.

24 changes: 24 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="phpunit.php"
colors="true"
>
<php>
<env name="API_URL" value="http://localhost/api"/>
<env name="DB_HOST" value="localhost"/>
<env name="DB_PORT" value="3306"/>
<env name="DB_NAME" value="directus_test"/>
<env name="DB_USERNAME" value="root"/>
<env name="DB_PASSWORD" value=""/>
</php>
<testsuites>
<testsuite name="Directus's test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/core</directory>
</whitelist>
</filter>
</phpunit>
21 changes: 21 additions & 0 deletions src/helpers/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -1595,3 +1595,24 @@ function is_valid_regex_pattern($pattern)
return $valid;
}
}

if (!function_exists('env')) {
/**
* Returns an environment variable
*
* @param string $key
* @param null $default
*
* @return array|false|null|string
*/
function env($key, $default = null)
{
$value = getenv($key);

if ($value === false) {
$value = $default;
}

return $value;
}
}
10 changes: 5 additions & 5 deletions tests/utils/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ function create_db_connection()

return new \Directus\Database\Connection([
'driver' => 'Pdo_mysql',
'host' => 'localhost',
'port' => 3306,
'database' => 'directus_test',
'username' => 'root',
'password' => null,
'host' => \Directus\env('DB_HOST', 'localhost'),
'port' => \Directus\env('DB_PORT', 3306),
'database' => \Directus\env('DB_NAME', 'directus_test'),
'username' => \Directus\env('DB_USERNAME', 'root'),
'password' => \Directus\env('DB_PASSWORD', null),
'charset' => $charset,
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
\PDO::MYSQL_ATTR_INIT_COMMAND => sprintf('SET NAMES "%s"', $charset)
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
function request($method, $path, array $options = [])
{
$http = new GuzzleHttp\Client([
'base_uri' => 'http://localhost/api'
'base_uri' => \Directus\env('API_URL', 'http://localhost/api')
]);

// if json is set to true, it means we want the body to be a JSON
Expand Down

0 comments on commit 2fb7d59

Please sign in to comment.