Files
breadcrumb-the-shire/tests/App/Module/ModuleManifestTest.php

73 lines
2.7 KiB
PHP
Raw Normal View History

<?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');
}
}