Skip to content

Commit

Permalink
Enhancement: Assert that the allow-plugins configuration is not sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 29, 2021
1 parent c387938 commit 0587e9d
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions test/Unit/Vendor/Composer/ConfigHashNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,87 @@ public function testNormalizeSortsConfigHashRecursivelyIfPropertyExists(string $
self::assertJsonStringEqualsJsonStringNormalized($expected->encoded(), $normalized->encoded());
}

/**
* @see https://getcomposer.org/doc/06-config.md#allow-plugins
*/
public function testNormalizeDoesNotSortAllowPluginsInConfig(): void
{
$json = Json::fromEncoded(
<<<'JSON'
{
"config": {
"sort-packages": true,
"allow-plugins": {
"foo/*": true,
"bar/*": false,
"*": true
}
}
}
JSON
);

$expected = Json::fromEncoded(
<<<'JSON'
{
"config": {
"allow-plugins": {
"foo/*": true,
"bar/*": false,
"*": true
},
"sort-packages": true
}
}
JSON
);

$normalizer = new Vendor\Composer\ConfigHashNormalizer();

$normalized = $normalizer->normalize($json);

self::assertJsonStringEqualsJsonStringNormalized($expected->encoded(), $normalized->encoded());
}

public function testNormalizeSortsAllowPluginsInOtherProperty(): void
{
$json = Json::fromEncoded(
<<<'JSON'
{
"extra": {
"something": {
"allowed-plugins": {
"foo": true,
"bar": false
}
}
}
}
JSON
);

$expected = Json::fromEncoded(
<<<'JSON'
{
"extra": {
"something": {
"allowed-plugins": {
"bar": false,
"foo": true
}
}
}
}
JSON
);

$normalizer = new Vendor\Composer\ConfigHashNormalizer();

$normalized = $normalizer->normalize($json);

self::assertJsonStringEqualsJsonStringNormalized($expected->encoded(), $normalized->encoded());
}

/**
* @see https://github.com/ergebnis/composer-normalize/issues/644
* @see https://getcomposer.org/doc/06-config.md#preferred-install
Expand Down

0 comments on commit 0587e9d

Please sign in to comment.