Skip to content

Commit 91ceba1

Browse files
p4veIPavel Karfikclxmstaab
authored
Add dotenv (#321)
Co-authored-by: Pavel Karfik <[email protected]> Co-authored-by: Markus Staab <[email protected]>
1 parent f5e14e6 commit 91ceba1

File tree

10 files changed

+55
-9
lines changed

10 files changed

+55
-9
lines changed

.env.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DBA_HOST=mysql80.ab
2+
DBA_USER=testuser
3+
DBA_PASSWORD=test
4+
DBA_DATABASE=phpstan_dba
5+
DBA_MODE=recording
6+
DBA_REFLECTOR=mysqli

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ composer.lock
55

66
mysqli.php
77
pdo.php
8+
9+
.env

bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?php
22

3+
use Dotenv\Dotenv;
34
use staabm\PHPStanDba\QueryReflection\QueryReflection;
45
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
56
use staabm\PHPStanDba\Tests\ReflectorFactory;
67

78
require_once __DIR__.'/vendor/autoload.php';
89

10+
if (false === getenv('GITHUB_ACTION')) {
11+
$dotenv = Dotenv::createImmutable(__DIR__);
12+
$dotenv->load();
13+
}
14+
915
$config = RuntimeConfiguration::create();
1016
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
1117
// $config->debugMode(true);

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"phpstan/phpstan-phpunit": "^1.0",
1818
"phpstan/phpstan-strict-rules": "^1.1",
1919
"phpunit/phpunit": "^9",
20-
"symplify/phpstan-extensions": "^10.0"
20+
"symplify/phpstan-extensions": "^10.0",
21+
"vlucas/phpdotenv": "^5.4"
2122
},
2223
"conflicts": {
2324
"phpstan/phpstan": "1.4.0"

tests/ReflectorFactory.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ public static function create(string $cacheDir): QueryReflector
2323
$user = getenv('DBA_USER') ?: 'root';
2424
$password = getenv('DBA_PASSWORD') ?: 'root';
2525
$dbname = getenv('DBA_DATABASE') ?: 'phpstan_dba';
26+
$mode = getenv('DBA_MODE') ?: 'recording';
27+
$reflector = getenv('DBA_REFLECTOR') ?: 'mysqli';
2628
} else {
27-
$host = getenv('DBA_HOST') ?: 'mysql80.ab';
28-
$user = getenv('DBA_USER') ?: 'testuser';
29-
$password = getenv('DBA_PASSWORD') ?: 'test';
30-
$dbname = getenv('DBA_DATABASE') ?: 'phpstan_dba';
29+
$host = getenv('DBA_HOST') ?: $_ENV['DBA_HOST'];
30+
$user = getenv('DBA_USER') ?: $_ENV['DBA_USER'];
31+
$password = getenv('DBA_PASSWORD') ?: $_ENV['DBA_PASSWORD'];
32+
$dbname = getenv('DBA_DATABASE') ?: $_ENV['DBA_DATABASE'];
33+
$mode = getenv('DBA_MODE') ?: $_ENV['DBA_MODE'];
34+
$reflector = getenv('DBA_REFLECTOR') ?: $_ENV['DBA_REFLECTOR'];
3135
}
3236

33-
$mode = getenv('DBA_MODE') ?: 'recording';
34-
$reflector = getenv('DBA_REFLECTOR') ?: 'mysqli';
35-
3637
// make env vars available to tests, in case non are defined yet
37-
putenv('DBA_REFLECTOR='.$reflector);
38+
$_ENV['DBA_REFLECTOR'] = $reflector;
3839

3940
// we need to record the reflection information in both, phpunit and phpstan since we are replaying it in both CI jobs.
4041
// in a regular application you will use phpstan-dba only within your phpstan CI job, therefore you only need 1 cache-file.

tests/default/config/bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?php
22

3+
use Dotenv\Dotenv;
34
use staabm\PHPStanDba\QueryReflection\QueryReflection;
45
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
56
use staabm\PHPStanDba\Tests\ReflectorFactory;
67

78
require_once __DIR__.'/../../../vendor/autoload.php';
89

10+
if (false === getenv('GITHUB_ACTION')) {
11+
$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
12+
$dotenv->load();
13+
}
14+
915
$config = RuntimeConfiguration::create();
1016
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
1117
// $config->debugMode(true);

tests/defaultFetchAssoc/config/bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<?php
22

3+
use Dotenv\Dotenv;
34
use staabm\PHPStanDba\QueryReflection\QueryReflection;
45
use staabm\PHPStanDba\QueryReflection\QueryReflector;
56
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
67
use staabm\PHPStanDba\Tests\ReflectorFactory;
78

89
require_once __DIR__.'/../../../vendor/autoload.php';
910

11+
if (false === getenv('GITHUB_ACTION')) {
12+
$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
13+
$dotenv->load();
14+
}
15+
1016
$config = RuntimeConfiguration::create();
1117
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
1218
$config->defaultFetchMode(QueryReflector::FETCH_TYPE_ASSOC);

tests/defaultFetchNumeric/config/bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<?php
22

3+
use Dotenv\Dotenv;
34
use staabm\PHPStanDba\QueryReflection\QueryReflection;
45
use staabm\PHPStanDba\QueryReflection\QueryReflector;
56
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
67
use staabm\PHPStanDba\Tests\ReflectorFactory;
78

89
require_once __DIR__.'/../../../vendor/autoload.php';
910

11+
if (false === getenv('GITHUB_ACTION')) {
12+
$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
13+
$dotenv->load();
14+
}
15+
1016
$config = RuntimeConfiguration::create();
1117
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
1218
$config->defaultFetchMode(QueryReflector::FETCH_TYPE_NUMERIC);

tests/rules/config/bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?php
22

3+
use Dotenv\Dotenv;
34
use staabm\PHPStanDba\QueryReflection\QueryReflection;
45
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
56
use staabm\PHPStanDba\Tests\ReflectorFactory;
67

78
require_once __DIR__.'/../../../vendor/autoload.php';
89

10+
if (false === getenv('GITHUB_ACTION')) {
11+
$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
12+
$dotenv->load();
13+
}
14+
915
$config = RuntimeConfiguration::create();
1016
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
1117
// $config->debugMode(true);

tests/stringify/config/bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?php
22

3+
use Dotenv\Dotenv;
34
use staabm\PHPStanDba\QueryReflection\QueryReflection;
45
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
56
use staabm\PHPStanDba\Tests\ReflectorFactory;
67

78
require_once __DIR__.'/../../../vendor/autoload.php';
89

10+
if (false === getenv('GITHUB_ACTION')) {
11+
$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
12+
$dotenv->load();
13+
}
14+
915
$config = RuntimeConfiguration::create();
1016
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
1117
$config->stringifyTypes(true);

0 commit comments

Comments
 (0)