Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DBA_HOST=mysql80.ab
DBA_USER=testuser
DBA_PASSWORD=test
DBA_DATABASE=phpstan_dba
DBA_MODE=recording
DBA_REFLECTOR=mysqli
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ composer.lock

mysqli.php
pdo.php

.env
6 changes: 6 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php

use Dotenv\Dotenv;
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
use staabm\PHPStanDba\Tests\ReflectorFactory;

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

if (false === getenv('GITHUB_ACTION')) {
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
}

$config = RuntimeConfiguration::create();
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
// $config->debugMode(true);
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 9 additions & 8 deletions tests/ReflectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions tests/default/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php

use Dotenv\Dotenv;
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
use staabm\PHPStanDba\Tests\ReflectorFactory;

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

if (false === getenv('GITHUB_ACTION')) {
Copy link
Owner

@staabm staabm Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this IF-case arround the loading.


another question: does the dotenv class automatically load the .env.dist file now?
I tried running this PR locally and I am still getting errors

$ composer test
> phpunit -c tests/default/config/phpunit.xml
PHPUnit 9.5.16 by Sebastian Bergmann and contributors.

Error in bootstrap script: RuntimeException:
Unknown mode:
PHP Warning:  Undefined array key "DBA_HOST" in C:\dvl\Workspace\phpstan-dba\tests\ReflectorFactory.php on line 29
PHP Warning:  Undefined array key "DBA_USER" in C:\dvl\Workspace\phpstan-dba\tests\ReflectorFactory.php on line 30
PHP Warning:  Undefined array key "DBA_PASSWORD" in C:\dvl\Workspace\phpstan-dba\tests\ReflectorFactory.php on line 31
PHP Warning:  Undefined array key "DBA_DATABASE" in C:\dvl\Workspace\phpstan-dba\tests\ReflectorFactory.php on line 32
PHP Warning:  Undefined array key "DBA_MODE" in C:\dvl\Workspace\phpstan-dba\tests\ReflectorFactory.php on line 33
PHP Warning:  Undefined array key "DBA_REFLECTOR" in C:\dvl\Workspace\phpstan-dba\tests\ReflectorFactory.php on line 34

does it work for you locally?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh I get it now. I need to copy the .env.dist file to .env once.. it works now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the .dist file is supposed to be like a template for the envs..

But it's commonly used so some defaults / test setup can be blaced in dist and setup from the existing file..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I am used to a process where the .dist file is automtically picked up, without the need to copy it a priori.

but thats fine.

thanks for the work you put into it here. I will merge it.

$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
$dotenv->load();
}

$config = RuntimeConfiguration::create();
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
// $config->debugMode(true);
Expand Down
6 changes: 6 additions & 0 deletions tests/defaultFetchAssoc/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php

use Dotenv\Dotenv;
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use staabm\PHPStanDba\QueryReflection\QueryReflector;
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
use staabm\PHPStanDba\Tests\ReflectorFactory;

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

if (false === getenv('GITHUB_ACTION')) {
$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
$dotenv->load();
}

$config = RuntimeConfiguration::create();
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
$config->defaultFetchMode(QueryReflector::FETCH_TYPE_ASSOC);
Expand Down
6 changes: 6 additions & 0 deletions tests/defaultFetchNumeric/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php

use Dotenv\Dotenv;
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use staabm\PHPStanDba\QueryReflection\QueryReflector;
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
use staabm\PHPStanDba\Tests\ReflectorFactory;

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

if (false === getenv('GITHUB_ACTION')) {
$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
$dotenv->load();
}

$config = RuntimeConfiguration::create();
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
$config->defaultFetchMode(QueryReflector::FETCH_TYPE_NUMERIC);
Expand Down
6 changes: 6 additions & 0 deletions tests/rules/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php

use Dotenv\Dotenv;
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
use staabm\PHPStanDba\Tests\ReflectorFactory;

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

if (false === getenv('GITHUB_ACTION')) {
$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
$dotenv->load();
}

$config = RuntimeConfiguration::create();
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
// $config->debugMode(true);
Expand Down
6 changes: 6 additions & 0 deletions tests/stringify/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php

use Dotenv\Dotenv;
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
use staabm\PHPStanDba\Tests\ReflectorFactory;

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

if (false === getenv('GITHUB_ACTION')) {
$dotenv = Dotenv::createImmutable(__DIR__.'/../../..');
$dotenv->load();
}

$config = RuntimeConfiguration::create();
$config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION);
$config->stringifyTypes(true);
Expand Down