Split detail page contracts

This commit is contained in:
2026-03-19 19:04:28 +01:00
parent f6046c9168
commit 522705dd33
21 changed files with 729 additions and 121 deletions

View File

@@ -0,0 +1,22 @@
<?php
namespace MintyPHP\Tests\Architecture;
final class DetailPageContractFiles
{
/**
* @return list<string>
*/
public static function standardDetailFormFiles(): array
{
return [
'pages/admin/users/_form.phtml',
'pages/admin/tenants/_form.phtml',
'pages/admin/departments/_form.phtml',
'pages/admin/roles/_form.phtml',
'pages/admin/permissions/_form.phtml',
'pages/admin/scheduled-jobs/edit(default).phtml',
'pages/admin/settings/index(default).phtml',
];
}
}

View File

@@ -1,59 +0,0 @@
<?php
namespace MintyPHP\Tests\Architecture;
use PHPUnit\Framework\TestCase;
class DetailPageContractTest extends TestCase
{
use ProjectFileAssertionSupport;
/**
* @return list<string>
*/
private function standardDetailFormFiles(): array
{
return [
'pages/admin/users/_form.phtml',
'pages/admin/tenants/_form.phtml',
'pages/admin/departments/_form.phtml',
'pages/admin/roles/_form.phtml',
'pages/admin/permissions/_form.phtml',
'pages/admin/scheduled-jobs/edit(default).phtml',
'pages/admin/settings/index(default).phtml',
];
}
public function testScopedDetailFormsUseStandardDetailOptInAttribute(): void
{
foreach ($this->standardDetailFormFiles() as $file) {
$content = $this->readProjectFile($file);
$this->assertStringContainsString('data-standard-detail-form="1"', $content, $file);
}
}
public function testAppInitIncludesStandardDetailPageAutoInitComponent(): void
{
$content = $this->readProjectFile('web/js/app-init.js');
$this->assertStringContainsString("import { initStandardDetailPages } from './components/app-standard-detail-page.js';", $content);
$this->assertStringContainsString("runtime.register('standard-detail-page', initStandardDetailPages", $content);
}
public function testDetailsTitlebarExposesUnsavedMessageAndPrimarySaveMarkers(): void
{
$content = $this->readProjectFile('templates/partials/app-details-titlebar.phtml');
$this->assertStringContainsString('data-detail-unsaved-message=', $content);
$this->assertStringContainsString('data-detail-action-policy="1"', $content);
$this->assertStringContainsString('data-detail-action-kind=', $content);
$this->assertStringContainsString('data-detail-save-primary="1"', $content);
}
public function testImportsWizardFormsUseStandardDetailOptIn(): void
{
$content = $this->readProjectFile('pages/admin/imports/index(default).phtml');
$this->assertStringContainsString('id="imports-upload-form"', $content);
$this->assertStringContainsString('id="imports-mapping-form"', $content);
$this->assertStringContainsString('id="imports-commit-form"', $content);
$this->assertSame(3, substr_count($content, 'data-standard-detail-form="1"'));
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace MintyPHP\Tests\Architecture;
use PHPUnit\Framework\TestCase;
final class DetailPageFormContractTest extends TestCase
{
use ProjectFileAssertionSupport;
public function testScopedDetailFormsUseStandardDetailOptInAttribute(): void
{
foreach (DetailPageContractFiles::standardDetailFormFiles() as $file) {
$content = $this->readProjectFile($file);
$this->assertStringContainsString('data-standard-detail-form="1"', $content, $file);
}
}
public function testImportsWizardFormsUseStandardDetailOptIn(): void
{
$content = $this->readProjectFile('pages/admin/imports/index(default).phtml');
$this->assertStringContainsString('id="imports-upload-form"', $content);
$this->assertStringContainsString('id="imports-mapping-form"', $content);
$this->assertStringContainsString('id="imports-commit-form"', $content);
$this->assertSame(3, substr_count($content, 'data-standard-detail-form="1"'));
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace MintyPHP\Tests\Architecture;
use PHPUnit\Framework\TestCase;
final class DetailPageRuntimeContractTest extends TestCase
{
use ProjectFileAssertionSupport;
public function testAppInitIncludesStandardDetailPageAutoInitComponent(): void
{
$content = $this->readProjectFile('web/js/app-init.js');
$this->assertStringContainsString(
"import { initStandardDetailPages } from './components/app-standard-detail-page.js';",
$content
);
$this->assertStringContainsString("runtime.register('standard-detail-page', initStandardDetailPages", $content);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace MintyPHP\Tests\Architecture;
use PHPUnit\Framework\TestCase;
final class DetailPageTitlebarContractTest extends TestCase
{
use ProjectFileAssertionSupport;
public function testDetailsTitlebarExposesUnsavedMessageAndPrimarySaveMarkers(): void
{
$content = $this->readProjectFile('templates/partials/app-details-titlebar.phtml');
$this->assertStringContainsString('data-detail-unsaved-message=', $content);
$this->assertStringContainsString('data-detail-save-primary="1"', $content);
}
}

View File

@@ -0,0 +1,125 @@
<?php
namespace MintyPHP\Tests\Console;
use MintyPHP\Console\Command;
use MintyPHP\Console\ConsoleApplication;
use PHPUnit\Framework\TestCase;
final class ConsoleApplicationTest extends TestCase
{
public function testListReturnsZero(): void
{
$app = new ConsoleApplication();
$app->register(new DummyCommand());
$exitCode = $app->run(['bin/console', 'list']);
self::assertSame(0, $exitCode);
}
public function testEmptyArgvShowsListAndReturnsZero(): void
{
$app = new ConsoleApplication();
$exitCode = $app->run(['bin/console']);
self::assertSame(0, $exitCode);
}
public function testUnknownCommandReturnsOne(): void
{
$app = new ConsoleApplication();
$exitCode = $app->run(['bin/console', 'nonexistent']);
self::assertSame(1, $exitCode);
}
public function testDispatchesRegisteredCommand(): void
{
$command = new DummyCommand();
$app = new ConsoleApplication();
$app->register($command);
$exitCode = $app->run(['bin/console', 'test:dummy', 'arg1', '--flag', '--key=value']);
self::assertSame(0, $exitCode);
self::assertSame(['arg1'], $command->lastArgs);
self::assertSame(['flag' => true, 'key' => 'value'], $command->lastOptions);
}
public function testCommandExitCodePropagates(): void
{
$app = new ConsoleApplication();
$app->register(new FailingCommand());
$exitCode = $app->run(['bin/console', 'test:fail']);
self::assertSame(42, $exitCode);
}
public function testMultiplePositionalArgs(): void
{
$command = new DummyCommand();
$app = new ConsoleApplication();
$app->register($command);
$app->run(['bin/console', 'test:dummy', 'first', 'second', 'third']);
self::assertSame(['first', 'second', 'third'], $command->lastArgs);
}
public function testOptionWithEqualsSign(): void
{
$command = new DummyCommand();
$app = new ConsoleApplication();
$app->register($command);
$app->run(['bin/console', 'test:dummy', '--module=addressbook']);
self::assertSame([], $command->lastArgs);
self::assertSame(['module' => 'addressbook'], $command->lastOptions);
}
}
final class DummyCommand extends Command
{
public array $lastArgs = [];
public array $lastOptions = [];
public function name(): string
{
return 'test:dummy';
}
public function description(): string
{
return 'A dummy command';
}
public function execute(array $args, array $options): int
{
$this->lastArgs = $args;
$this->lastOptions = $options;
return 0;
}
}
final class FailingCommand extends Command
{
public function name(): string
{
return 'test:fail';
}
public function description(): string
{
return 'Always fails';
}
public function execute(array $args, array $options): int
{
return 42;
}
}

View File

@@ -35,4 +35,4 @@ ohne dass jede Aenderung immer die komplette Suite im Kopf behalten muss.
- `tests/Architecture/ContainerFactoryContractTest.php`
- `tests/Architecture/SecurityLoggingContractTest.php`
- `tests/Architecture/StatusTaxonomyContractTest.php`
- `tests/Architecture/DetailPageContractTest.php`
- `tests/Architecture/AuthHelpLinksContractTest.php`