2045c856e9
- Add 10 core testing guides (setup, AAA principles, PHPUnit/Pest, mocking, anti-patterns, PHP 8.4+, debugging, data factories, advanced edge cases) - Add 13 component testing guides covering all Laravel layers - Add standard templates for PHPUnit 10/11 and Pest v2/v3 including ArchitectureTest - Add Docker smart test runner, dependency installer, and CI/CD templates (GitHub Actions, GitLab CI) - Add 4 Claude Code skills (laravel-test-setup, laravel-unit-test with --all mode, laravel-test-review, laravel-mock-helper) - Add single unified installer script (sg-install-unit-testing.sh) with global support, CLI runners, and 1-click updater (sg-test-update) - Add comprehensive documentation (README.md, USAGE-GUIDE.md) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
|
|
class ArchitectureTest extends TestCase
|
|
{
|
|
#[Test]
|
|
public function no_debugging_statements_exist_in_application(): void
|
|
{
|
|
$appPath = realpath(__DIR__ . '/../../app');
|
|
$this->assertDirectoryExists($appPath);
|
|
|
|
$iterator = new \RecursiveIteratorIterator(
|
|
new \RecursiveDirectoryIterator($appPath, \FilesystemIterator::SKIP_DOTS)
|
|
);
|
|
|
|
$forbiddenPatterns = ['/\bdd\(/', '/\bdump\(/', '/\bvar_dump\(/', '/\bprint_r\(/', '/\bray\(/'];
|
|
$violations = [];
|
|
|
|
/** @var \SplFileInfo $file */
|
|
foreach ($iterator as $file) {
|
|
if ($file->getExtension() !== 'php') {
|
|
continue;
|
|
}
|
|
|
|
$content = file_get_contents($file->getRealPath());
|
|
foreach ($forbiddenPatterns as $pattern) {
|
|
if (preg_match($pattern, $content)) {
|
|
$violations[] = $file->getRelativePathname() . " matches pattern {$pattern}";
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->assertEmpty(
|
|
$violations,
|
|
"Found forbidden debugging statements:\n" . implode("\n", $violations)
|
|
);
|
|
}
|
|
|
|
#[Test]
|
|
public function controllers_must_have_controller_suffix(): void
|
|
{
|
|
$controllersPath = realpath(__DIR__ . '/../../app/Http/Controllers');
|
|
if (!$controllersPath || !is_dir($controllersPath)) {
|
|
$this->markTestSkipped('Controllers directory does not exist.');
|
|
}
|
|
|
|
$iterator = new \RecursiveIteratorIterator(
|
|
new \RecursiveDirectoryIterator($controllersPath, \FilesystemIterator::SKIP_DOTS)
|
|
);
|
|
|
|
$invalidFiles = [];
|
|
/** @var \SplFileInfo $file */
|
|
foreach ($iterator as $file) {
|
|
if ($file->getExtension() !== 'php') {
|
|
continue;
|
|
}
|
|
|
|
$filename = $file->getBasename('.php');
|
|
if (!str_ends_with($filename, 'Controller')) {
|
|
$invalidFiles[] = $file->getRelativePathname();
|
|
}
|
|
}
|
|
|
|
$this->assertEmpty(
|
|
$invalidFiles,
|
|
"Controllers must end with 'Controller':\n" . implode("\n", $invalidFiles)
|
|
);
|
|
}
|
|
}
|