Skip to content

Commit

Permalink
Remove PHP 8 DNF parameter type declarations LRN-43664
Browse files Browse the repository at this point in the history
  • Loading branch information
david-scarratt-lrn committed May 6, 2024
1 parent 52b0b2f commit cd8c1c9
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 90 deletions.
155 changes: 73 additions & 82 deletions tests/Request/InitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testGenerateWithMeta(
string $service,
array $security,
string $secret,
array|string $request,
/* array|string */ $request,
?string $action
) {
// This test verifies the correctness of the added telemetry data
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testGenerateSignature(
string $service,
array $security,
string $secret,
array|string $request,
/* array|string */ $request,
?string $action
) {
// We disable telemetry to be able to reliably test signature generation. Added telemetry
Expand All @@ -100,11 +100,11 @@ public function testGenerateSignature(
* @dataProvider generateProvider
*/
public function testGenerate(
array|string $expectedInitOptions,
/* array|string */ $expectedInitOptions,
string $service,
array $security,
string $secret,
array|string $request,
/* array|string */ $request,
?string $action
) {
// We disable telemetry to be able to reliably test signature generation. Added telemetry
Expand Down Expand Up @@ -282,84 +282,75 @@ public function constructorProvider(): array
'The service provided (wrongservice) is not valid'
],
'empty-security' => [

$service,
'',
$secret,
$request,
$action,
null,
ValidationException::class,
'The security packet must be an array or a valid JSON string'
],
'empty-security' => [

$service,
'',
$secret,
$request,
$action,
null,
ValidationException::class,
'The security packet must be an array or a valid JSON string'
],
'null-security' => [

$service,
null,
$secret,
$request,
$action,
null,
ValidationException::class,
'The security packet must be an array or a valid JSON string'
],
'empty-secret' => [

$service,
$security,
'',
$request,
$action,
null,
ValidationException::class,
'The `secret` argument must be a valid string'
],
'incorrect-security' => [

$service,
$wrongSecurity,
$secret,
$request,
$action,
null,
ValidationException::class,
'Invalid key found in the security packet: wrongParam'
],
'missing-questions_user_id' =>
[

'questions',
$security,
$secret,
$request,
$action,
null,
ValidationException::class,
'Questions API requires a `user_id` in the security packet'
],
'invalid-request' =>
[

$service,
$security,
$secret,
25,
$action,
null,
ValidationException::class,
'The request packet must be an array or a valid JSON string'
],
$service,
'',
$secret,
$request,
$action,
null,
ValidationException::class,
'The security packet must be an array or a valid JSON string'
],
'empty-security' => [
$service,
'',
$secret,
$request,
$action,
null,
ValidationException::class,
'The security packet must be an array or a valid JSON string'
],
'null-security' => [
$service,
null,
$secret,
$request,
$action,
null,
ValidationException::class,
'The security packet must be an array or a valid JSON string'
],
'empty-secret' => [
$service,
$security,
'',
$request,
$action,
null,
ValidationException::class,
'The `secret` argument must be a valid string'
],
'incorrect-security' => [
$service,
$wrongSecurity,
$secret,
$request,
$action,
null,
ValidationException::class,
'Invalid key found in the security packet: wrongParam'
],
'missing-questions_user_id' => [
'questions',
$security,
$secret,
$request,
$action,
null,
ValidationException::class,
'Questions API requires a `user_id` in the security packet'
],
'invalid-request' => [
$service,
$security,
$secret,
25,
$action,
null,
ValidationException::class,
'The request packet must be an array or a valid JSON string'
],
];
}

Expand Down
12 changes: 4 additions & 8 deletions tests/Services/PreHashStrings/LegacyPreHashStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,25 @@ public function testPreHashString(
string $service,
array $security,
string $secret,
array|string $request,
?array $request,
?string $action,
bool $v1Compat,
string $expected
) {
$preHashString = new LegacyPreHashString($service, $v1Compat);
if (is_string($request)) {
$request = json_decode($request, true);
$this->assertTrue($request !== false, 'Cannot decode JSON from string request');
}
$result = $preHashString->getPreHashString($security, $request, $action, $v1Compat ? $secret : null);
$this->assertEquals($expected, $result);
}

/** @returns array <
/** @returns array<string, array<
* string $service
* array $security
* string $secret
* array|string $request
* array $request
* ?string $action
* bool $v1Compat
* string $expected
* > */
* >> */
public function preHashStringProvider()
{
$testCases = [];
Expand Down

0 comments on commit cd8c1c9

Please sign in to comment.