Skip to content

Commit

Permalink
fix(tests): fix creasico/laravel-package#47
Browse files Browse the repository at this point in the history
and see creasico/laravel-package#48 for the guide

Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
  • Loading branch information
feryardiant committed Jul 16, 2023
1 parent f05df24 commit 534b903
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: test-reports
path: |
tests/coverage
tests/reports
path: tests/reports

reports:
name: Report Test Coverages
Expand All @@ -183,10 +181,9 @@ jobs:
uses: actions/download-artifact@v3
with:
name: test-reports
path: tests

- name: Report to CodeClimate
run: |
curl -LSs $CC_TEST_REPORTER_URL > ./cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter sum-coverage -o - tests/reports/codeclimate.*.json | ./cc-test-reporter upload-coverage --input -
./cc-test-reporter sum-coverage -o - codeclimate.*.json | ./cc-test-reporter upload-coverage --input -
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory="tests/.phpunit.cache" displayDetailsOnSkippedTests="true" displayDetailsOnIncompleteTests="true" backupStaticProperties="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory="tests/.cache" displayDetailsOnSkippedTests="true" displayDetailsOnIncompleteTests="true" backupStaticProperties="false">
<testsuites>
<testsuite name="Creasi Test Suite">
<directory>tests</directory>
Expand All @@ -8,7 +8,7 @@
<coverage>
<report>
<clover outputFile="tests/reports/clover.xml"/>
<html outputDirectory="tests/coverage"/>
<html outputDirectory="tests/reports/html"/>
</report>
</coverage>
<logging>
Expand Down
22 changes: 16 additions & 6 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,31 @@ protected function getEnvironmentSetUp($app): void
$config->set('app.locale', 'id');
$config->set('app.faker_locale', 'id_ID');

if (env('DB_CONNECTION', 'sqlite')) {
$config->set('database.default', 'sqlite');
$conn = env('DB_CONNECTION', 'sqlite');

$database = __DIR__.'/test.sqlite';
$config->set('database.default', $conn);

if (! file_exists($database)) {
if ($conn === 'sqlite') {
if (! file_exists($database = __DIR__.'/test.sqlite')) {
touch($database);
}

$config->set('database.connections.sqlite', [
'driver' => 'sqlite',
$this->mergeConfig($config, 'database.connections.sqlite', [
'database' => $database,
'foreign_key_constraints' => true,
]);
} else {
$this->mergeConfig($config, 'database.connections.'.$conn, [
'database' => env('DB_DATABASE', 'creasi_test'),
'username' => env('DB_USERNAME', 'creasico'),
'password' => env('DB_PASSWORD', 'secret'),
]);
}
});
}

private function mergeConfig(Repository $config, string $key, array $value)
{
$config->set($key, array_merge($config->get($key, []), $value));
}
}

0 comments on commit 534b903

Please sign in to comment.