Files
breadcrumb-the-shire/tests/Architecture/ConfigContractsTest.php
fs 0c78dc4355 chore(setup): track config.php directly, slim README to setup checklist
config/config.php was gitignored and devs had to copy it from
config/config.php.example on every fresh clone. Since the bootstrap
config reads everything from .env via $envString() / $envInt() /
$envBool() defaults, there is nothing developer-specific in the file —
the cp step was dead ceremony.

- Remove config/config.php from .gitignore and track it directly
- Delete config/config.php.example
- Drop the example-existence + per-doc reference checks from
  bin/docs-drift-check.sh; add a legacy-pattern check that flags
  any new mention of the removed example file
- Update ConfigContractsTest to require config.php and forbid the
  example
- Clean stale references in CLAUDE.md, README.md, six docs files,
  and the core-guardrails skill

Same commit slims README down from 294 to 47 lines: one setup
checklist (now 3 commands instead of 4), the seeded login table,
the three quality-gate commands, and pointers to CLAUDE.md and
docs/index.md for everything else.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 08:37:45 +02:00

108 lines
3.2 KiB
PHP

<?php
namespace MintyPHP\Tests\Architecture;
use PHPUnit\Framework\TestCase;
final class ConfigContractsTest extends TestCase
{
use ProjectFileAssertionSupport;
public function testConfigDirectoryContainsOnlyDeclarativeConfigFiles(): void
{
$required = [
'config/assets.php',
'config/routes.php',
'config/modules.php',
'config/config.php',
];
foreach ($required as $file) {
$this->assertFileExists($this->projectRootPath() . '/' . $file, 'Missing required config file: ' . $file);
}
$forbidden = [
'config/router.php',
'config/settings.php',
'config/config.php.example',
];
foreach ($forbidden as $file) {
$this->assertFileDoesNotExist($this->projectRootPath() . '/' . $file, 'Forbidden runtime config file exists: ' . $file);
}
}
public function testConfigDoesNotDefineLegacyRouteConstants(): void
{
$content = $this->readProjectFile('config/config.php');
$this->assertStringNotContainsString('APP_ROUTE_DEFINITIONS', $content);
$this->assertStringNotContainsString('APP_PUBLIC_PATHS', $content);
}
public function testRuntimePathsDoNotReferenceLegacyRouteConstants(): void
{
$runtimeFiles = $this->runtimeSourceFiles();
$patterns = [
'/\bAPP_ROUTE_DEFINITIONS\b/' => 'APP_ROUTE_DEFINITIONS',
'/\bAPP_PUBLIC_PATHS\b/' => 'APP_PUBLIC_PATHS',
];
$violations = [];
foreach ($runtimeFiles as $relativePath) {
$content = $this->readProjectFile($relativePath);
foreach ($patterns as $regex => $label) {
if (preg_match($regex, $content)) {
$violations[] = $relativePath . ': ' . $label;
}
}
}
$violations = array_values(array_unique($violations));
sort($violations);
$this->assertSame(
[],
$violations,
"Legacy route constants referenced in runtime paths:\n" . implode("\n", $violations)
);
}
/**
* @return list<string>
*/
private function runtimeSourceFiles(): array
{
$root = $this->projectRootPath();
$scanTargets = ['core', 'pages', 'templates', 'web'];
$extensions = ['php', 'phtml', 'js'];
$files = [];
foreach ($scanTargets as $target) {
$fullPath = $root . '/' . $target;
if (!is_dir($fullPath)) {
continue;
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($fullPath, \FilesystemIterator::SKIP_DOTS)
);
foreach ($iterator as $file) {
if (!$file->isFile()) {
continue;
}
$extension = strtolower((string) $file->getExtension());
if (!in_array($extension, $extensions, true)) {
continue;
}
$files[] = str_replace($root . '/', '', $file->getPathname());
}
}
$files = array_values(array_unique($files));
sort($files);
return $files;
}
}