1
0
Files
breadcrumb-the-shire/tests/Architecture/AuthzUiContractSupport.php
fs 0e86925464 refactor: rename lib/ to core/ for clearer core-module separation
Rename the top-level lib/ directory to core/ so the project root
immediately communicates which code is core platform and which lives
in modules/. PHP namespaces (MintyPHP\*) are unchanged — only the
Composer PSR-4 path mapping moves from lib/ to core/.

Module-internal lib/ directories (modules/*/lib/) are untouched.

Updated across the full stack:
- composer.json PSR-4 mapping
- bootstrap entry points (web/index.php, bin/*, tests/bootstrap.php)
- tooling configs (phpstan.neon, phpunit.xml, php-cs-fixer)
- 26 architecture contract tests
- enforcement-policy, guard-catalog, quality-gates
- all documentation (CLAUDE.md, README, 25 docs/, .agents/skills/)
- bin/qa-extended.sh search paths
- .claude/settings.local.json permission paths

Workflow: .agents/runs/CORE-LIB-RENAME-001/ (Analyst → Planner →
Executor → Code Review (4 findings fixed) → Security Review →
Acceptance Test → Finalizer)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:20:42 +02:00

135 lines
4.8 KiB
PHP

<?php
namespace MintyPHP\Tests\Architecture;
trait AuthzUiContractSupport
{
/**
* @return array<string, array{0: string, 1: string, 2: string|null}>
*/
public static function adminPageAuthWiringProvider(): array
{
return [
'users index' => [
'pages/admin/users/index(default).phtml',
'pages/admin/users/index().php',
'UiCapabilityMap::PAGE_USERS_INDEX',
],
'users create' => [
'pages/admin/users/create(default).phtml',
'pages/admin/users/create().php',
'UiCapabilityMap::PAGE_USERS_CREATE',
],
'tenants edit' => [
'pages/admin/tenants/edit(default).phtml',
'pages/admin/tenants/edit($id).php',
null,
],
'departments edit' => [
'pages/admin/departments/edit(default).phtml',
'pages/admin/departments/edit($id).php',
null,
],
'stats index' => [
'pages/admin/stats/index(default).phtml',
'pages/admin/stats/index().php',
'UiCapabilityMap::PAGE_STATS_INDEX',
],
'api audit index' => [
'modules/audit/pages/audit/api-audit/index(default).phtml',
'modules/audit/pages/audit/api-audit/index().php',
null,
],
'import audit index' => [
'modules/audit/pages/audit/import-audit/index(default).phtml',
'modules/audit/pages/audit/import-audit/index().php',
null,
],
'scheduled jobs index' => [
'pages/admin/scheduled-jobs/index(default).phtml',
'pages/admin/scheduled-jobs/index().php',
'UiCapabilityMap::PAGE_JOBS_PURGE',
],
'system audit index' => [
'modules/audit/pages/audit/system-audit/index(default).phtml',
'modules/audit/pages/audit/system-audit/index().php',
null,
],
'user lifecycle index' => [
'modules/audit/pages/audit/user-lifecycle-audit/index(default).phtml',
'modules/audit/pages/audit/user-lifecycle-audit/index().php',
null,
],
'user lifecycle view' => [
'modules/audit/pages/audit/user-lifecycle-audit/view(default).phtml',
'modules/audit/pages/audit/user-lifecycle-audit/view($id).php',
null,
],
];
}
/**
* @return list<string>
*/
private function extractPageAuthKeys(string $content): array
{
preg_match_all('/\\$pageAuth\\[[\'"]([a-z_]+)[\'"]\\]/', $content, $matches);
$keys = array_values(array_unique($matches[1]));
sort($keys);
return $keys;
}
/**
* @return list<string>
*/
private function extractViewAuthPageKeys(string $content): array
{
$keys = [];
// Match inline array: $viewAuth['page'] = ['key' => ...];
preg_match_all('/\\$viewAuth\\[\'page\'\\]\\s*=\\s*\\[(.*?)\\];/s', $content, $blocks);
foreach ($blocks[1] as $block) {
preg_match_all('/[\'"]([a-z_]+)[\'"]\\s*=>/', $block, $matches);
foreach ($matches[1] as $key) {
$keys[] = $key;
}
}
// Match pageCapabilities() inline array: ->pageCapabilities(..., ['key' => ...])
if (preg_match('/->pageCapabilities\\([^,]+,\\s*\\[(.*?)\\]\\s*\\)/s', $content, $pcMatch)) {
preg_match_all('/[\'"]([a-z_]+)[\'"]\\s*=>/', $pcMatch[1], $matches);
foreach ($matches[1] as $key) {
$keys[] = $key;
}
}
$keys = array_values(array_unique($keys));
sort($keys);
return $keys;
}
/**
* @return list<string>
*/
private function extractUiCapabilityMapKeys(string $mapConstant): array
{
$parts = explode('::', $mapConstant);
$constantName = trim((string) end($parts));
$this->assertNotSame('', $constantName, 'Invalid UiCapabilityMap constant: ' . $mapConstant);
$mapContent = $this->readProjectFile('core/Service/Access/UiCapabilityMap.php');
$constantPattern = '/public const\\s+' . preg_quote($constantName, '/') . '\\s*=\\s*\\[(.*?)\\];/s';
$matched = preg_match($constantPattern, $mapContent, $constantMatch);
$this->assertSame(
1,
$matched,
'Could not find UiCapabilityMap constant block: ' . $mapConstant
);
preg_match_all('/[\'"]([a-z_]+)[\'"]\\s*=>/', (string) ($constantMatch[1] ?? ''), $keyMatches);
$keys = array_values(array_unique($keyMatches[1]));
sort($keys);
return $keys;
}
}