1
0
Files
breadcrumb-the-shire/tests/Architecture/ServiceLayerNoHtmlContractTest.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

95 lines
3.1 KiB
PHP

<?php
namespace MintyPHP\Tests\Architecture;
use PHPUnit\Framework\TestCase;
/**
* Service layer (Service, Gateway, Policy) must not contain HTML output.
* HTML rendering belongs in views (.phtml) and templates only.
*
* Excluded: PDF services that legitimately build HTML for Dompdf rendering.
*/
class ServiceLayerNoHtmlContractTest extends TestCase
{
use ProjectFileAssertionSupport;
/** @var list<string> */
private const EXCLUDED_FILES = [
'core/Service/User/UserAccessPdfService.php',
];
/**
* Matches opening HTML tags that indicate rendering logic.
* Ignores comments and string literals containing tag descriptions.
*/
private const HTML_TAG_PATTERN = '/<(?:div|span|table|form|input|button|select|textarea|label|ul|ol|li|h[1-6]|thead|tbody|tr|td|th|section|article|nav|header|footer|main|aside)\b/';
public function testServicesContainNoHtmlTags(): void
{
$violations = $this->findHtmlViolations('core/Service');
$violations = array_merge($violations, $this->findHtmlViolations('core/Http'));
self::assertSame(
[],
$violations,
"Service layer must not contain HTML tags. Violations found:\n" . implode("\n", $violations)
);
}
public function testModuleServicesContainNoHtmlTags(): void
{
$root = $this->projectRootPath();
$modulesDir = $root . '/modules';
if (!is_dir($modulesDir)) {
self::markTestSkipped('modules/ directory missing.');
}
$violations = [];
foreach (scandir($modulesDir) ?: [] as $entry) {
if ($entry === '.' || $entry === '..' || !is_dir($modulesDir . '/' . $entry)) {
continue;
}
$libRel = 'modules/' . $entry . '/lib';
if (is_dir($root . '/' . $libRel)) {
$violations = array_merge($violations, $this->findHtmlViolations($libRel));
}
}
self::assertSame(
[],
$violations,
"Module service layer must not contain HTML tags. Violations found:\n" . implode("\n", $violations)
);
}
/**
* @return list<string>
*/
private function findHtmlViolations(string $relativeDirectory): array
{
$root = $this->projectRootPath();
$basePath = $root . '/' . $relativeDirectory;
if (!is_dir($basePath)) {
return [];
}
$hits = $this->findPatternMatchesInPhpFiles($relativeDirectory, self::HTML_TAG_PATTERN);
return array_values(array_filter(
$hits,
static function (string $path): bool {
// Exclude files that legitimately build HTML (PDF rendering)
foreach (self::EXCLUDED_FILES as $excluded) {
if ($path === $excluded) {
return false;
}
}
// Only flag Service/Gateway/Policy/Factory files, not generic helpers
return (bool) preg_match('/(Service|Gateway|Policy|Factory)\.php$/', $path);
}
));
}
}