Skip to content

Commit

Permalink
Upgrade removed withConsecutive+willReturnOnConsecutiveCalls API with…
Browse files Browse the repository at this point in the history
… willReturnMap
  • Loading branch information
Slamdunk committed Feb 20, 2023
1 parent d60671f commit 948cb03
Showing 1 changed file with 101 additions and 81 deletions.
182 changes: 101 additions & 81 deletions tests/Token/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,19 @@ public function parseMustRaiseExceptionWhenDealingWithClaimsThatHaveEmptyStringK
public function parseMustReturnAnUnsecuredTokenWhenSignatureIsNotInformed(): void
{
$this->decoder->expects(self::exactly(3))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'], ['c'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec', 'c_dec');
->method('base64UrlDecode')
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
['c', 'c_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWT', 'alg' => 'none'],
[RegisteredClaims::AUDIENCE => 'test'],
);
->method('jsonDecode')
->willReturnMap([
['a_dec', ['typ' => 'JWT', 'alg' => 'none']],
['b_dec', [RegisteredClaims::AUDIENCE => 'test']],
]);

$parser = $this->createParser();
$token = $parser->parse('a.b.c');
Expand All @@ -209,16 +211,18 @@ public function parseMustConfigureTypeToJWTWhenItIsMissing(): void
{
$this->decoder->expects(self::exactly(3))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'], ['c'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec', 'c_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
['c', 'c_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['alg' => 'none'],
[RegisteredClaims::AUDIENCE => 'test'],
);
->method('jsonDecode')
->willReturnMap([
['a_dec', ['alg' => 'none']],
['b_dec', [RegisteredClaims::AUDIENCE => 'test']],
]);

$parser = $this->createParser();
$token = $parser->parse('a.b.c');
Expand All @@ -239,16 +243,18 @@ public function parseMustNotChangeTypeWhenItIsConfigured(): void
{
$this->decoder->expects(self::exactly(3))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'], ['c'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec', 'c_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
['c', 'c_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWS', 'alg' => 'none'],
[RegisteredClaims::AUDIENCE => 'test'],
);
->method('jsonDecode')
->willReturnMap([
['a_dec', ['typ' => 'JWS', 'alg' => 'none']],
['b_dec', [RegisteredClaims::AUDIENCE => 'test']],
]);

$parser = $this->createParser();
$token = $parser->parse('a.b.c');
Expand All @@ -269,16 +275,18 @@ public function parseShouldReplicateClaimValueOnHeaderWhenNeeded(): void
{
$this->decoder->expects(self::exactly(3))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'], ['c'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec', 'c_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
['c', 'c_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWT', 'alg' => 'none', RegisteredClaims::AUDIENCE => 'test'],
[RegisteredClaims::AUDIENCE => 'test'],
);
->willReturnMap([
['a_dec', ['typ' => 'JWT', 'alg' => 'none', RegisteredClaims::AUDIENCE => 'test']],
['b_dec', [RegisteredClaims::AUDIENCE => 'test']],
]);

$parser = $this->createParser();
$token = $parser->parse('a.b.c');
Expand All @@ -299,16 +307,18 @@ public function parseMustReturnANonSignedTokenWhenSignatureAlgorithmIsMissing():
{
$this->decoder->expects(self::exactly(3))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'], ['c'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec', 'c_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
['c', 'c_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWT'],
[RegisteredClaims::AUDIENCE => 'test'],
);
->willReturnMap([
['a_dec', ['typ' => 'JWT']],
['b_dec', [RegisteredClaims::AUDIENCE => 'test']],
]);

$parser = $this->createParser();
$token = $parser->parse('a.b.c');
Expand All @@ -329,16 +339,18 @@ public function parseMustReturnANonSignedTokenWhenSignatureAlgorithmIsNone(): vo
{
$this->decoder->expects(self::exactly(3))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'], ['c'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec', 'c_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
['c', 'c_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWT', 'alg' => 'none'],
[RegisteredClaims::AUDIENCE => 'test'],
);
->willReturnMap([
['a_dec', ['typ' => 'JWT', 'alg' => 'none']],
['b_dec', [RegisteredClaims::AUDIENCE => 'test']],
]);

$parser = $this->createParser();
$token = $parser->parse('a.b.c');
Expand All @@ -359,16 +371,18 @@ public function parseMustReturnASignedTokenWhenSignatureIsInformed(): void
{
$this->decoder->expects(self::exactly(3))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'], ['c'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec', 'c_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
['c', 'c_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWT', 'alg' => 'HS256'],
[RegisteredClaims::AUDIENCE => 'test'],
);
->willReturnMap([
['a_dec', ['typ' => 'JWT', 'alg' => 'HS256']],
['b_dec', [RegisteredClaims::AUDIENCE => 'test']],
]);

$parser = $this->createParser();
$token = $parser->parse('a.b.c');
Expand All @@ -394,16 +408,18 @@ public function parseMustConvertDateClaimsToObjects(): void

$this->decoder->expects(self::exactly(3))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'], ['c'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec', 'c_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
['c', 'c_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWT', 'alg' => 'HS256'],
$data,
);
->willReturnMap([
['a_dec', ['typ' => 'JWT', 'alg' => 'HS256']],
['b_dec', $data],
]);

$token = $this->createParser()->parse('a.b.c');
self::assertInstanceOf(Plain::class, $token);
Expand All @@ -428,16 +444,18 @@ public function parseMustConvertStringDates(): void

$this->decoder->expects(self::exactly(3))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'], ['c'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec', 'c_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
['c', 'c_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWT', 'alg' => 'HS256'],
$data,
);
->willReturnMap([
['a_dec', ['typ' => 'JWT', 'alg' => 'HS256']],
['b_dec', $data],
]);

$token = $this->createParser()->parse('a.b.c');
self::assertInstanceOf(Plain::class, $token);
Expand All @@ -457,16 +475,17 @@ public function parseShouldRaiseExceptionOnInvalidDate(): void

$this->decoder->expects(self::exactly(2))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWT', 'alg' => 'HS256'],
$data,
);
->willReturnMap([
['a_dec', ['typ' => 'JWT', 'alg' => 'HS256']],
['b_dec', $data],
]);

$this->expectException(InvalidTokenStructure::class);
$this->expectExceptionMessage('Value is not in the allowed date format: 14/10/2018 10:50:10.10 UTC');
Expand All @@ -480,16 +499,17 @@ public function parseShouldRaiseExceptionOnTimestampBeyondDateTimeImmutableRange

$this->decoder->expects(self::exactly(2))
->method('base64UrlDecode')
->withConsecutive(['a'], ['b'])
->willReturnOnConsecutiveCalls('a_dec', 'b_dec');
->willReturnMap([
['a', 'a_dec'],
['b', 'b_dec'],
]);

$this->decoder->expects(self::exactly(2))
->method('jsonDecode')
->withConsecutive(['a_dec'], ['b_dec'])
->willReturnOnConsecutiveCalls(
['typ' => 'JWT', 'alg' => 'HS256'],
$data,
);
->willReturnMap([
['a_dec', ['typ' => 'JWT', 'alg' => 'HS256']],
['b_dec', $data],
]);

$this->expectException(InvalidTokenStructure::class);
$this->createParser()->parse('a.b.c');
Expand Down

0 comments on commit 948cb03

Please sign in to comment.