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

[4.x] Route cloning refactor (#1353)

* Refactor cloning action, update tests

* Delete redundant "should not be cloned" part from shouldBeCloned()

* Use 'clone' instead of a universal route in tenant parameter removal test

* Improve comment

* Add test for cloneRoutesWithMiddleware(), correct existing tests

* Allow cloning specific routes by name

* Fix typo in CloneActionTest

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* clean up CloneRoutesAsTenant, add a todo

* phpstan

* Add test for handling 'clone'  in MW groups

* Improve regression test

* Improve regression test

* Handle nested cloning flags in CloneRoutesAsTenant

* Ignore routes that are already considered tenant routes from cloning, update test accordingly

* Clarify cloning logic

* CloneRoutesAsTenant cleanup

* Rewrite clone action annotation, fix fluent usage bug

* Improve tests (comments, use $tenant->id instead of $tenant->getTenantKey())

* Test that the clone action can be used fluently without issues now (could serve as a regression test for the routesToClone change in previous commit)

* Minor annotation improvements

* Improve route cloning action docblock

* Add note about clearing the $routesToClone property

* improve docblock

* clean up tests

* fix typo

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
lukinovec 2025-07-01 00:32:42 +02:00 committed by GitHub
parent 7e1fe075f4
commit 1e926a1dde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 362 additions and 351 deletions

View file

@ -344,9 +344,9 @@ test('the tenant parameter is only removed from tenant routes when using path id
->middleware('tenant')
->name('tenant-route');
RouteFacade::get($pathIdentification ? '/universal-route' : '/universal-route/{tenant?}', [ControllerWithMiddleware::class, 'routeHasTenantParameter'])
->middleware('universal')
->name('universal-route');
RouteFacade::get($pathIdentification ? '/cloned-route' : '/cloned-route/{tenant?}', [ControllerWithMiddleware::class, 'routeHasTenantParameter'])
->middleware('clone')
->name('cloned-route');
/** @var CloneRoutesAsTenant */
$cloneRoutesAction = app(CloneRoutesAsTenant::class);
@ -364,8 +364,8 @@ test('the tenant parameter is only removed from tenant routes when using path id
$response = pest()->get($tenantKey . '/tenant-route')->assertOk();
expect((bool) $response->getContent())->toBeFalse();
// The tenant parameter gets removed from the cloned universal route
$response = pest()->get($tenantKey . '/universal-route')->assertOk();
// The tenant parameter gets removed from the cloned route
$response = pest()->get($tenantKey . '/cloned-route')->assertOk();
expect((bool) $response->getContent())->toBeFalse();
} else {
// Tenant parameter is not removed from tenant routes using other kernel identification MW
@ -374,12 +374,12 @@ test('the tenant parameter is only removed from tenant routes when using path id
$response = pest()->get("http://{$domain}/{$tenantKey}/tenant-route")->assertOk();
expect((bool) $response->getContent())->toBeTrue();
// The tenant parameter does not get removed from the universal route when accessing it through the central domain
$response = pest()->get("http://localhost/universal-route/$tenantKey")->assertOk();
// The tenant parameter does not get removed from the cloned route when accessing it through the central domain
$response = pest()->get("http://localhost/cloned-route/$tenantKey")->assertOk();
expect((bool) $response->getContent())->toBeTrue();
// The tenant parameter gets removed from the universal route when accessing it through the tenant domain
$response = pest()->get("http://{$domain}/universal-route")->assertOk();
// The tenant parameter gets removed from the cloned route when accessing it through the tenant domain
$response = pest()->get("http://{$domain}/cloned-route")->assertOk();
expect((bool) $response->getContent())->toBeFalse();
}
} else {