Skip to content

Commit a0ce283

Browse files
committed
Corona: Add types to request class properties
Reviewed at https://reviews.lunr.nl/r/1103/
1 parent 289de78 commit a0ce283

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/Lunr/Corona/Request.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,62 +39,62 @@ class Request
3939
* Stored $_POST values
4040
* @var array<string,mixed>
4141
*/
42-
protected $post;
42+
protected readonly array $post;
4343

4444
/**
4545
* Stored $_GET values
4646
* @var array<string,mixed>
4747
*/
48-
protected $get;
48+
protected readonly array $get;
4949

5050
/**
5151
* Stored $_COOKIE values
5252
* @var array<string,mixed>
5353
*/
54-
protected $cookie;
54+
protected readonly array $cookie;
5555

5656
/**
5757
* Stored $_SERVER values
5858
* @var array<string,mixed>
5959
*/
60-
protected $server;
60+
protected readonly array $server;
6161

6262
/**
6363
* Request property data
6464
*
6565
* @var array<string, mixed>
6666
*/
67-
protected $request;
67+
protected readonly array $request;
6868

6969
/**
7070
* Stored $_FILES values
7171
* @var array<string,array<string,mixed>>
7272
*/
73-
protected $files;
73+
protected readonly array $files;
7474

7575
/**
7676
* Stored php://input values
7777
* @var string
7878
*/
79-
protected $raw_data;
79+
protected string $raw_data;
8080

8181
/**
8282
* Stored command line arguments
8383
* @var array<string,string|null>
8484
*/
85-
protected $cli_args;
85+
protected readonly array $cli_args;
8686

8787
/**
8888
* Shared instance of the request parser.
8989
* @var RequestParserInterface
9090
*/
91-
protected $parser;
91+
protected readonly RequestParserInterface $parser;
9292

9393
/**
9494
* The request values to mock.
9595
* @var array<string,mixed>
9696
*/
97-
private $mock;
97+
private array $mock;
9898

9999
/**
100100
* Constructor.
@@ -122,15 +122,8 @@ public function __construct($parser)
122122
*/
123123
public function __destruct()
124124
{
125-
unset($this->post);
126-
unset($this->get);
127-
unset($this->server);
128-
unset($this->cookie);
129-
unset($this->request);
130-
unset($this->files);
131-
unset($this->parser);
132-
unset($this->mock);
133-
unset($this->raw_data);
125+
// Intentionally not unsetting $this->mock and $this->raw_data, since
126+
// that may break access to mocked request values during PHP shutdown.
134127
}
135128

136129
/**

src/Lunr/Corona/Tests/RequestGetDataTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,12 @@ public function testGetAllOptionsReturnsArray($keys): void
196196
$values[] = 'value';
197197
}
198198

199-
$this->set_reflection_property_value('cli_args', array_combine($keys, $values));
199+
$class = $this->reflection->newInstanceWithoutConstructor();
200200

201-
$return = $this->class->get_all_options();
201+
$this->reflection->getProperty('cli_args')
202+
->setValue($class, array_combine($keys, $values));
203+
204+
$return = $class->get_all_options();
202205

203206
$this->assertEquals($keys, $return);
204207
}
@@ -213,9 +216,12 @@ public function testGetAllOptionsReturnsArray($keys): void
213216
*/
214217
public function testGetOptionDataReturnsValueForValidKey($value): void
215218
{
216-
$this->set_reflection_property_value('cli_args', [ 'a' => $value ]);
219+
$class = $this->reflection->newInstanceWithoutConstructor();
220+
221+
$this->reflection->getProperty('cli_args')
222+
->setValue($class, [ 'a' => $value ]);
217223

218-
$result = $this->class->get_option_data('a');
224+
$result = $class->get_option_data('a');
219225

220226
$this->assertEquals($value, $result);
221227
}

0 commit comments

Comments
 (0)