Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ All notable changes from version 4.0.0 onward are documented in this file.
example `choices`) can keep a meaningful order instead of an alphabetical one. The containing array is still
checked.

### Changed

- Excluded the superfluous trait name, superfluous abstract class prefix, alphabetical array key order, and function
length checks from `tests/` directories.

## 6.0.0

### Added
Expand Down
9 changes: 8 additions & 1 deletion phpcs.ruleset.84.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
<rule ref="Zend.Files.ClosingTag"/>

<rule ref="PixelFederationCodingStandard.Arrays.AlphabeticallySortedByKeys">
<exclude-pattern>*/tests/*</exclude-pattern>
<properties>
<property name="ignoredParentKeys" type="array">
<element value="choices"/>
Expand Down Expand Up @@ -342,10 +343,15 @@
</rule>
<rule ref="SlevomatCodingStandard.Classes.RequireSelfReference"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousErrorNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousTraitNaming">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
<rule ref="SlevomatCodingStandard.Classes.TraitUseOrder"/>
<rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing">
Expand Down Expand Up @@ -417,6 +423,7 @@
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Functions.FunctionLength">
<exclude-pattern>*/tests/*</exclude-pattern>
<properties>
<property name="maxLinesLength" value="35"/>
</properties>
Expand Down
39 changes: 34 additions & 5 deletions tests/Functional/AlphabeticallySortedByKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ public function testEmptyIgnoredParentKeysPreservesOriginalBehaviour(): void

public function testPackagedRulesetConfiguresIgnoredParentKeys(): void
{
$messages = $this->runSniffWithRuleset(
__DIR__ . '/AlphabeticallySortedByKeys/Arrays.php',
self::getPath('PATH_PHPCS_RULESET'),
1,
);
$path = $this->copyFixtureToTemporaryFile('AlphabeticallySortedByKeys/Arrays.php');

try {
$messages = $this->runSniffWithRuleset(
$path,
self::getPath('PATH_PHPCS_RULESET'),
1,
);
} finally {
if (is_file($path)) {
unlink($path);
}
}

self::assertSame([13, 23, 34], array_column($messages, 'line'));
}
Expand Down Expand Up @@ -90,6 +98,27 @@ public function testLongArraySyntaxIsIgnored(): void
}
}

private function copyFixtureToTemporaryFile(string $fixture): string
{
$temporaryPath = tempnam(sys_get_temp_dir(), 'phpcs-array-');
if ($temporaryPath === false) {
throw new RuntimeException('Could not create temporary PHP file.');
}

$path = $temporaryPath . '.php';
if (!rename($temporaryPath, $path)) {
throw new RuntimeException('Could not create temporary PHP file.');
}

if (!copy(__DIR__ . '/' . $fixture, $path)) {
unlink($path);

throw new RuntimeException('Could not copy fixture to temporary PHP file.');
}

return $path;
}

private function getEscapedKeysSnippet(): string
{
return $this->getBasicEscapesSnippet() . $this->getAdditionalEscapesSnippet();
Expand Down
Loading