Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 441f7ce

Browse files
committed
test: add support for multiple ruleset; add trailing semicolon fixture
1 parent 34475d8 commit 441f7ce

31 files changed

+85
-47
lines changed

‎tests/bootstrap.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
die('Please install via Composer before running tests.');
3636
}
3737

38-
putenv("SNIFFS_PATH={$libDir}/Inpsyde/Sniffs");
38+
putenv("LIB_PATH={$libDir}");
3939
putenv('SNIFFS_NAMESPACE=Inpsyde\\Sniffs');
4040
putenv("FIXTURES_PATH={$testsDir}/fixtures");
4141

‎tests/cases/FixturesTest.php‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,36 @@ private function createPhpcsForFixture(
209209
array $properties
210210
): File {
211211

212-
$sniffFile = str_replace('.', '/', "{$sniffName}Sniff");
213-
$sniffPath = getenv('SNIFFS_PATH') . "/{$sniffFile}.php";
212+
$sniffFile = $this->buildSniffFile($sniffName);
213+
$sniffPath = getenv('LIB_PATH') . "/{$sniffFile}.php";
214214
if (!file_exists($sniffPath) || !is_readable($sniffPath)) {
215215
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
216216
throw new Exception("Non-existent of unreadable sniff file '{$sniffPath}' found.");
217217
}
218218

219+
$standard = strtok($sniffName, '.');
219220
$config = new Config();
220-
$config->standards = [dirname(getenv('SNIFFS_PATH'))];
221-
$config->sniffs = ["Inpsyde.{$sniffName}"];
221+
$config->standards = [getenv('LIB_PATH') . "/{$standard}"];
222+
$config->sniffs = [$sniffName];
222223
$ruleset = new Ruleset($config);
223224

224-
$baseSniffNamespace = getenv('SNIFFS_NAMESPACE');
225225
$sniffFqn = str_replace('/', '\\', $sniffFile);
226226
foreach ($properties as $name => $value) {
227-
$ruleset->setSniffProperty("{$baseSniffNamespace}\\{$sniffFqn}", $name, $value);
227+
$ruleset->setSniffProperty(
228+
$sniffFqn,
229+
$name,
230+
['scope' => 'sniff', 'value' => $value],
231+
);
228232
}
229233

230234
return new LocalFile($fixtureFile, $ruleset, $config);
231235
}
236+
237+
private function buildSniffFile(string $sniffName): string
238+
{
239+
$parts = explode('.', $sniffName);
240+
array_splice($parts, 1, 0, 'Sniffs');
241+
242+
return implode('/', $parts) . 'Sniff';
243+
}
232244
}

‎tests/fixtures/Psr4Fixture.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php # -*- coding: utf-8 -*-
2-
// @phpcsSniff CodeQuality.Psr4
2+
// @phpcsSniff Inpsyde.CodeQuality.Psr4
33

44
namespace {
55

‎tests/fixtures/argument-type-declaration.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
// @phpcsSniff CodeQuality.ArgumentTypeDeclaration
2+
// @phpcsSniff Inpsyde.CodeQuality.ArgumentTypeDeclaration
33

44
use Psr\Container as PsrContainer;
55

‎tests/fixtures/disable-call-user-func.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
// @phpcsSniff CodeQuality.DisableCallUserFunc
2+
// @phpcsSniff Inpsyde.CodeQuality.DisableCallUserFunc
33

44
function test() {
55
// @phpcsErrorOnNextLine

‎tests/fixtures/disallow-magic-serialize.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
// @phpcsSniff CodeQuality.DisableMagicSerialize
3+
// @phpcsSniff Inpsyde.CodeQuality.DisableMagicSerialize
44

55
class Foo {
66

‎tests/fixtures/disallow-short-open-tag.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function (string $sniff, array $messages, array $warnings, array $errors, array
1313
}
1414
// @phpcsProcessFixtureEnd
1515

16-
// @phpcsSniff CodeQuality.DisallowShortOpenTag
16+
// @phpcsSniff Inpsyde.CodeQuality.DisallowShortOpenTag
1717
?>
1818
<div>
1919
<?= strtolower($x) ?>

‎tests/fixtures/element-name-minimal-length.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
// @phpcsSniff CodeQuality.ElementNameMinimalLength
2+
// @phpcsSniff Inpsyde.CodeQuality.ElementNameMinimalLength
33

44
namespace {
55

‎tests/fixtures/encoding-comment.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Inpsyde\CodingStandard\Tests\Fixtures;
44

55

6-
// @phpcsSniff CodeQuality.EncodingComment
6+
// @phpcsSniff Inpsyde.CodeQuality.EncodingComment
77

88
// @phpcsWarningCodeOnNextLine EncodingComment
99
// -*- coding: utf-8 -*-
@@ -15,4 +15,4 @@
1515

1616
<?php //-*- coding: utf-8 -*-
1717
// @phpcsWarningOnPreviousLine CodeQuality.EncodingComment
18-
?>
18+
?>

‎tests/fixtures/forbidden-public-property.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
// @phpcsSniff CodeQuality.ForbiddenPublicProperty
2+
// @phpcsSniff Inpsyde.CodeQuality.ForbiddenPublicProperty
33

44
$foo = 'foo';
55

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /