Skip to content

Commit 43afd1e

Browse files
Use typed properties in tests as much as possible
1 parent a4db9f8 commit 43afd1e

21 files changed

+48
-168
lines changed

Tests/File/FakeFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class FakeFile extends OrigFile
1717
{
18-
private $realpath;
18+
private string $realpath;
1919

2020
public function __construct(string $realpath, string $path)
2121
{

Tests/File/FileTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
*/
2121
class FileTest extends TestCase
2222
{
23-
protected $file;
24-
2523
public function testGetMimeTypeUsesMimeTypeGuessers()
2624
{
2725
$file = new File(__DIR__.'/Fixtures/test.gif');

Tests/Fixtures/response-functional/deleted_cookie.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@
3434
$listener = new SessionListener($container);
3535

3636
$kernel = new class($r) implements HttpKernelInterface {
37-
/**
38-
* @var Response
39-
*/
40-
private $response;
37+
private Response $response;
4138

4239
public function __construct(Response $response)
4340
{

Tests/RateLimiter/MockAbstractRequestRateLimiter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MockAbstractRequestRateLimiter extends AbstractRequestRateLimiter
2020
/**
2121
* @var LimiterInterface[]
2222
*/
23-
private $limiters;
23+
private array $limiters;
2424

2525
public function __construct(array $limiters)
2626
{

Tests/Session/Attribute/AttributeBagTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
*/
2222
class AttributeBagTest extends TestCase
2323
{
24-
private $array = [];
24+
private array $array = [];
2525

26-
/**
27-
* @var AttributeBag
28-
*/
29-
private $bag;
26+
private ?AttributeBag $bag = null;
3027

3128
protected function setUp(): void
3229
{

Tests/Session/Flash/AutoExpireFlashBagTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
*/
2222
class AutoExpireFlashBagTest extends TestCase
2323
{
24-
/**
25-
* @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
26-
*/
27-
private $bag;
24+
protected array $array = [];
2825

29-
protected $array = [];
26+
private FlashBag $bag;
3027

3128
protected function setUp(): void
3229
{
@@ -38,7 +35,7 @@ protected function setUp(): void
3835

3936
protected function tearDown(): void
4037
{
41-
$this->bag = null;
38+
unset($this->bag);
4239
parent::tearDown();
4340
}
4441

Tests/Session/Flash/FlashBagTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
*/
2222
class FlashBagTest extends TestCase
2323
{
24-
/**
25-
* @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
26-
*/
27-
private $bag;
24+
protected array $array = [];
2825

29-
protected $array = [];
26+
private FlashBag $bag;
3027

3128
protected function setUp(): void
3229
{
@@ -38,7 +35,7 @@ protected function setUp(): void
3835

3936
protected function tearDown(): void
4037
{
41-
$this->bag = null;
38+
unset($this->bag);
4239
parent::tearDown();
4340
}
4441

Tests/Session/SessionTest.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
1818
use Symfony\Component\HttpFoundation\Session\Session;
1919
use Symfony\Component\HttpFoundation\Session\SessionBagProxy;
20+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2021
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
2122
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
23+
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
2224

2325
/**
2426
* SessionTest.
@@ -29,28 +31,15 @@
2931
*/
3032
class SessionTest extends TestCase
3133
{
32-
/**
33-
* @var \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface
34-
*/
35-
protected $storage;
36-
37-
/**
38-
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface
39-
*/
40-
protected $session;
34+
protected SessionStorageInterface $storage;
35+
protected SessionInterface $session;
4136

4237
protected function setUp(): void
4338
{
4439
$this->storage = new MockArraySessionStorage();
4540
$this->session = new Session($this->storage, new AttributeBag(), new FlashBag());
4641
}
4742

48-
protected function tearDown(): void
49-
{
50-
$this->storage = null;
51-
$this->session = null;
52-
}
53-
5443
public function testStart()
5544
{
5645
$this->assertEquals('', $this->session->getId());

Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
2424
{
2525
protected const PREFIX = 'prefix_';
2626

27-
/**
28-
* @var RedisSessionHandler
29-
*/
30-
protected $storage;
31-
32-
/**
33-
* @var \Redis|\RedisArray|\RedisCluster|\Predis\Client
34-
*/
35-
protected $redisClient;
27+
protected RedisSessionHandler $storage;
28+
protected \Redis|Relay|\RedisArray|\RedisCluster|\Predis\Client $redisClient;
3629

3730
abstract protected function createRedisClient(string $host): \Redis|Relay|\RedisArray|\RedisCluster|\Predis\Client;
3831

@@ -58,14 +51,6 @@ protected function setUp(): void
5851
);
5952
}
6053

61-
protected function tearDown(): void
62-
{
63-
$this->redisClient = null;
64-
$this->storage = null;
65-
66-
parent::tearDown();
67-
}
68-
6954
public function testOpenSession()
7055
{
7156
$this->assertTrue($this->storage->open('', ''));

Tests/Session/Storage/Handler/MarshallingSessionHandlerTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,8 @@
2222
*/
2323
class MarshallingSessionHandlerTest extends TestCase
2424
{
25-
/**
26-
* @var MockObject|\SessionHandlerInterface
27-
*/
28-
protected $handler;
29-
30-
/**
31-
* @var MockObject|MarshallerInterface
32-
*/
33-
protected $marshaller;
25+
protected MockObject&\SessionHandlerInterface $handler;
26+
protected MockObject&MarshallerInterface $marshaller;
3427

3528
protected function setUp(): void
3629
{

0 commit comments

Comments
 (0)