diff --git a/.env.dist b/.env.dist new file mode 100644 index 000000000..b0dd4c486 --- /dev/null +++ b/.env.dist @@ -0,0 +1,6 @@ +DBA_HOST=mysql80.ab +DBA_USER=testuser +DBA_PASSWORD=test +DBA_DATABASE=phpstan_dba +DBA_MODE=recording +DBA_REFLECTOR=mysqli diff --git a/.gitignore b/.gitignore index 184b3f18e..140d44e7a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ composer.lock mysqli.php pdo.php + +.env diff --git a/bootstrap.php b/bootstrap.php index 4989f0c14..b0ebbdbec 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,11 +1,17 @@ load(); +} + $config = RuntimeConfiguration::create(); $config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION); // $config->debugMode(true); diff --git a/composer.json b/composer.json index 962c106bc..bbba1b910 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-strict-rules": "^1.1", "phpunit/phpunit": "^9", - "symplify/phpstan-extensions": "^10.0" + "symplify/phpstan-extensions": "^10.0", + "vlucas/phpdotenv": "^5.4" }, "conflicts": { "phpstan/phpstan": "1.4.0" diff --git a/tests/ReflectorFactory.php b/tests/ReflectorFactory.php index 18c8f890b..7384b8e2c 100644 --- a/tests/ReflectorFactory.php +++ b/tests/ReflectorFactory.php @@ -23,18 +23,19 @@ public static function create(string $cacheDir): QueryReflector $user = getenv('DBA_USER') ?: 'root'; $password = getenv('DBA_PASSWORD') ?: 'root'; $dbname = getenv('DBA_DATABASE') ?: 'phpstan_dba'; + $mode = getenv('DBA_MODE') ?: 'recording'; + $reflector = getenv('DBA_REFLECTOR') ?: 'mysqli'; } else { - $host = getenv('DBA_HOST') ?: 'mysql80.ab'; - $user = getenv('DBA_USER') ?: 'testuser'; - $password = getenv('DBA_PASSWORD') ?: 'test'; - $dbname = getenv('DBA_DATABASE') ?: 'phpstan_dba'; + $host = getenv('DBA_HOST') ?: $_ENV['DBA_HOST']; + $user = getenv('DBA_USER') ?: $_ENV['DBA_USER']; + $password = getenv('DBA_PASSWORD') ?: $_ENV['DBA_PASSWORD']; + $dbname = getenv('DBA_DATABASE') ?: $_ENV['DBA_DATABASE']; + $mode = getenv('DBA_MODE') ?: $_ENV['DBA_MODE']; + $reflector = getenv('DBA_REFLECTOR') ?: $_ENV['DBA_REFLECTOR']; } - $mode = getenv('DBA_MODE') ?: 'recording'; - $reflector = getenv('DBA_REFLECTOR') ?: 'mysqli'; - // make env vars available to tests, in case non are defined yet - putenv('DBA_REFLECTOR='.$reflector); + $_ENV['DBA_REFLECTOR'] = $reflector; // we need to record the reflection information in both, phpunit and phpstan since we are replaying it in both CI jobs. // in a regular application you will use phpstan-dba only within your phpstan CI job, therefore you only need 1 cache-file. diff --git a/tests/default/config/bootstrap.php b/tests/default/config/bootstrap.php index 5b66d5846..58862a54b 100644 --- a/tests/default/config/bootstrap.php +++ b/tests/default/config/bootstrap.php @@ -1,11 +1,17 @@ load(); +} + $config = RuntimeConfiguration::create(); $config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION); // $config->debugMode(true); diff --git a/tests/defaultFetchAssoc/config/bootstrap.php b/tests/defaultFetchAssoc/config/bootstrap.php index c4ceb4205..844ace2b4 100644 --- a/tests/defaultFetchAssoc/config/bootstrap.php +++ b/tests/defaultFetchAssoc/config/bootstrap.php @@ -1,5 +1,6 @@ load(); +} + $config = RuntimeConfiguration::create(); $config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION); $config->defaultFetchMode(QueryReflector::FETCH_TYPE_ASSOC); diff --git a/tests/defaultFetchNumeric/config/bootstrap.php b/tests/defaultFetchNumeric/config/bootstrap.php index 9de8bbd16..a22663be1 100644 --- a/tests/defaultFetchNumeric/config/bootstrap.php +++ b/tests/defaultFetchNumeric/config/bootstrap.php @@ -1,5 +1,6 @@ load(); +} + $config = RuntimeConfiguration::create(); $config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION); $config->defaultFetchMode(QueryReflector::FETCH_TYPE_NUMERIC); diff --git a/tests/rules/config/bootstrap.php b/tests/rules/config/bootstrap.php index 5b66d5846..58862a54b 100644 --- a/tests/rules/config/bootstrap.php +++ b/tests/rules/config/bootstrap.php @@ -1,11 +1,17 @@ load(); +} + $config = RuntimeConfiguration::create(); $config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION); // $config->debugMode(true); diff --git a/tests/stringify/config/bootstrap.php b/tests/stringify/config/bootstrap.php index 814c7f206..4ed1aad54 100644 --- a/tests/stringify/config/bootstrap.php +++ b/tests/stringify/config/bootstrap.php @@ -1,11 +1,17 @@ load(); +} + $config = RuntimeConfiguration::create(); $config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION); $config->stringifyTypes(true);