Skip to content

Commit

Permalink
#18: Added inclusion of .env files in tests.
Browse files Browse the repository at this point in the history
Also corrected fixtures so that tests would pass.
  • Loading branch information
ulin-evgeny committed Jun 2, 2024
1 parent 3d99bce commit 5dbf83b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testBulkCreate(): void

public function testDelete(): void
{
$filePath = 'Photo';
$filePath = 'preview_Photo';
Storage::put($filePath, 'content');

$response = $this->actingAs(self::$user)->json('delete', '/media/4');
Expand Down
33 changes: 26 additions & 7 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace RonasIT\Media\Tests;

use Carbon\Carbon;
use Dotenv\Dotenv;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
use Orchestra\Testbench\TestCase as BaseTest;
use RonasIT\Media\MediaServiceProvider;
use RonasIT\Support\Traits\FixturesTrait;
Expand Down Expand Up @@ -42,6 +44,30 @@ public function getFixturePath(string $fixtureName): string
}

protected function getEnvironmentSetUp($app): void
{
$this->includeEnv();

$this->setupDb($app);
}

protected function getPackageProviders($app): array
{
return [
MediaServiceProvider::class,
];
}

protected function includeEnv(): void
{
$pathToEnv = str_replace('/vendor/orchestra/testbench-core/laravel', '', base_path());
$name = env('APP_ENV') ? '.env.' . env('APP_ENV') : null;
if (File::exists("{$pathToEnv}/{$name}")) {
$dotenv = Dotenv::createImmutable($pathToEnv, $name);
$dotenv->load();
}
}

protected function setupDb($app): void
{
$app['config']->set('database.default', env('DB_DEFAULT', 'pgsql'));
$app['config']->set('database.connections.pgsql', [
Expand All @@ -51,11 +77,4 @@ protected function getEnvironmentSetUp($app): void
'username' => env('DB_USERNAME', 'forge'),
]);
}

protected function getPackageProviders($app): array
{
return [
MediaServiceProvider::class
];
}
}
4 changes: 2 additions & 2 deletions tests/fixtures/MediaTest/bulk_create_changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"created_at": "2024-01-01 00:00:00",
"updated_at": "2024-01-01 00:00:00",
"deleted_at": null,
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/app\/preview_file1.png",
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/framework\/testing\/disks\/local\/preview_file1.png",
"name": "preview_file1.png",
"is_public": false,
"owner_id": 2,
Expand All @@ -32,7 +32,7 @@
"created_at": "2024-01-01 00:00:00",
"updated_at": "2024-01-01 00:00:00",
"deleted_at": null,
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/app\/preview_file2.png",
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/framework\/testing\/disks\/local\/preview_file2.png",
"name": "preview_file2.png",
"is_public": false,
"owner_id": 2,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/MediaTest/create_changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"created_at": "2024-01-01 00:00:00",
"updated_at": "2024-01-01 00:00:00",
"deleted_at": null,
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/app\/preview_file.png",
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/framework\/testing\/disks\/local\/preview_file.png",
"name": "preview_file.png",
"is_public": false,
"owner_id": 2,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/MediaTest/create_public_changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"created_at": "2024-01-01 00:00:00",
"updated_at": "2024-01-01 00:00:00",
"deleted_at": null,
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/app\/preview_file.png",
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/framework\/testing\/disks\/local\/preview_file.png",
"name": "preview_file.png",
"is_public": false,
"owner_id": 2,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/MediaTest/uploading_good_files_changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"created_at": "2024-01-01 00:00:00",
"updated_at": "2024-01-01 00:00:00",
"deleted_at": null,
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/app\/preview_file.png",
"link": "\/app\/vendor\/orchestra\/testbench-core\/laravel\/storage\/framework\/testing\/disks\/local\/preview_file.png",
"name": "preview_file.png",
"is_public": false,
"owner_id": 2,
Expand Down

0 comments on commit 5dbf83b

Please sign in to comment.