forked from fa/breadcrumb-the-shire
fix: eliminate $_SESSION drift in SessionProvider and add notification UI states
Pass AppContainer to SessionProvider::clear() so all module providers use SessionStoreInterface consistently instead of raw $_SESSION. Also add loading and error states to the notification bell dropdown (GR-UI-014). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace MintyPHP\Tests\Unit\Module;
|
||||
|
||||
use MintyPHP\App\AppContainer;
|
||||
use MintyPHP\Http\SessionStore;
|
||||
use MintyPHP\Http\SessionStoreInterface;
|
||||
use MintyPHP\Module\AddressBook\Providers\AddressBookSessionProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -21,13 +23,11 @@ final class SessionProviderTest extends TestCase
|
||||
$_SESSION = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a real AppContainer that returns null for any get() call.
|
||||
* AppContainer is final and cannot be mocked.
|
||||
*/
|
||||
private function emptyContainer(): AppContainer
|
||||
private function containerWithSessionStore(): AppContainer
|
||||
{
|
||||
return new AppContainer();
|
||||
$container = new AppContainer();
|
||||
$container->set(SessionStoreInterface::class, static fn (): SessionStore => new SessionStore());
|
||||
return $container;
|
||||
}
|
||||
|
||||
public function testPopulateWithInvalidUserClearsSessionKey(): void
|
||||
@@ -35,7 +35,7 @@ final class SessionProviderTest extends TestCase
|
||||
$_SESSION['module.addressbook.departments_by_tenant'] = [['tenant' => 'old']];
|
||||
|
||||
$provider = new AddressBookSessionProvider();
|
||||
$provider->populate(['id' => 0], $this->emptyContainer());
|
||||
$provider->populate(['id' => 0], $this->containerWithSessionStore());
|
||||
|
||||
self::assertArrayNotHasKey('module.addressbook.departments_by_tenant', $_SESSION);
|
||||
}
|
||||
@@ -45,22 +45,17 @@ final class SessionProviderTest extends TestCase
|
||||
$_SESSION['module.addressbook.departments_by_tenant'] = [['tenant' => 'old']];
|
||||
|
||||
$provider = new AddressBookSessionProvider();
|
||||
$provider->populate([], $this->emptyContainer());
|
||||
$provider->populate([], $this->containerWithSessionStore());
|
||||
|
||||
self::assertArrayNotHasKey('module.addressbook.departments_by_tenant', $_SESSION);
|
||||
}
|
||||
|
||||
public function testPopulateReturnsEarlyWhenContainerMissesDependencies(): void
|
||||
{
|
||||
$container = $this->containerWithSessionStore();
|
||||
$provider = new AddressBookSessionProvider();
|
||||
// Container has no bindings → get() will throw, but provider guards with instanceof check
|
||||
// The provider should handle this gracefully (no session key set)
|
||||
try {
|
||||
$provider->populate(['id' => 42], $this->emptyContainer());
|
||||
} catch (\Throwable) {
|
||||
// Provider may throw if container has no binding — that's acceptable;
|
||||
// in production, bindings are always registered before providers run.
|
||||
}
|
||||
// Container has SessionStore but no UserTenantContextService → provider returns early
|
||||
$provider->populate(['id' => 42], $container);
|
||||
|
||||
self::assertArrayNotHasKey('module.addressbook.departments_by_tenant', $_SESSION);
|
||||
}
|
||||
@@ -72,7 +67,7 @@ final class SessionProviderTest extends TestCase
|
||||
];
|
||||
|
||||
$provider = new AddressBookSessionProvider();
|
||||
$provider->clear();
|
||||
$provider->clear($this->containerWithSessionStore());
|
||||
|
||||
self::assertArrayNotHasKey('module.addressbook.departments_by_tenant', $_SESSION);
|
||||
}
|
||||
@@ -81,7 +76,7 @@ final class SessionProviderTest extends TestCase
|
||||
{
|
||||
// Key doesn't exist — clear() should not throw
|
||||
$provider = new AddressBookSessionProvider();
|
||||
$provider->clear();
|
||||
$provider->clear($this->containerWithSessionStore());
|
||||
|
||||
self::assertArrayNotHasKey('module.addressbook.departments_by_tenant', $_SESSION);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user