Skip to content

Commit

Permalink
Fix ArgumentCountError on the TenantAssetsController (archtechx#894)
Browse files Browse the repository at this point in the history
* Fix ArgumentCount exception on the TenantAssetsController when no `$path` is provided

* CS

* CS

* Handle null case explicitly

* code style

Co-authored-by: Bram Wubs <[email protected]>
Co-authored-by: Samuel Štancl <[email protected]>
  • Loading branch information
3 people authored Jul 20, 2022
1 parent ba92810 commit 747c192
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Controllers/TenantAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Stancl\Tenancy\Controllers;

use Illuminate\Routing\Controller;
use Throwable;

class TenantAssetsController extends Controller
{
Expand All @@ -15,11 +16,13 @@ public function __construct()
$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);
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/TenantAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,19 @@ public function asset_helper_tenancy_can_be_disabled()

$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();
}

}

0 comments on commit 747c192

Please sign in to comment.