Documentation

SetSniffPropertyTest extends TestCase
in package

FinalYes

These tests specifically focus on the changes made to work around the PHP 8.2 dynamic properties deprecation.

Tags
covers

Table of Contents

Methods

dataDirectCallWithOldArrayFormatSetsProperty()  : array<string, array<string, mixed>>
Data provider.
dataSniffPropertiesGetSetWhenAllowed()  : array<string, array<string|int, string>>
Data provider.
testDirectCallWithNewArrayFormatSetsProperty()  : void
Test that setting a property via a direct call to the Ruleset::setSniffProperty() method sets the property correctly when using the new $settings array format.
testDirectCallWithOldArrayFormatSetsProperty()  : void
Test that setting a property via a direct call to the Ruleset::setSniffProperty() method sets the property correctly when using the old $settings array format.
testDirectCallWithOldArrayFormatThrowsDeprecationNotice()  : void
Test that setting a property via a direct call to the Ruleset::setSniffProperty() method throws a deprecation notice when using the old $settings array format.
testSetPropertyAppliesPropertyToMultipleSniffsInCategory()  : void
Test that setting a property for a category will apply it correctly to those sniffs which support the property, but won't apply it to sniffs which don't.
testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCategory()  : void
Test that attempting to set a non-existent property on a sniff when the property directive is for a whole category, does not yield an error.
testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForStandard()  : void
Test that attempting to set a non-existent property on a sniff when the property directive is for the whole standard, does not yield an error.
testSetPropertyThrowsErrorOnInvalidProperty()  : void
Test that attempting to set a non-existent property directly on a sniff will throw an error when the sniff does not explicitly declare the property, extends stdClass or has magic methods.
testSetPropertyThrowsErrorWhenPropertyOnlyAllowedViaAttribute()  : void
Test that attempting to set a non-existent property directly on a sniff will throw an error when the sniff does not explicitly declare the property, extends stdClass or has magic methods, even though the sniff has the PHP 8.2 `#[AllowDynamicProperties]` attribute set.
testSniffPropertiesGetSetWhenAllowed()  : void
Test that setting a property via the ruleset works in all situations which allow for it.

Methods

dataDirectCallWithOldArrayFormatSetsProperty()

Data provider.

public static dataDirectCallWithOldArrayFormatSetsProperty() : array<string, array<string, mixed>>
Tags
see
self::testDirectCallWithOldArrayFormatSetsProperty()
Return values
array<string, array<string, mixed>>

dataSniffPropertiesGetSetWhenAllowed()

Data provider.

public static dataSniffPropertiesGetSetWhenAllowed() : array<string, array<string|int, string>>
Tags
see
self::testSniffPropertiesGetSetWhenAllowed()
Return values
array<string, array<string|int, string>>

testDirectCallWithNewArrayFormatSetsProperty()

Test that setting a property via a direct call to the Ruleset::setSniffProperty() method sets the property correctly when using the new $settings array format.

public testDirectCallWithNewArrayFormatSetsProperty() : void

testDirectCallWithOldArrayFormatSetsProperty()

Test that setting a property via a direct call to the Ruleset::setSniffProperty() method sets the property correctly when using the old $settings array format.

public testDirectCallWithOldArrayFormatSetsProperty(mixed $propertyValue) : void

Tested by silencing the deprecation notice as otherwise the test would fail on the deprecation notice.

Parameters
$propertyValue : mixed

Value for the property to set.

Tags
dataProvider

dataDirectCallWithOldArrayFormatSetsProperty

testDirectCallWithOldArrayFormatThrowsDeprecationNotice()

Test that setting a property via a direct call to the Ruleset::setSniffProperty() method throws a deprecation notice when using the old $settings array format.

public testDirectCallWithOldArrayFormatThrowsDeprecationNotice() : void

Note: as PHPUnit stops as soon as it sees the deprecation notice, the setting of the property value is not tested here.

testSetPropertyAppliesPropertyToMultipleSniffsInCategory()

Test that setting a property for a category will apply it correctly to those sniffs which support the property, but won't apply it to sniffs which don't.

public testSetPropertyAppliesPropertyToMultipleSniffsInCategory() : void

Note: this test intentionally uses the PEAR.Functions category as two sniffs in that category have a public property with the same name (indent) and one sniff doesn't, which makes it a great test case for this.

testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCategory()

Test that attempting to set a non-existent property on a sniff when the property directive is for a whole category, does not yield an error.

public testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCategory() : void
Tags
doesNotPerformAssertions

testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForStandard()

Test that attempting to set a non-existent property on a sniff when the property directive is for the whole standard, does not yield an error.

public testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForStandard() : void
Tags
doesNotPerformAssertions

testSetPropertyThrowsErrorOnInvalidProperty()

Test that attempting to set a non-existent property directly on a sniff will throw an error when the sniff does not explicitly declare the property, extends stdClass or has magic methods.

public testSetPropertyThrowsErrorOnInvalidProperty() : void

testSetPropertyThrowsErrorWhenPropertyOnlyAllowedViaAttribute()

Test that attempting to set a non-existent property directly on a sniff will throw an error when the sniff does not explicitly declare the property, extends stdClass or has magic methods, even though the sniff has the PHP 8.2 `#[AllowDynamicProperties]` attribute set.

public testSetPropertyThrowsErrorWhenPropertyOnlyAllowedViaAttribute() : void

testSniffPropertiesGetSetWhenAllowed()

Test that setting a property via the ruleset works in all situations which allow for it.

public testSniffPropertiesGetSetWhenAllowed(string $name) : void
Parameters
$name : string

Name of the test. Used for the sniff name, the ruleset file name etc.

Tags
dataProvider

dataSniffPropertiesGetSetWhenAllowed


        
On this page

Search results