1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 14:34:04 +00:00

Fix ArgumentCountError on the TenantAssetsController (#894)

* Fix ArgumentCount exception on the TenantAssetsController when no `$path` is provided

* CS

* CS

* Handle null case explicitly

* code style

Co-authored-by: Bram Wubs <bram@sibi.nl>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
Bram Wubs 2022-07-20 21:35:33 +02:00 committed by GitHub
parent ba928100e6
commit 747c192979
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Controllers;
use Illuminate\Routing\Controller;
use Throwable;
class TenantAssetsController extends Controller
{
@ -15,11 +16,13 @@ class TenantAssetsController extends Controller
$this->middleware(static::$tenancyMiddleware);
}
public function asset($path)
public function asset($path = null)
{
abort_if($path === null, 404);
try {
return response()->file(storage_path("app/public/$path"));
} catch (\Throwable $th) {
} catch (Throwable $th) {
abort(404);
}
}

View file

@ -126,4 +126,19 @@ class TenantAssetTest extends TestCase
$this->assertSame($original, asset('foo'));
}
public function test_asset_controller_returns_a_404_when_no_path_is_provided()
{
TenantAssetsController::$tenancyMiddleware = InitializeTenancyByRequestData::class;
$tenant = Tenant::create();
tenancy()->initialize($tenant);
$response = $this->get(tenant_asset(null), [
'X-Tenant' => $tenant->id,
]);
$response->assertNotFound();
}
}