Skip to content

Commit d9fd1f2

Browse files
Use typed properties in tests as much as possible
1 parent 38e6f7f commit d9fd1f2

File tree

63 files changed

+176
-559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+176
-559
lines changed

Test/FormIntegrationTestCase.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
*/
2121
abstract class FormIntegrationTestCase extends TestCase
2222
{
23-
/**
24-
* @var FormFactoryInterface
25-
*/
26-
protected $factory;
23+
protected FormFactoryInterface $factory;
2724

2825
protected function setUp(): void
2926
{

Tests/AbstractRequestHandlerTestCase.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,16 @@
2929
*/
3030
abstract class AbstractRequestHandlerTestCase extends TestCase
3131
{
32-
/**
33-
* @var RequestHandlerInterface
34-
*/
35-
protected $requestHandler;
36-
37-
/**
38-
* @var FormFactory
39-
*/
40-
protected $factory;
41-
32+
protected RequestHandlerInterface $requestHandler;
33+
protected FormFactory $factory;
4234
protected $request;
43-
44-
protected $serverParams;
35+
protected ServerParams $serverParams;
4536

4637
protected function setUp(): void
4738
{
4839
$this->serverParams = new class() extends ServerParams {
49-
public $contentLength;
50-
public $postMaxSize = '';
40+
public ?int $contentLength = null;
41+
public string $postMaxSize = '';
5142

5243
public function getContentLength(): ?int
5344
{

Tests/ChoiceList/AbstractChoiceListTestCase.php

Lines changed: 17 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -19,90 +19,23 @@
1919
*/
2020
abstract class AbstractChoiceListTestCase extends TestCase
2121
{
22-
/**
23-
* @var ChoiceListInterface
24-
*/
25-
protected $list;
26-
27-
/**
28-
* @var array
29-
*/
30-
protected $choices;
31-
32-
/**
33-
* @var array
34-
*/
35-
protected $values;
36-
37-
/**
38-
* @var array
39-
*/
40-
protected $structuredValues;
41-
42-
/**
43-
* @var array
44-
*/
45-
protected $keys;
46-
47-
/**
48-
* @var mixed
49-
*/
50-
protected $choice1;
51-
52-
/**
53-
* @var mixed
54-
*/
55-
protected $choice2;
56-
57-
/**
58-
* @var mixed
59-
*/
60-
protected $choice3;
61-
62-
/**
63-
* @var mixed
64-
*/
65-
protected $choice4;
66-
67-
/**
68-
* @var string
69-
*/
70-
protected $value1;
71-
72-
/**
73-
* @var string
74-
*/
75-
protected $value2;
76-
77-
/**
78-
* @var string
79-
*/
80-
protected $value3;
81-
82-
/**
83-
* @var string
84-
*/
85-
protected $value4;
86-
87-
/**
88-
* @var string
89-
*/
90-
protected $key1;
91-
92-
/**
93-
* @var string
94-
*/
95-
protected $key2;
96-
97-
/**
98-
* @var string
99-
*/
100-
protected $key3;
101-
102-
/**
103-
* @var string
104-
*/
105-
protected $key4;
22+
protected ChoiceListInterface $list;
23+
protected array $choices;
24+
protected array $values;
25+
protected array $structuredValues;
26+
protected array $keys;
27+
protected mixed $choice1;
28+
protected mixed $choice2;
29+
protected mixed $choice3;
30+
protected mixed $choice4;
31+
protected string $value1;
32+
protected string $value2;
33+
protected string $value3;
34+
protected string $value4;
35+
protected string $key1;
36+
protected string $key2;
37+
protected string $key3;
38+
protected string $key4;
10639

10740
protected function setUp(): void
10841
{

Tests/ChoiceList/ArrayChoiceListTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class ArrayChoiceListTest extends AbstractChoiceListTestCase
2121
{
22-
private $object;
22+
private \stdClass $object;
2323

2424
protected function setUp(): void
2525
{

Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
*/
2929
class CachingFactoryDecoratorTest extends TestCase
3030
{
31-
/**
32-
* @var CachingFactoryDecorator
33-
*/
34-
private $factory;
31+
private CachingFactoryDecorator $factory;
3532

3633
protected function setUp(): void
3734
{

Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,12 @@
2727

2828
class DefaultChoiceListFactoryTest extends TestCase
2929
{
30-
private $obj1;
31-
32-
private $obj2;
33-
34-
private $obj3;
35-
36-
private $obj4;
37-
38-
private $obj5;
39-
40-
private $obj6;
41-
42-
private $list;
43-
44-
/**
45-
* @var DefaultChoiceListFactory
46-
*/
47-
private $factory;
30+
private \stdClass $obj1;
31+
private \stdClass $obj2;
32+
private \stdClass $obj3;
33+
private \stdClass $obj4;
34+
private ArrayChoiceList $list;
35+
private DefaultChoiceListFactory $factory;
4836

4937
public function getValue($object)
5038
{
@@ -208,9 +196,9 @@ public function testCreateFromChoicesGroupedValuesAsClosure()
208196
public function testCreateFromFilteredChoices()
209197
{
210198
$list = $this->factory->createListFromChoices(
211-
['A' => $this->obj1, 'B' => $this->obj2, 'C' => $this->obj3, 'D' => $this->obj4, 'E' => $this->obj5, 'F' => $this->obj6],
199+
['A' => $this->obj1, 'B' => $this->obj2, 'C' => $this->obj3, 'D' => $this->obj4, 'E' => null, 'F' => null],
212200
null,
213-
fn ($choice) => $choice !== $this->obj5 && $choice !== $this->obj6
201+
fn ($choice) => null !== $choice
214202
);
215203

216204
$this->assertObjectListWithGeneratedValues($list);
@@ -222,11 +210,11 @@ public function testCreateFromChoicesGroupedAndFiltered()
222210
[
223211
'Group 1' => ['A' => $this->obj1, 'B' => $this->obj2],
224212
'Group 2' => ['C' => $this->obj3, 'D' => $this->obj4],
225-
'Group 3' => ['E' => $this->obj5, 'F' => $this->obj6],
213+
'Group 3' => ['E' => null, 'F' => null],
226214
'Group 4' => [/* empty group should be filtered */],
227215
],
228216
null,
229-
fn ($choice) => $choice !== $this->obj5 && $choice !== $this->obj6
217+
fn ($choice) => null !== $choice
230218
);
231219

232220
$this->assertObjectListWithGeneratedValues($list);
@@ -238,11 +226,11 @@ public function testCreateFromChoicesGroupedAndFilteredTraversable()
238226
new \ArrayIterator([
239227
'Group 1' => ['A' => $this->obj1, 'B' => $this->obj2],
240228
'Group 2' => ['C' => $this->obj3, 'D' => $this->obj4],
241-
'Group 3' => ['E' => $this->obj5, 'F' => $this->obj6],
229+
'Group 3' => ['E' => null, 'F' => null],
242230
'Group 4' => [/* empty group should be filtered */],
243231
]),
244232
null,
245-
fn ($choice) => $choice !== $this->obj5 && $choice !== $this->obj6
233+
fn ($choice) => null !== $choice
246234
);
247235

248236
$this->assertObjectListWithGeneratedValues($list);
@@ -1026,7 +1014,7 @@ private function assertGroupedViewWithChoiceDuplication($view)
10261014

10271015
class DefaultChoiceListFactoryTest_Castable
10281016
{
1029-
private $property;
1017+
private string $property;
10301018

10311019
public function __construct($property)
10321020
{

Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
*/
2626
class PropertyAccessDecoratorTest extends TestCase
2727
{
28-
/**
29-
* @var PropertyAccessDecorator
30-
*/
31-
private $factory;
28+
private PropertyAccessDecorator $factory;
3229

3330
protected function setUp(): void
3431
{

Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,11 @@
2121
*/
2222
class CallbackChoiceLoaderTest extends TestCase
2323
{
24-
/**
25-
* @var \Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader
26-
*/
27-
private static $loader;
28-
29-
/**
30-
* @var callable
31-
*/
32-
private static $value;
33-
34-
/**
35-
* @var array
36-
*/
37-
private static $choices;
38-
39-
/**
40-
* @var string[]
41-
*/
42-
private static $choiceValues;
43-
44-
/**
45-
* @var \Symfony\Component\Form\ChoiceList\LazyChoiceList
46-
*/
47-
private static $lazyChoiceList;
24+
private static CallbackChoiceLoader $loader;
25+
private static \Closure $value;
26+
private static array $choices;
27+
private static array $choiceValues = ['choice_one', 'choice_two'];
28+
private static LazyChoiceList $lazyChoiceList;
4829

4930
public static function setUpBeforeClass(): void
5031
{
@@ -54,7 +35,6 @@ public static function setUpBeforeClass(): void
5435
(object) ['value' => 'choice_one'],
5536
(object) ['value' => 'choice_two'],
5637
];
57-
self::$choiceValues = ['choice_one', 'choice_two'];
5838
self::$lazyChoiceList = new LazyChoiceList(self::$loader, self::$value);
5939
}
6040

@@ -106,13 +86,4 @@ public function testLoadValuesForChoicesLoadsChoiceListOnFirstCall()
10686
'Choice list should not be reloaded.'
10787
);
10888
}
109-
110-
public static function tearDownAfterClass(): void
111-
{
112-
self::$loader = null;
113-
self::$value = null;
114-
self::$choices = [];
115-
self::$choiceValues = [];
116-
self::$lazyChoiceList = null;
117-
}
11889
}

Tests/ChoiceList/Loader/IntlCallbackChoiceLoaderTest.php

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,11 @@
2222
*/
2323
class IntlCallbackChoiceLoaderTest extends TestCase
2424
{
25-
/**
26-
* @var \Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader
27-
*/
28-
private static $loader;
29-
30-
/**
31-
* @var callable
32-
*/
33-
private static $value;
34-
35-
/**
36-
* @var array
37-
*/
38-
private static $choices;
39-
40-
/**
41-
* @var string[]
42-
*/
43-
private static $choiceValues;
44-
45-
/**
46-
* @var \Symfony\Component\Form\ChoiceList\LazyChoiceList
47-
*/
48-
private static $lazyChoiceList;
25+
private static IntlCallbackChoiceLoader $loader;
26+
private static \Closure $value;
27+
private static array $choices;
28+
private static array $choiceValues = ['choice_one', 'choice_two'];
29+
private static LazyChoiceList $lazyChoiceList;
4930

5031
public static function setUpBeforeClass(): void
5132
{
@@ -55,7 +36,6 @@ public static function setUpBeforeClass(): void
5536
(object) ['value' => 'choice_one'],
5637
(object) ['value' => 'choice_two'],
5738
];
58-
self::$choiceValues = ['choice_one', 'choice_two'];
5939
self::$lazyChoiceList = new LazyChoiceList(self::$loader, self::$value);
6040
}
6141

@@ -101,13 +81,4 @@ public function testLoadValuesForChoicesLoadsChoiceListOnFirstCall()
10181
'Choice list should not be reloaded.'
10282
);
10383
}
104-
105-
public static function tearDownAfterClass(): void
106-
{
107-
self::$loader = null;
108-
self::$value = null;
109-
self::$choices = [];
110-
self::$choiceValues = [];
111-
self::$lazyChoiceList = null;
112-
}
11384
}

0 commit comments

Comments
 (0)