diff --git a/src/Controllers/TenantAssetsController.php b/src/Controllers/TenantAssetsController.php index 2d8db007..225231f8 100644 --- a/src/Controllers/TenantAssetsController.php +++ b/src/Controllers/TenantAssetsController.php @@ -14,7 +14,7 @@ class TenantAssetsController extends Controller public function asset($path) { try { - return response()->file(storage_path('app/public/' . $path)); + return response()->file(storage_path("app/public/$path")); } catch (\Throwable $th) { abort(404); } diff --git a/tests/TenantAssetTest.php b/tests/TenantAssetTest.php index 800071a7..985a782e 100644 --- a/tests/TenantAssetTest.php +++ b/tests/TenantAssetTest.php @@ -7,9 +7,19 @@ class TenantAssetTest extends TestCase /** @test */ public function asset_can_be_accessed_using_the_url_returned_by_the_tenant_asset_helper() { - $this->markTestIncomplete(); $filename = 'testfile' . $this->randomString(10); \Storage::disk('public')->put($filename, 'bar'); - $this->get(tenant_asset($filename))->assertSee('bar'); + $path = storage_path("app/public/$filename"); + + // response()->file() returns BinaryFileResponse whose content is + // inaccessible via getContent, so ->assertSee() can't be used + $this->get(tenant_asset($filename))->assertSuccessful(); + $this->assertFileExists($path); + + $f = fopen($path, 'r'); + $content = fread($f, filesize($path)); + fclose($f); + + $this->assertSame('bar', $content); } }