mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:34:03 +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:
parent
ba928100e6
commit
747c192979
2 changed files with 20 additions and 2 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue