|
@@ -28,8 +28,7 @@ final class ComposerFileTest extends TestCase
|
|
|
{
|
|
|
public function testScriptsHaveDescriptions(): void
|
|
|
{
|
|
|
- $composerJsonContent = file_get_contents(__DIR__.'/../../composer.json');
|
|
|
- $composerJson = json_decode($composerJsonContent, true, 512, JSON_THROW_ON_ERROR);
|
|
|
+ $composerJson = self::readComposerJson();
|
|
|
|
|
|
$scripts = array_keys($composerJson['scripts']);
|
|
|
$descriptions = array_keys($composerJson['scripts-descriptions']);
|
|
@@ -37,4 +36,42 @@ final class ComposerFileTest extends TestCase
|
|
|
self::assertSame([], array_diff($scripts, $descriptions), 'There should be no scripts with missing description.');
|
|
|
self::assertSame([], array_diff($descriptions, $scripts), 'There should be no superfluous description for not defined scripts.');
|
|
|
}
|
|
|
+
|
|
|
+ public function testScriptsAliasesDescriptionsFollowThePattern(): void
|
|
|
+ {
|
|
|
+ $composerJson = self::readComposerJson();
|
|
|
+
|
|
|
+ $scripts = array_keys($composerJson['scripts']);
|
|
|
+
|
|
|
+ $aliases = array_reduce($scripts, static function (array $carry, string $script) use ($composerJson): array {
|
|
|
+ $code = $composerJson['scripts'][$script];
|
|
|
+
|
|
|
+ if (\is_string($code) && '@' === $code[0]) {
|
|
|
+ $potentialAlias = substr($code, 1);
|
|
|
+ if (isset($composerJson['scripts'][$potentialAlias])) {
|
|
|
+ $carry[$script] = $potentialAlias;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $carry;
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ foreach ($aliases as $code => $alias) {
|
|
|
+ self::assertSame(
|
|
|
+ "Alias for '{$alias}'",
|
|
|
+ $composerJson['scripts-descriptions'][$code],
|
|
|
+ "Script description for '{$code}' alias should be following the pattern.",
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return array<string, mixed>
|
|
|
+ */
|
|
|
+ private static function readComposerJson(): array
|
|
|
+ {
|
|
|
+ $composerJsonContent = file_get_contents(__DIR__.'/../../composer.json');
|
|
|
+
|
|
|
+ return json_decode($composerJsonContent, true, 512, JSON_THROW_ON_ERROR);
|
|
|
+ }
|
|
|
}
|