mirror of
https://github.com/opdavies/build-configs.git
synced 2025-02-15 10:40:46 +00:00
71 lines
1.7 KiB
PHP
Executable file
71 lines
1.7 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Finder\Finder;
|
|
|
|
/**
|
|
* @group snapshots
|
|
*/
|
|
class SnapshotTest extends TestCase
|
|
{
|
|
/**
|
|
* @var array<int, string>
|
|
*/
|
|
private static $configs = [
|
|
'drupal',
|
|
'drupal-commerce-kickstart',
|
|
'drupal-localgov',
|
|
];
|
|
|
|
public function testCompareFiles(): void
|
|
{
|
|
foreach (self::$configs as $config) {
|
|
$baseDir = getcwd() . "/tests/snapshots/output/{$config}";
|
|
$generatedDir = getcwd() . "/.ignored/snapshots/output/{$config}";
|
|
|
|
$this->runCliTool($config);
|
|
|
|
$baseFiles = $this->getFiles($baseDir);
|
|
|
|
foreach ($baseFiles as $file) {
|
|
$this->assertFileEquals(
|
|
expected: $baseDir . '/' . $file,
|
|
actual: $generatedDir . '/' . $file,
|
|
message: "Files do not match: {$file}",
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function runCliTool(string $config): void
|
|
{
|
|
$cliCommand = sprintf(
|
|
"%s app:generate --config-file %s --output-dir %s",
|
|
getcwd() . '/bin/build-configs',
|
|
getcwd() . "/tests/snapshots/configs/{$config}.yaml",
|
|
getcwd() . "/.ignored/snapshots/output/{$config}",
|
|
);
|
|
|
|
exec($cliCommand);
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
private function getFiles(string $directory): array
|
|
{
|
|
$files = [];
|
|
|
|
$finder = new Finder();
|
|
$finder->in($directory)->files();
|
|
|
|
foreach ($finder as $file) {
|
|
$files[] = $file->getRelativePathname();
|
|
}
|
|
|
|
return $files;
|
|
}
|
|
}
|