update project
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Architecture\Concerns;
|
||||
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
trait ScansArchitecture
|
||||
{
|
||||
/** @return string[] */
|
||||
protected function phpFiles(string $relative): array
|
||||
{
|
||||
$root = dirname(__DIR__, 3).'/'.$relative;
|
||||
if (! is_dir($root)) {
|
||||
return [];
|
||||
}
|
||||
$files = [];
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root)) as $file) {
|
||||
if ($file->isFile() && $file->getExtension() === 'php') {
|
||||
$files[] = $file->getPathname();
|
||||
}
|
||||
}
|
||||
sort($files);
|
||||
return $files;
|
||||
}
|
||||
|
||||
protected function assertFilesDoNotContain(string $relative, array $needles, array $excludePathContains = []): void
|
||||
{
|
||||
foreach ($this->phpFiles($relative) as $file) {
|
||||
foreach ($excludePathContains as $exclude) {
|
||||
if (str_contains($file, $exclude)) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
$contents = file_get_contents($file) ?: '';
|
||||
foreach ($needles as $needle) {
|
||||
$this->assertStringNotContainsString($needle, $contents, $file.' contains forbidden pattern: '.$needle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user