Skip to content

Commit 3af8785

Browse files
authored
Merge pull request #262 from PHPCSStandards/feature/tests-setsniffproperty-various-improvements
Tests/SetSniffPropertyTest: various improvements
2 parents d4c963b + 08a4b8b commit 3af8785

9 files changed

+46
-40
lines changed

tests/Core/Ruleset/Fixtures/Sniffs/Category/SetPropertyAllowedAsDeclaredSniff.php renamed to tests/Core/Ruleset/Fixtures/Sniffs/SetProperty/AllowedAsDeclaredSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* @see \PHP_CodeSniffer\Tests\Core\Ruleset\SetSniffPropertyTest
66
*/
77

8-
namespace Fixtures\Sniffs\Category;
8+
namespace Fixtures\Sniffs\SetProperty;
99

1010
use PHP_CodeSniffer\Files\File;
1111
use PHP_CodeSniffer\Sniffs\Sniff;
1212

13-
class SetPropertyAllowedAsDeclaredSniff implements Sniff
13+
class AllowedAsDeclaredSniff implements Sniff
1414
{
1515

1616
public $arbitrarystring;

tests/Core/Ruleset/Fixtures/Sniffs/Category/SetPropertyAllowedViaMagicMethodSniff.php renamed to tests/Core/Ruleset/Fixtures/Sniffs/SetProperty/AllowedViaMagicMethodSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* @see \PHP_CodeSniffer\Tests\Core\Ruleset\SetSniffPropertyTest
66
*/
77

8-
namespace Fixtures\Sniffs\Category;
8+
namespace Fixtures\Sniffs\SetProperty;
99

1010
use PHP_CodeSniffer\Files\File;
1111
use PHP_CodeSniffer\Sniffs\Sniff;
1212

13-
class SetPropertyAllowedViaMagicMethodSniff implements Sniff
13+
class AllowedViaMagicMethodSniff implements Sniff
1414
{
1515
private $magic = [];
1616

tests/Core/Ruleset/Fixtures/Sniffs/Category/SetPropertyAllowedViaStdClassSniff.php renamed to tests/Core/Ruleset/Fixtures/Sniffs/SetProperty/AllowedViaStdClassSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* @see \PHP_CodeSniffer\Tests\Core\Ruleset\SetSniffPropertyTest
66
*/
77

8-
namespace Fixtures\Sniffs\Category;
8+
namespace Fixtures\Sniffs\SetProperty;
99

1010
use PHP_CodeSniffer\Files\File;
1111
use PHP_CodeSniffer\Sniffs\Sniff;
1212
use stdClass;
1313

14-
class SetPropertyAllowedViaStdClassSniff extends stdClass implements Sniff
14+
class AllowedViaStdClassSniff extends stdClass implements Sniff
1515
{
1616

1717
public function register()

tests/Core/Ruleset/Fixtures/Sniffs/Category/SetPropertyNotAllowedViaAttributeSniff.php renamed to tests/Core/Ruleset/Fixtures/Sniffs/SetProperty/NotAllowedViaAttributeSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
* @see \PHP_CodeSniffer\Tests\Core\Ruleset\SetSniffPropertyTest
66
*/
77

8-
namespace Fixtures\Sniffs\Category;
8+
namespace Fixtures\Sniffs\SetProperty;
99

1010
use AllowDynamicProperties;
1111
use PHP_CodeSniffer\Files\File;
1212
use PHP_CodeSniffer\Sniffs\Sniff;
1313

1414
#[AllowDynamicProperties]
15-
class SetPropertyNotAllowedViaAttributeSniff implements Sniff
15+
class NotAllowedViaAttributeSniff implements Sniff
1616
{
1717

1818
public function register()

tests/Core/Ruleset/SetPropertyAllowedAsDeclaredTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Fixtures" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
33

4-
<rule ref="./tests/Core/Ruleset/Fixtures/Sniffs/Category/SetPropertyAllowedAsDeclaredSniff.php">
4+
<rule ref="./tests/Core/Ruleset/Fixtures/Sniffs/SetProperty/AllowedAsDeclaredSniff.php">
55
<properties>
66
<property name="arbitrarystring" value="arbitraryvalue"/>
77
<property name="arbitraryarray" type="array">

tests/Core/Ruleset/SetPropertyAllowedViaMagicMethodTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Fixtures" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
33

4-
<rule ref="./tests/Core/Ruleset/Fixtures/Sniffs/Category/SetPropertyAllowedViaMagicMethodSniff.php">
4+
<rule ref="./tests/Core/Ruleset/Fixtures/Sniffs/SetProperty/AllowedViaMagicMethodSniff.php">
55
<properties>
66
<property name="arbitrarystring" value="arbitraryvalue"/>
77
<property name="arbitraryarray" type="array">

tests/Core/Ruleset/SetPropertyAllowedViaStdClassTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Fixtures" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
33

4-
<rule ref="./tests/Core/Ruleset/Fixtures/Sniffs/Category/SetPropertyAllowedViaStdClassSniff.php">
4+
<rule ref="./tests/Core/Ruleset/Fixtures/Sniffs/SetProperty/AllowedViaStdClassSniff.php">
55
<properties>
66
<property name="arbitrarystring" value="arbitraryvalue"/>
77
<property name="arbitraryarray" type="array">

tests/Core/Ruleset/SetPropertyNotAllowedViaAttributeTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Fixtures" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
33

4-
<rule ref="./tests/Core/Ruleset/Fixtures/Sniffs/Category/SetPropertyNotAllowedViaAttributeSniff.php">
4+
<rule ref="./tests/Core/Ruleset/Fixtures/Sniffs/SetProperty/NotAllowedViaAttributeSniff.php">
55
<properties>
66
<property name="arbitrarystring" value="arbitraryvalue"/>
77
</properties>

tests/Core/Ruleset/SetSniffPropertyTest.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ final class SetSniffPropertyTest extends TestCase
3434
*/
3535
public function testSniffPropertiesGetSetWhenAllowed($name)
3636
{
37-
$sniffCode = "Fixtures.Category.{$name}";
38-
$sniffClass = 'Fixtures\Sniffs\Category\\'.$name.'Sniff';
37+
$sniffCode = "Fixtures.SetProperty.{$name}";
38+
$sniffClass = 'Fixtures\Sniffs\SetProperty\\'.$name.'Sniff';
3939
$properties = [
4040
'arbitrarystring' => 'arbitraryvalue',
4141
'arbitraryarray' => [
@@ -45,7 +45,7 @@ public function testSniffPropertiesGetSetWhenAllowed($name)
4545
];
4646

4747
// Set up the ruleset.
48-
$standard = __DIR__."/{$name}Test.xml";
48+
$standard = __DIR__."/SetProperty{$name}Test.xml";
4949
$config = new Config(["--standard=$standard"]);
5050
$ruleset = new Ruleset($config);
5151

@@ -72,14 +72,14 @@ public function testSniffPropertiesGetSetWhenAllowed($name)
7272
*
7373
* @see self::testSniffPropertiesGetSetWhenAllowed()
7474
*
75-
* @return array
75+
* @return array<string, array<string>>
7676
*/
7777
public static function dataSniffPropertiesGetSetWhenAllowed()
7878
{
7979
return [
80-
'Property allowed as explicitly declared' => ['SetPropertyAllowedAsDeclared'],
81-
'Property allowed as sniff extends stdClass' => ['SetPropertyAllowedViaStdClass'],
82-
'Property allowed as sniff has magic __set() method' => ['SetPropertyAllowedViaMagicMethod'],
80+
'Property allowed as explicitly declared' => ['AllowedAsDeclared'],
81+
'Property allowed as sniff extends stdClass' => ['AllowedViaStdClass'],
82+
'Property allowed as sniff has magic __set() method' => ['AllowedViaMagicMethod'],
8383
];
8484

8585
}//end dataSniffPropertiesGetSetWhenAllowed()
@@ -163,7 +163,7 @@ public function testSetPropertyThrowsErrorOnInvalidProperty()
163163
public function testSetPropertyThrowsErrorWhenPropertyOnlyAllowedViaAttribute()
164164
{
165165
$exceptionClass = 'PHP_CodeSniffer\Exceptions\RuntimeException';
166-
$exceptionMsg = 'Ruleset invalid. Property "arbitrarystring" does not exist on sniff Fixtures.Category.SetPropertyNotAllowedViaAttribute';
166+
$exceptionMsg = 'Ruleset invalid. Property "arbitrarystring" does not exist on sniff Fixtures.SetProperty.NotAllowedViaAttribute';
167167
if (method_exists($this, 'expectException') === true) {
168168
$this->expectException($exceptionClass);
169169
$this->expectExceptionMessage($exceptionMsg);
@@ -224,12 +224,12 @@ public function testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCateg
224224
*/
225225
public function testDirectCallWithNewArrayFormatSetsProperty()
226226
{
227-
$name = 'SetPropertyAllowedAsDeclared';
228-
$sniffCode = "Fixtures.Category.{$name}";
229-
$sniffClass = 'Fixtures\Sniffs\Category\\'.$name.'Sniff';
227+
$name = 'AllowedAsDeclared';
228+
$sniffCode = "Fixtures.SetProperty.{$name}";
229+
$sniffClass = 'Fixtures\Sniffs\SetProperty\\'.$name.'Sniff';
230230

231231
// Set up the ruleset.
232-
$standard = __DIR__."/{$name}Test.xml";
232+
$standard = __DIR__."/SetProperty{$name}Test.xml";
233233
$config = new Config(["--standard=$standard"]);
234234
$ruleset = new Ruleset($config);
235235

@@ -275,12 +275,12 @@ public function testDirectCallWithNewArrayFormatSetsProperty()
275275
*/
276276
public function testDirectCallWithOldArrayFormatSetsProperty($propertyValue)
277277
{
278-
$name = 'SetPropertyAllowedAsDeclared';
279-
$sniffCode = "Fixtures.Category.{$name}";
280-
$sniffClass = 'Fixtures\Sniffs\Category\\'.$name.'Sniff';
278+
$name = 'AllowedAsDeclared';
279+
$sniffCode = "Fixtures.SetProperty.{$name}";
280+
$sniffClass = 'Fixtures\Sniffs\SetProperty\\'.$name.'Sniff';
281281

282282
// Set up the ruleset.
283-
$standard = __DIR__."/{$name}Test.xml";
283+
$standard = __DIR__."/SetProperty{$name}Test.xml";
284284
$config = new Config(["--standard=$standard"]);
285285
$ruleset = new Ruleset($config);
286286

@@ -313,34 +313,40 @@ public function testDirectCallWithOldArrayFormatSetsProperty($propertyValue)
313313
*
314314
* @see self::testDirectCallWithOldArrayFormatSetsProperty()
315315
*
316-
* @return array
316+
* @return array<string, array<string, mixed>>
317317
*/
318318
public static function dataDirectCallWithOldArrayFormatSetsProperty()
319319
{
320320
return [
321-
'Property value is not an array (boolean)' => [false],
322-
'Property value is not an array (string)' => ['a string'],
323-
'Property value is an empty array' => [[]],
321+
'Property value is not an array (boolean)' => [
322+
'propertyValue' => false,
323+
],
324+
'Property value is not an array (string)' => [
325+
'propertyValue' => 'a string',
326+
],
327+
'Property value is an empty array' => [
328+
'propertyValue' => [],
329+
],
324330
'Property value is an array without keys' => [
325-
[
331+
'propertyValue' => [
326332
'value',
327333
false,
328334
],
329335
],
330336
'Property value is an array without the "scope" or "value" keys' => [
331-
[
337+
'propertyValue' => [
332338
'key1' => 'value',
333339
'key2' => false,
334340
],
335341
],
336342
'Property value is an array without the "scope" key' => [
337-
[
343+
'propertyValue' => [
338344
'key1' => 'value',
339345
'value' => true,
340346
],
341347
],
342348
'Property value is an array without the "value" key' => [
343-
[
349+
'propertyValue' => [
344350
'scope' => 'value',
345351
'key2' => 1234,
346352
],
@@ -376,12 +382,12 @@ public function testDirectCallWithOldArrayFormatThrowsDeprecationNotice()
376382
$this->setExpectedException($exceptionClass, $exceptionMsg);
377383
}
378384

379-
$name = 'SetPropertyAllowedAsDeclared';
380-
$sniffCode = "Fixtures.Category.{$name}";
381-
$sniffClass = 'Fixtures\Sniffs\Category\\'.$name.'Sniff';
385+
$name = 'AllowedAsDeclared';
386+
$sniffCode = "Fixtures.SetProperty.{$name}";
387+
$sniffClass = 'Fixtures\Sniffs\SetProperty\\'.$name.'Sniff';
382388

383389
// Set up the ruleset.
384-
$standard = __DIR__."/{$name}Test.xml";
390+
$standard = __DIR__."/SetProperty{$name}Test.xml";
385391
$config = new Config(["--standard=$standard"]);
386392
$ruleset = new Ruleset($config);
387393

0 commit comments

Comments
 (0)