Skip to content

Commit

Permalink
Corona: Add types to request class properties
Browse files Browse the repository at this point in the history
  • Loading branch information
pprkut committed Jan 25, 2024
1 parent 289de78 commit a0ce283
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
31 changes: 12 additions & 19 deletions src/Lunr/Corona/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,62 +39,62 @@ class Request
* Stored $_POST values
* @var array<string,mixed>
*/
protected $post;
protected readonly array $post;

/**
* Stored $_GET values
* @var array<string,mixed>
*/
protected $get;
protected readonly array $get;

/**
* Stored $_COOKIE values
* @var array<string,mixed>
*/
protected $cookie;
protected readonly array $cookie;

/**
* Stored $_SERVER values
* @var array<string,mixed>
*/
protected $server;
protected readonly array $server;

/**
* Request property data
*
* @var array<string, mixed>
*/
protected $request;
protected readonly array $request;

/**
* Stored $_FILES values
* @var array<string,array<string,mixed>>
*/
protected $files;
protected readonly array $files;

/**
* Stored php://input values
* @var string
*/
protected $raw_data;
protected string $raw_data;

/**
* Stored command line arguments
* @var array<string,string|null>
*/
protected $cli_args;
protected readonly array $cli_args;

/**
* Shared instance of the request parser.
* @var RequestParserInterface
*/
protected $parser;
protected readonly RequestParserInterface $parser;

/**
* The request values to mock.
* @var array<string,mixed>
*/
private $mock;
private array $mock;

/**
* Constructor.
Expand Down Expand Up @@ -122,15 +122,8 @@ public function __construct($parser)
*/
public function __destruct()
{
unset($this->post);
unset($this->get);
unset($this->server);
unset($this->cookie);
unset($this->request);
unset($this->files);
unset($this->parser);
unset($this->mock);
unset($this->raw_data);
// Intentionally not unsetting $this->mock and $this->raw_data, since
// that may break access to mocked request values during PHP shutdown.
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/Lunr/Corona/Tests/RequestGetDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,12 @@ public function testGetAllOptionsReturnsArray($keys): void
$values[] = 'value';
}

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

$return = $this->class->get_all_options();
$this->reflection->getProperty('cli_args')
->setValue($class, array_combine($keys, $values));

$return = $class->get_all_options();

$this->assertEquals($keys, $return);
}
Expand All @@ -213,9 +216,12 @@ public function testGetAllOptionsReturnsArray($keys): void
*/
public function testGetOptionDataReturnsValueForValidKey($value): void
{
$this->set_reflection_property_value('cli_args', [ 'a' => $value ]);
$class = $this->reflection->newInstanceWithoutConstructor();

$this->reflection->getProperty('cli_args')
->setValue($class, [ 'a' => $value ]);

$result = $this->class->get_option_data('a');
$result = $class->get_option_data('a');

$this->assertEquals($value, $result);
}
Expand Down

0 comments on commit a0ce283

Please sign in to comment.