Skip to content

Commit

Permalink
Use type aliases to simplify expected values from JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
gapple committed Feb 25, 2023
1 parent 4cdf3ba commit 563ec3a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests/Httpwg/HttpwgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
use gapple\Tests\StructuredFields\RulesetTest;
use ParagonIE\ConstantTime\Base32;

/**
* @phpstan-type ExpectedParameters array<array{string, mixed}>
* @phpstan-type ExpectedTuple array{mixed, ExpectedParameters}
* @phpstan-type ExpectedInnerList array{array<ExpectedTuple>, ExpectedParameters}
* @phpstan-type ExpectedOuterList array<ExpectedTuple>
* @phpstan-type ExpectedDictionary array<array{string, ExpectedTuple}>
*/
abstract class HttpwgTest extends RulesetTest
{
/**
Expand Down Expand Up @@ -67,7 +74,7 @@ protected function rulesetDataProvider(): array
/**
* Convert the expected value of an item tuple.
*
* @param array{mixed, array<array{string, mixed}>} $item
* @param ExpectedTuple $item
* @return \gapple\StructuredFields\Item
*/
private static function convertExpectedItem(array $item): Item
Expand All @@ -78,7 +85,7 @@ private static function convertExpectedItem(array $item): Item
/**
* Convert the expected values of a parameters map.
*
* @param array<array{string, mixed}> $parameters
* @param ExpectedParameters $parameters
* @return Parameters
*/
private static function convertParameters(array $parameters): Parameters
Expand All @@ -100,7 +107,7 @@ private static function convertParameters(array $parameters): Parameters
/**
* Convert the expected values of an inner list tuple.
*
* @param array{array<array{mixed, array<array{string, mixed}>}>, array<array{string, mixed}>} $innerList
* @param ExpectedInnerList $innerList
* @return InnerList
*/
private static function convertInnerList(array $innerList): InnerList
Expand All @@ -117,7 +124,7 @@ private static function convertInnerList(array $innerList): InnerList
/**
* Convert the expected values of a list.
*
* @param array<array{mixed, array<array{string, mixed}>}> $list
* @param ExpectedOuterList $list
* @return OuterList
*/
private static function convertExpectedList(array $list): OuterList
Expand All @@ -138,7 +145,7 @@ private static function convertExpectedList(array $list): OuterList
/**
* Convert the expected values of a dictionary.
*
* @param array<array{string, array{mixed, array<array{string, mixed}>}}> $dictionary
* @param ExpectedDictionary $dictionary
* @return Dictionary
*/
private static function convertExpectedDictionary(array $dictionary): Dictionary
Expand Down

0 comments on commit 563ec3a

Please sign in to comment.