Skip to content

Commit

Permalink
remove testing specific db connection config #108 (#453)
Browse files Browse the repository at this point in the history
* remove testing specific db connection config #108

* use demo company tenant db for test #108

* change db name + include jwt secret env #108
  • Loading branch information
beesaferoot authored Dec 30, 2024
1 parent 2d65345 commit 686192b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 52 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/test_suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
mariadb:
image: mariadb:10.11
env:
MYSQL_DATABASE: testing_test_company_db
MYSQL_DATABASE: micro_power_manager
MYSQL_ROOT_PASSWORD: wF9zLp2qRxaS2e
ports:
- 3306:3306
Expand Down Expand Up @@ -48,10 +48,10 @@ jobs:
php artisan migrate:fresh --seed
working-directory: ./src/backend
env:
DB_CONNECTION: testing
DB_CONNECTION: micro_power_manager
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_DATABASE: testing_test_company_db
DB_DATABASE: micro_power_manager
DB_USERNAME: root
DB_PASSWORD: wF9zLp2qRxaS2e

Expand All @@ -60,9 +60,10 @@ jobs:
working-directory: ./src/backend
continue-on-error: true
env:
DB_CONNECTION: testing
DB_CONNECTION: micro_power_manager
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_DATABASE: testing_test_company_db
DB_DATABASE: micro_power_manager
DB_USERNAME: root
DB_PASSWORD: wF9zLp2qRxaS2e
JWT_SECRET: YOUR-JWT-SECRET
36 changes: 0 additions & 36 deletions src/backend/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,6 @@
'strict' => false,
'engine' => null,
],

// PHPunit testing main connection
'testing' => [
// 'driver' => 'sqlite',
// 'database' => ':memory:',
// 'prefix' => '',
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'testing_test_company_db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'wF9zLp2qRxaS2e'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],

// PHPunit testing test_db connection
'testing_test_company_db' => [
// 'driver' => 'sqlite',
// 'database' => ':memory:',
// 'prefix' => '',
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'testing_test_company_db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'wF9zLp2qRxaS2e'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
],

/*
Expand Down
2 changes: 1 addition & 1 deletion src/backend/database/factories/AgentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function definition() {
'balance' => 0,
'commission_revenue' => 0,
'due_to_energy_supplier' => 0,
'connection' => 'testing_test_company_db',
'connection' => 'shard',
];
}
}
3 changes: 2 additions & 1 deletion src/backend/database/factories/CompanyDatabaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Database\Factories;

use App\Models\CompanyDatabase;
use App\Utils\DemoCompany;
use Illuminate\Database\Eloquent\Factories\Factory;

class CompanyDatabaseFactory extends Factory {
Expand All @@ -16,7 +17,7 @@ class CompanyDatabaseFactory extends Factory {
public function definition() {
return [
'company_id' => 1,
'database_name' => 'testing_test_company_db',
'database_name' => DemoCompany::DEMO_COMPANY_DATABASE_NAME,
];
}
}
7 changes: 3 additions & 4 deletions src/backend/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
</whitelist>
</filter>
<php>
<env name="sample" value="en"/>
<ini name="memory_limit" value="512M"/>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="TEST_DB_CONNECTION" value="testing_test_company_db"/>
<env name="DB_CONNECTION" value="micro_power_manager" force="true" />
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_PORT" value="3306"/>
<env name="DB_DATABASE" value="testing_test_company_db"/>
<env name="DB_DATABASE" value="micro_power_manager" force="true"/>
<env name="DB_USERNAME" value="root"/>
<env name="DB_PASSWORD" value="wF9zLp2qRxaS2e"/>
</php>
Expand Down
10 changes: 5 additions & 5 deletions src/backend/tests/RefreshMultipleDatabases.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ trait RefreshMultipleDatabases {
protected function refreshInMemoryDatabase() {
Artisan::call(
'migrate:fresh',
['--database' => 'micro_power_manager', '--path' => '/database/migrations/base']
['--database' => 'micro_power_manager', '--path' => '/database/migrations/']
);
Artisan::call(
'migrate:fresh',
['--database' => 'testing_test_company_db', '--path' => '/database/migrations/testing_test_company_db']
'migrate:fresh ',
['--database' => 'shard', '--path' => '/database/migrations/micropowermanager']
);
app(Kernel::class)->setArtisan(null);
$this->app[Kernel::class]->setArtisan(null);
Expand All @@ -27,12 +27,12 @@ protected function refreshTestDatabase() {
if (!RefreshDatabaseState::$migrated) {
Artisan::call(
'migrate:fresh',
['--database' => 'micro_power_manager', '--path' => '/database/migrations/base']
['--database' => 'micro_power_manager', '--path' => '/database/migrations/']
);

Artisan::call(
'migrate:fresh',
['--database' => 'testing_test_company_db', '--path' => '/database/migrations/testing_test_company_db']
['--database' => 'shard', '--path' => '/database/migrations/micropowermanager']
);

app(Kernel::class)->setArtisan(null);
Expand Down

0 comments on commit 686192b

Please sign in to comment.