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
3 changes: 3 additions & 0 deletions tests/Core/Ruleset/Fixtures/PropertyTypeHandlingInline.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
*/
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Core/Ruleset/PropertyTypeHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion tests/Core/Ruleset/PropertyTypeHandlingTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<rule ref="./tests/Core/Ruleset/Fixtures/TestStandard/Sniffs/SetProperty/PropertyTypeHandlingSniff.php">
<properties>
<property name="expectsString" value="arbitraryvalue"/>
<property name="expectsTrimmedString" value=" some value "/>
<property name="emptyStringBecomesNull" value=" "/>

<property name="expectsIntButAcceptsString" value="12345"/>
Expand All @@ -12,10 +13,13 @@
<property name="expectsNull" value="null"/>
<property name="expectsNullCase" value="NULL"/>

<property name="expectsBooleanTrue" value="true"/>
<!-- Also tests that property names get cleaned of surrounding whitespace. -->
<property name=" expectsBooleanTrue " value="true"/>
<property name="expectsBooleanTrueCase" value="True"/>
<property name="expectsBooleanTrueTrimmed" value="true "/>
<property name="expectsBooleanFalse" value="false"/>
<property name="expectsBooleanFalseCase" value="fALSe"/>
<property name="expectsBooleanFalseTrimmed" value=" false "/>

<property name="expectsArrayWithOnlyValues" type="array">
<element value="string"/>
Expand Down