Skip to content

Commit 033caca

Browse files
committed
More tests for weird parameters or properties definitions
1 parent 928e07e commit 033caca

11 files changed

+86
-1
lines changed

tests/Helpers/FunctionHelperTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public function dataParametersNames(): array
7171
'someParametersWithNullableTypeHints',
7272
['$string', '$int', '$bool', '$float', '$callable', '$array', '$object'],
7373
],
74+
[
75+
'parametersWithWeirdDefinition',
76+
['$string', '$int', '$bool', '$float', '$callable', '$array', '$object'],
77+
],
7478
];
7579
}
7680

@@ -147,6 +151,23 @@ public function dataParametersTypeHints(): array
147151
'$array',
148152
],
149153
],
154+
[
155+
'parametersWithWeirdDefinition',
156+
[
157+
'$string' => new ParameterTypeHint('string', false, false),
158+
'$int' => null,
159+
'$bool' => new ParameterTypeHint('bool', false, true),
160+
'$float' => null,
161+
'$callable' => new ParameterTypeHint('callable', false, false),
162+
'$array' => null,
163+
'$object' => new ParameterTypeHint('\FooNamespace\FooClass', false, false),
164+
],
165+
[
166+
'$int',
167+
'$float',
168+
'$array',
169+
],
170+
],
150171
];
151172
}
152173

@@ -180,6 +201,18 @@ public function dataParametersNullableTypeHints(): array
180201
'$object' => new ParameterTypeHint('\FooNamespace\FooClass', true, false),
181202
],
182203
],
204+
[
205+
'parametersWithWeirdDefinition',
206+
[
207+
'$string' => new ParameterTypeHint('string', true, false),
208+
'$int' => new ParameterTypeHint('int', false, false),
209+
'$bool' => new ParameterTypeHint('bool', true, true),
210+
'$float' => new ParameterTypeHint('float', false, false),
211+
'$callable' => new ParameterTypeHint('callable', true, false),
212+
'$array' => new ParameterTypeHint('array', false, true),
213+
'$object' => new ParameterTypeHint('\FooNamespace\FooClass', true, false),
214+
],
215+
],
183216
];
184217
}
185218

tests/Helpers/PropertyHelperTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function dataIsProperty(): array
3030
'$hoo',
3131
false,
3232
],
33+
[
34+
'$weirdDefinition',
35+
true,
36+
],
3337
];
3438
}
3539

tests/Helpers/data/functionParametersNames.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ public function allParametersWithNullableTypeHints(?string $string, ?int $int =
2424

2525
abstract public function someParametersWithNullableTypeHints(?string $string, int $int, ?bool $bool = true, float $float, ?callable $callable, array $array = [], ?\FooNamespace\FooClass $object);
2626

27+
abstract public function parametersWithWeirdDefinition(?string$string,int$int,?bool$bool=true,float$float,?callable$callable,array$array=[],?\FooNamespace\FooClass$object);
28+
2729
}

tests/Helpers/data/functionParametersNullableTypeHints.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ public function allParametersWithNullableTypeHints(?string $string, ?int $int =
1212

1313
abstract public function someParametersWithNullableTypeHints(?string $string, int $int, ?bool $bool = true, float $float, ?callable $callable, array $array = [], ?\FooNamespace\FooClass $object);
1414

15+
abstract public function parametersWithWeirdDefinition(?string$string,int$int,?bool$bool=true,float$float,?callable$callable,array$array=[],?\FooNamespace\FooClass$object);
16+
1517
}

tests/Helpers/data/functionParametersTypeHints.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ final public function allParametersWithoutTypeHints($string = '', $int, $bool, $
1717

1818
abstract public function someParametersWithoutTypeHints(string $string, $int, bool $bool = true, $float, callable $callable, $array = [], \FooNamespace\FooClass $object);
1919

20+
abstract public function parametersWithWeirdDefinition(string$string,$int,bool$bool=true,$float,callable$callable,$array=[],\FooNamespace\FooClass$object);
21+
2022
}

tests/Helpers/data/propertyOrNot.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ public function __construct($boo)
1515
$hoo = $boo;
1616
}
1717

18+
private$weirdDefinition;
19+
1820
}

tests/Sniffs/Classes/UnusedPrivateElementsSniffTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ public function testErrors()
7171
UnusedPrivateElementsSniff::CODE_UNUSED_METHOD,
7272
'Class ClassWithSomeUnusedProperties contains unused private method unusedMethodReturningReference().'
7373
);
74+
75+
$this->assertSniffError(
76+
$resultFile,
77+
101,
78+
UnusedPrivateElementsSniff::CODE_UNUSED_PROPERTY,
79+
'Class ClassWithSomeUnusedProperties contains unused property $unusedPropertyWithWeirdDefinition.'
80+
);
81+
$this->assertSniffError(
82+
$resultFile,
83+
103,
84+
UnusedPrivateElementsSniff::CODE_WRITE_ONLY_PROPERTY,
85+
'Class ClassWithSomeUnusedProperties contains write-only property $unusedWriteOnlyPropertyWithWeirdDefinition.'
86+
);
7487
}
7588

7689
public function testOnlyPublicElements()

tests/Sniffs/Classes/data/classWithSomeUnusedElements.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,13 @@ private function &unusedMethodReturningReference()
9898
return [];
9999
}
100100

101+
private$unusedPropertyWithWeirdDefinition;
102+
103+
private$unusedWriteOnlyPropertyWithWeirdDefinition;
104+
105+
public function unusedWriteOnlyPropertyWithWeirdDefinitionMethod()
106+
{
107+
$this->unusedWriteOnlyPropertyWithWeirdDefinition = null;
108+
}
109+
101110
}

tests/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniffTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testErrors()
1818
'enabled' => true,
1919
]);
2020

21-
$this->assertSame(11, $report->getErrorCount());
21+
$this->assertSame(12, $report->getErrorCount());
2222

2323
$code = NullableTypeForNullDefaultValueSniff::CODE_NULLABILITY_SYMBOL_REQUIRED;
2424
$this->assertSniffError($report, 3, $code);
@@ -32,6 +32,7 @@ public function testErrors()
3232
$this->assertSniffError($report, 47, $code);
3333
$this->assertSniffError($report, 52, $code);
3434
$this->assertSniffError($report, 57, $code);
35+
$this->assertSniffError($report, 62, $code);
3536
}
3637

3738
public function testFixable()

tests/Sniffs/TypeHints/data/nullableTypeForNullDefaultValueErrors.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public function reference(float & $ref = null)
5959

6060
}
6161

62+
public function weirdDefinition(float&$ref=null)
63+
{
64+
65+
}
66+
6267
}

0 commit comments

Comments
 (0)