diff --git a/tests/MediaTest.php b/tests/MediaTest.php index 4e15180..176e3f4 100644 --- a/tests/MediaTest.php +++ b/tests/MediaTest.php @@ -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'); diff --git a/tests/TestCase.php b/tests/TestCase.php index bbcbf6b..0c0837f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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; @@ -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', [ @@ -51,11 +77,4 @@ protected function getEnvironmentSetUp($app): void 'username' => env('DB_USERNAME', 'forge'), ]); } - - protected function getPackageProviders($app): array - { - return [ - MediaServiceProvider::class - ]; - } } diff --git a/tests/fixtures/MediaTest/bulk_create_changes.json b/tests/fixtures/MediaTest/bulk_create_changes.json index 3d2f96e..7eaee7b 100644 --- a/tests/fixtures/MediaTest/bulk_create_changes.json +++ b/tests/fixtures/MediaTest/bulk_create_changes.json @@ -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, @@ -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, diff --git a/tests/fixtures/MediaTest/create_changes.json b/tests/fixtures/MediaTest/create_changes.json index 09de428..698b5f7 100644 --- a/tests/fixtures/MediaTest/create_changes.json +++ b/tests/fixtures/MediaTest/create_changes.json @@ -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, diff --git a/tests/fixtures/MediaTest/create_public_changes.json b/tests/fixtures/MediaTest/create_public_changes.json index f6de496..b65210b 100644 --- a/tests/fixtures/MediaTest/create_public_changes.json +++ b/tests/fixtures/MediaTest/create_public_changes.json @@ -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, diff --git a/tests/fixtures/MediaTest/uploading_good_files_changes.json b/tests/fixtures/MediaTest/uploading_good_files_changes.json index 09de428..698b5f7 100644 --- a/tests/fixtures/MediaTest/uploading_good_files_changes.json +++ b/tests/fixtures/MediaTest/uploading_good_files_changes.json @@ -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,