Skip to content

Commit 74a1601

Browse files
authored
Merge pull request #209 from kitloong/feature/env
Read env from phpunit xml
2 parents b4017e9 + afa0d25 commit 74a1601

10 files changed

+96
-111
lines changed

.env.action

Lines changed: 0 additions & 33 deletions
This file was deleted.

.env.example

Lines changed: 0 additions & 33 deletions
This file was deleted.

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
/.github export-ignore
66
/tests export-ignore
77
/.editorconfig export-ignore
8-
/.env.* export-ignore
98
/.gitattributes export-ignore
109
/.gitignore export-ignore
1110
/.phpmd.xml export-ignore
1211
/check_migrations.sh export-ignore
1312
/phpcs.xml export-ignore
1413
/phpstan.neon export-ignore
1514
/phpunit.xml.dist export-ignore
15+
/phpunit-action.xml export-ignore
1616
/testbench.yaml export-ignore

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
117117
composer update --prefer-stable --prefer-dist --no-interaction --no-progress
118118
119-
- name: Setup .env
119+
- name: Setup environment
120120
run: |
121121
mkdir ./database
122122
composer run action-env-setup

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/migrations
66
/storage
77
/vendor
8-
.env
98
.php-cs-fixer.cache
109
.php_cs.cache
1110
.phpstorm.meta.php

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"prefer-stable": true,
5353
"scripts": {
5454
"action-env-setup": [
55-
"@php -r \"file_exists('.env') || copy('.env.action', '.env');\""
55+
"@php -r \"file_exists('phpunit.xml') || copy('phpunit-action.xml', 'phpunit.xml');\""
5656
],
5757
"phpcs": [
5858
"phpcs"

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ parameters:
1111
level: 6
1212

1313
ignoreErrors:
14-
- '#Class Dotenv\\Dotenv constructor invoked with 1 parameter, 4 required.#'
15-
- '#Parameter \#1 \$store of class Dotenv\\Dotenv constructor expects Dotenv\\Store\\StoreInterface, string given.#'
1614
- '#Method KitLoong\\MigrationsGenerator\\Database\\(.*)Schema::getViews\(\) should return Illuminate\\Support\\Collection<int, KitLoong\\MigrationsGenerator\\Schema\\Models\\View> but returns Illuminate\\Support\\Collection<(int|\(int\|string\)), KitLoong\\MigrationsGenerator\\Database\\Models\\(.*)\\(.*)View>.#'
1715
- '#Method KitLoong\\MigrationsGenerator\\Database\\(.*)Schema::getProcedures\(\) should return Illuminate\\Support\\Collection<int, KitLoong\\MigrationsGenerator\\Schema\\Models\\Procedure> but returns Illuminate\\Support\\Collection<(int|\(int\|string\)), KitLoong\\MigrationsGenerator\\Database\\Models\\(.*)\\(.*)Procedure>.#'
1816
- '#Method KitLoong\\MigrationsGenerator\\Database\\(.*)Schema::getForeignKeys\(\) should return Illuminate\\Support\\Collection<int, KitLoong\\MigrationsGenerator\\Schema\\Models\\ForeignKey> but returns Illuminate\\Support\\Collection<(int|\(int\|string\)), KitLoong\\MigrationsGenerator\\Database\\Models\\(.*)\\(.*)ForeignKey>.#'

phpunit-action.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
stderr="true"
8+
>
9+
<coverage includeUncoveredFiles="true"/>
10+
<testsuites>
11+
<testsuite name="Application Test Suite">
12+
<directory suffix="Test.php">tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
<source>
16+
<include>
17+
<directory suffix=".php">src</directory>
18+
</include>
19+
</source>
20+
<php>
21+
<env name="MYSQL57_HOST" value="127.0.0.1"/>
22+
<env name="MYSQL57_PORT" value="3306"/>
23+
<env name="MYSQL57_DATABASE" value="migration"/>
24+
<env name="MYSQL57_USERNAME" value="root"/>
25+
<env name="MYSQL57_PASSWORD" value=""/>
26+
27+
<env name="MYSQL8_HOST" value="127.0.0.1"/>
28+
<env name="MYSQL8_PORT" value="33062"/>
29+
<env name="MYSQL8_DATABASE" value="migration"/>
30+
<env name="MYSQL8_USERNAME" value="root"/>
31+
<env name="MYSQL8_PASSWORD" value=""/>
32+
33+
<env name="POSTGRES_HOST" value="127.0.0.1"/>
34+
<env name="POSTGRES_PORT" value="5432"/>
35+
<env name="POSTGRES_DATABASE" value="migration"/>
36+
<env name="POSTGRES_USERNAME" value="root"/>
37+
<env name="POSTGRES_PASSWORD" value="!QAZ2wsx"/>
38+
39+
<env name="SQLSRV_HOST" value="127.0.0.1"/>
40+
<env name="SQLSRV_PORT" value="1433"/>
41+
<env name="SQLSRV_DATABASE" value="migration"/>
42+
<env name="SQLSRV_USERNAME" value="sa"/>
43+
<env name="SQLSRV_PASSWORD" value="!QAZ2wsx"/>
44+
45+
<env name="MARIADB_HOST" value="127.0.0.1"/>
46+
<env name="MARIADB_PORT" value="3307"/>
47+
<env name="MARIADB_DATABASE" value="migration"/>
48+
<env name="MARIADB_USERNAME" value="root"/>
49+
<env name="MARIADB_PASSWORD" value=""/>
50+
51+
<env name="SQLITE_DATABASE" value="./database/migration.sqlite"/>
52+
53+
<env name="MYSQLDUMP_HAS_OPTION_SKIP_COLUMN_STATISTICS" value="true"/>
54+
</php>
55+
</phpunit>

phpunit.xml.dist

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,43 @@
1313
</testsuite>
1414
</testsuites>
1515
<source>
16-
<include>
17-
<directory suffix=".php">src</directory>
18-
</include>
16+
<include>
17+
<directory suffix=".php">src</directory>
18+
</include>
1919
</source>
20+
<php>
21+
<env name="MYSQL57_HOST" value="mysql57"/>
22+
<env name="MYSQL57_PORT" value="3306"/>
23+
<env name="MYSQL57_DATABASE" value="migration"/>
24+
<env name="MYSQL57_USERNAME" value=""/>
25+
<env name="MYSQL57_PASSWORD" value=""/>
26+
27+
<env name="MYSQL8_HOST" value="mysql8"/>
28+
<env name="MYSQL8_PORT" value="3306"/>
29+
<env name="MYSQL8_DATABASE" value="migration"/>
30+
<env name="MYSQL8_USERNAME" value=""/>
31+
<env name="MYSQL8_PASSWORD" value=""/>
32+
33+
<env name="POSTGRES_HOST" value="postgis"/>
34+
<env name="POSTGRES_PORT" value="5432"/>
35+
<env name="POSTGRES_DATABASE" value="migration"/>
36+
<env name="POSTGRES_USERNAME" value=""/>
37+
<env name="POSTGRES_PASSWORD" value=""/>
38+
39+
<env name="SQLSRV_HOST" value="sqlsrv"/>
40+
<env name="SQLSRV_PORT" value="1433"/>
41+
<env name="SQLSRV_DATABASE" value="migration"/>
42+
<env name="SQLSRV_USERNAME" value=""/>
43+
<env name="SQLSRV_PASSWORD" value=""/>
44+
45+
<env name="MARIADB_HOST" value="mariadb"/>
46+
<env name="MARIADB_PORT" value="3306"/>
47+
<env name="MARIADB_DATABASE" value="migration"/>
48+
<env name="MARIADB_USERNAME" value=""/>
49+
<env name="MARIADB_PASSWORD" value=""/>
50+
51+
<env name="SQLITE_DATABASE" value="./database/migration.sqlite"/>
52+
53+
<env name="MYSQLDUMP_HAS_OPTION_SKIP_COLUMN_STATISTICS" value="false"/>
54+
</php>
2055
</phpunit>

tests/Feature/FeatureTestCase.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace KitLoong\MigrationsGenerator\Tests\Feature;
44

5-
use Dotenv\Dotenv;
6-
use Dotenv\Exception\InvalidPathException;
75
use Illuminate\Database\Migrations\MigrationRepositoryInterface;
86
use Illuminate\Support\Facades\DB;
97
use Illuminate\Support\Facades\File;
@@ -14,20 +12,6 @@ abstract class FeatureTestCase extends TestCase
1412
{
1513
abstract protected function refreshDatabase(): void;
1614

17-
/**
18-
* @inheritDoc
19-
*/
20-
protected function getEnvironmentSetUp($app): void
21-
{
22-
parent::getEnvironmentSetUp($app);
23-
24-
try {
25-
$this->loadDotenv();
26-
} catch (InvalidPathException) {
27-
$this->markTestSkipped('Skipped feature tests.');
28-
}
29-
}
30-
3115
protected function setUp(): void
3216
{
3317
parent::setUp();
@@ -42,26 +26,6 @@ protected function tearDown(): void
4226
parent::tearDown();
4327
}
4428

45-
protected function loadDotenv(): void
46-
{
47-
if (method_exists(Dotenv::class, 'createImmutable')) {
48-
$dotenv = Dotenv::createImmutable(base_path());
49-
$dotenv->load();
50-
return;
51-
}
52-
53-
if (method_exists(Dotenv::class, 'create')) {
54-
/** @noinspection PhpParamsInspection */
55-
$dotenv = Dotenv::create(base_path());
56-
$dotenv->load();
57-
return;
58-
}
59-
60-
/** @noinspection PhpParamsInspection */
61-
$dotenv = new Dotenv(base_path());
62-
$dotenv->load();
63-
}
64-
6529
protected function prepareStoragePath(): void
6630
{
6731
File::deleteDirectory(storage_path());

0 commit comments

Comments
 (0)