1
0
Files
breadcrumb-the-shire/tests/App/Module/ModuleManifestTest.php
fs c364e2b46d feat: introduce module system and extract address book as first module (MODULAR-MONOLITH-V1-001)
Add a module kernel (ModuleManifest, ModuleRegistry) that allows modules to
contribute routes, UI slots, search providers, layout context, session
lifecycle, and permissions. Modules are activated via config/modules.php or
APP_ENABLED_MODULES env variable. Conflicts (duplicate routes, permissions,
slot keys) cause a fail-fast with a clear error message.

Extract the address book from hardcoded Core integration points into the
first module (modules/addressbook/). The module provides:
- Aside icon-bar tab + People panel via UI slot system
- Global search resource via AddressBookSearchProvider
- Layout context data via AddressBookLayoutProvider
- Session lifecycle via AddressBookSessionProvider

Core cleanup removes address-book hardcodings from SearchSqlResourceProvider,
SearchUiMetaProvider, SearchItemMapperProvider, appBuildLayoutNavContext(),
and the aside templates. Permissions (ADDRESS_BOOK_VIEW) and business logic
(AddressBookService) remain in Core as they gate general user visibility.

Includes 38 new tests (894 total), PHPStan level 5 clean, and architecture
tests verifying zero hardcoded address-book references in search/templates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 15:43:25 +01:00

73 lines
2.7 KiB
PHP

<?php
namespace MintyPHP\Tests\App\Module;
use InvalidArgumentException;
use MintyPHP\App\Module\ModuleManifest;
use PHPUnit\Framework\TestCase;
final class ModuleManifestTest extends TestCase
{
public function testMinimalManifest(): void
{
$manifest = ModuleManifest::fromArray(['id' => 'testmod'], '/tmp/modules/testmod');
self::assertSame('testmod', $manifest->id);
self::assertSame('0.0.0', $manifest->version);
self::assertFalse($manifest->enabledByDefault);
self::assertSame(100, $manifest->loadOrder);
self::assertSame([], $manifest->routes);
self::assertSame([], $manifest->permissions);
self::assertSame([], $manifest->searchResources);
self::assertNull($manifest->migrationsPath);
}
public function testFullManifest(): void
{
$raw = [
'id' => 'addressbook',
'version' => '1.0.0',
'enabled_by_default' => true,
'load_order' => 10,
'routes' => [['path' => '/address-book', 'target' => 'address-book/index']],
'public_paths' => [],
'container_registrars' => ['App\\Registrar'],
'ui_slots' => ['aside.tab_panel' => [['key' => 'people', 'label' => 'People']]],
'search_resources' => ['App\\SearchProvider'],
'asset_groups' => ['address-book' => ['css/view.css']],
'scheduler_jobs' => [],
'layout_context_providers' => ['App\\LayoutProvider'],
'session_providers' => ['App\\SessionProvider'],
'permissions' => ['address_book.view'],
'migrations_path' => 'db/updates',
];
$manifest = ModuleManifest::fromArray($raw, '/srv/modules/addressbook');
self::assertSame('addressbook', $manifest->id);
self::assertSame('1.0.0', $manifest->version);
self::assertTrue($manifest->enabledByDefault);
self::assertSame(10, $manifest->loadOrder);
self::assertCount(1, $manifest->routes);
self::assertSame(['address_book.view'], $manifest->permissions);
self::assertSame('/srv/modules/addressbook/db/updates', $manifest->migrationsPath);
self::assertSame(['App\\LayoutProvider'], $manifest->layoutContextProviders);
self::assertSame(['App\\SessionProvider'], $manifest->sessionProviders);
}
public function testMissingIdThrows(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('non-empty string "id"');
ModuleManifest::fromArray([], '/tmp/modules/broken');
}
public function testEmptyIdThrows(): void
{
$this->expectException(InvalidArgumentException::class);
ModuleManifest::fromArray(['id' => ' '], '/tmp/modules/broken');
}
}