diff --git a/tests/Core/Ruleset/Fixtures/PropertyTypeHandlingInline.inc b/tests/Core/Ruleset/Fixtures/PropertyTypeHandlingInline.inc index 4c06f2c497..47bdaddcbe 100644 --- a/tests/Core/Ruleset/Fixtures/PropertyTypeHandlingInline.inc +++ b/tests/Core/Ruleset/Fixtures/PropertyTypeHandlingInline.inc @@ -4,6 +4,7 @@ * Testing handling of properties set inline. */ // phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsString arbitraryvalue +// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsTrimmedString some value // phpcs:set TestStandard.SetProperty.PropertyTypeHandling emptyStringBecomesNull // phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsIntButAcceptsString 12345 @@ -14,8 +15,10 @@ // phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsBooleanTrue true // phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsBooleanTrueCase True +// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsBooleanTrueTrimmed true // phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsBooleanFalse false // phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsBooleanFalseCase fALSe +// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsBooleanFalseTrimmed false // phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithOnlyValues[] string, 10, 1.5, null, true, false // phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,null=>null,true=>true,false=>false diff --git a/tests/Core/Ruleset/Fixtures/TestStandard/Sniffs/SetProperty/PropertyTypeHandlingSniff.php b/tests/Core/Ruleset/Fixtures/TestStandard/Sniffs/SetProperty/PropertyTypeHandlingSniff.php index 8ee815a579..49f50c433d 100644 --- a/tests/Core/Ruleset/Fixtures/TestStandard/Sniffs/SetProperty/PropertyTypeHandlingSniff.php +++ b/tests/Core/Ruleset/Fixtures/TestStandard/Sniffs/SetProperty/PropertyTypeHandlingSniff.php @@ -22,6 +22,15 @@ final class PropertyTypeHandlingSniff implements Sniff */ public $expectsString; + /** + * Used to verify that string properties are set as string, with surrounding whitespace trimmed. + * + * This is the default behaviour. + * + * @var string + */ + public $expectsTrimmedString; + /** * Used to verify that a string value with only whitespace will end up being set as null. * @@ -44,14 +53,14 @@ final class PropertyTypeHandlingSniff implements Sniff public $expectsFloatButAcceptsString; /** - * Used to verify that null gets set as a proper null value. + * Used to verify that null gets set as a string. * * @var null */ public $expectsNull; /** - * Used to verify that null gets set as a proper null value. + * Used to verify that null gets set as a string. * * @var null */ @@ -71,6 +80,13 @@ final class PropertyTypeHandlingSniff implements Sniff */ public $expectsBooleanTrueCase; + /** + * Used to verify that booleans get set as proper boolean values. + * + * @var bool + */ + public $expectsBooleanTrueTrimmed; + /** * Used to verify that booleans get set as proper boolean values. * @@ -85,6 +101,13 @@ final class PropertyTypeHandlingSniff implements Sniff */ public $expectsBooleanFalseCase; + /** + * Used to verify that booleans get set as proper boolean values. + * + * @var bool + */ + public $expectsBooleanFalseTrimmed; + /** * Used to verify that array properties get parsed to a proper array. * diff --git a/tests/Core/Ruleset/PropertyTypeHandlingTest.php b/tests/Core/Ruleset/PropertyTypeHandlingTest.php index ecb82ffd98..a22633ae01 100644 --- a/tests/Core/Ruleset/PropertyTypeHandlingTest.php +++ b/tests/Core/Ruleset/PropertyTypeHandlingTest.php @@ -119,6 +119,10 @@ public static function dataTypeHandling() 'propertyName' => 'expectsString', 'expected' => 'arbitraryvalue', ], + 'String value with whitespace gets trimmed' => [ + 'propertyName' => 'expectsTrimmedString', + 'expected' => 'some value', + ], 'String with whitespace only value becomes null' => [ 'propertyName' => 'emptyStringBecomesNull', 'expected' => null, @@ -147,6 +151,10 @@ public static function dataTypeHandling() 'propertyName' => 'expectsBooleanTrueCase', 'expected' => 'True', ], + 'True (with spaces) value gets set as boolean' => [ + 'propertyName' => 'expectsBooleanTrueTrimmed', + 'expected' => true, + ], 'False value gets set as boolean' => [ 'propertyName' => 'expectsBooleanFalse', 'expected' => false, @@ -155,6 +163,10 @@ public static function dataTypeHandling() 'propertyName' => 'expectsBooleanFalseCase', 'expected' => 'fALSe', ], + 'False (with spaces) value gets set as boolean' => [ + 'propertyName' => 'expectsBooleanFalseTrimmed', + 'expected' => false, + ], 'Array with only values (new style)' => [ 'propertyName' => 'expectsArrayWithOnlyValues', 'expected' => $expectedArrayOnlyValues, diff --git a/tests/Core/Ruleset/PropertyTypeHandlingTest.xml b/tests/Core/Ruleset/PropertyTypeHandlingTest.xml index 612928e0c1..c69b0394ef 100644 --- a/tests/Core/Ruleset/PropertyTypeHandlingTest.xml +++ b/tests/Core/Ruleset/PropertyTypeHandlingTest.xml @@ -4,6 +4,7 @@ + @@ -12,10 +13,13 @@ - + + + +