Skip to content

Commit 3aa61b8

Browse files
committed
Avoid parseDsn error
1 parent 31125ac commit 3aa61b8

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sudo: false
1313

1414
env:
1515
matrix:
16-
- DB=mysql db_dsn='mysql://travis@127.0.0.1/cakephp_test'
16+
- DB=mysql db_user=root db_host=0.0.0.0 db_name=cakephp_test
1717

1818
global:
1919
- DEFAULT=1 PREFER_LOWEST="--prefer-lowest"
@@ -23,10 +23,10 @@ matrix:
2323

2424
include:
2525
- php: 7.3
26-
env: PREFER_LOWEST=""
26+
env: PREFER_LOWEST="" DB=mysql db_user=root db_host=0.0.0.0 db_name=cakephp_test
2727

2828
- php: '7.4snapshot'
29-
env: PREFER_LOWEST=""
29+
env: PREFER_LOWEST="" DB=mysql db_user=root db_host=0.0.0.0 db_name=cakephp_test
3030

3131
- php: 7.3
3232
env: PHPCS=1 DEFAULT=0 PREFER_LOWEST="

tests/bootstrap.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,28 @@
2727

2828
return;
2929
}
30-
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';
30+
31+
// With PHP7.3 & CakePHP 3.5.0, StaticConfigTrait::parseDsn causes the error in preg_match
32+
// (It has benn fixed in 3.5.1 https://github.com/cakephp/cakephp/commit/91475ccfa58948b2561ffd9631664c1c3edaf300)
33+
// In place of using `db_dsn` uri, set db config with array.
34+
if (getenv('DB') === 'mysql') {
35+
$dbConfig = [
36+
'className' => \Cake\Database\Connection::class,
37+
'driver' => \Cake\Database\Driver\Mysql::class,
38+
'host' => getenv('db_host'),
39+
'username' => getenv('db_user'),
40+
'database' => getenv('db_name'),
41+
'url' => null,
42+
];
43+
\Cake\Datasource\ConnectionManager::setConfig('test', $dbConfig);
44+
\Cake\Datasource\ConnectionManager::setConfig('test_custom_i18n_datasource', $dbConfig);
45+
try {
46+
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';
47+
} catch (\BadMethodCallException $e) {
48+
if (strpos($e->getMessage(), 'Cannot reconfigure existing key') !== 0) {
49+
throw $e;
50+
}
51+
}
52+
} else {
53+
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';
54+
}

0 commit comments

Comments
 (0)