Skip to content

Commit

Permalink
Merge pull request #931 from peter279k/improve_assertions
Browse files Browse the repository at this point in the history
Improve assert equals
  • Loading branch information
Ocramius authored Oct 1, 2022
2 parents 106fa9b + 9ad445e commit 0b66124
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 49 deletions.
10 changes: 5 additions & 5 deletions test/functional/ES512TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public function builderCanGenerateAToken(): Token
->withHeader('jki', '1234')
->getToken($this->config->signer(), $this->config->signingKey());

self::assertEquals('1234', $token->headers()->get('jki'));
self::assertEquals('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertEquals($user, $token->claims()->get('user'));
self::assertSame('1234', $token->headers()->get('jki'));
self::assertSame('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertSame($user, $token->claims()->get('user'));

self::assertEquals(
self::assertSame(
['http://client.abc.com', 'http://client2.abc.com'],
$token->claims()->get(Token\RegisteredClaims::AUDIENCE),
);
Expand All @@ -123,7 +123,7 @@ public function parserCanReadAToken(Token $generated): void
assert($read instanceof Token\Plain);

self::assertEquals($generated, $read);
self::assertEquals('testing', $read->claims()->get('user')['name']);
self::assertSame('testing', $read->claims()->get('user')['name']);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions test/functional/EcdsaTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ public function builderCanGenerateAToken(): Token
->withHeader('jki', '1234')
->getToken($this->config->signer(), $this->config->signingKey());

self::assertEquals('1234', $token->headers()->get('jki'));
self::assertEquals('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertEquals($user, $token->claims()->get('user'));
self::assertSame('1234', $token->headers()->get('jki'));
self::assertSame('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertSame($user, $token->claims()->get('user'));

self::assertEquals(
self::assertSame(
['http://client.abc.com', 'http://client2.abc.com'],
$token->claims()->get(Token\RegisteredClaims::AUDIENCE),
);
Expand All @@ -125,7 +125,7 @@ public function parserCanReadAToken(Token $generated): void
assert($read instanceof Token\Plain);

self::assertEquals($generated, $read);
self::assertEquals('testing', $read->claims()->get('user')['name']);
self::assertSame('testing', $read->claims()->get('user')['name']);
}

/**
Expand Down Expand Up @@ -234,6 +234,6 @@ public function everythingShouldWorkWhenUsingATokenGeneratedByOtherLibs(): void
$constraint = new SignedWith(Sha512::create(), InMemory::plainText($key));

self::assertTrue($this->config->validator()->validate($token, $constraint));
self::assertEquals('world', $token->claims()->get('hello'));
self::assertSame('world', $token->claims()->get('hello'));
}
}
10 changes: 5 additions & 5 deletions test/functional/EddsaTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public function builderCanGenerateAToken(): Token
->withHeader('jki', '1234')
->getToken($this->config->signer(), $this->config->signingKey());

self::assertEquals('1234', $token->headers()->get('jki'));
self::assertEquals('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertEquals($user, $token->claims()->get('user'));
self::assertSame('1234', $token->headers()->get('jki'));
self::assertSame('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertSame($user, $token->claims()->get('user'));

self::assertEquals(
self::assertSame(
['http://client.abc.com', 'http://client2.abc.com'],
$token->claims()->get(Token\RegisteredClaims::AUDIENCE),
);
Expand All @@ -106,7 +106,7 @@ public function parserCanReadAToken(Token $generated): void
assert($read instanceof Token\Plain);

self::assertEquals($generated, $read);
self::assertEquals('testing', $read->claims()->get('user')['name']);
self::assertSame('testing', $read->claims()->get('user')['name']);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions test/functional/HmacTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public function builderCanGenerateAToken(): Token
->withHeader('jki', '1234')
->getToken($this->config->signer(), $this->config->signingKey());

self::assertEquals('1234', $token->headers()->get('jki'));
self::assertEquals(['http://client.abc.com'], $token->claims()->get(Token\RegisteredClaims::AUDIENCE));
self::assertEquals('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertEquals($user, $token->claims()->get('user'));
self::assertSame('1234', $token->headers()->get('jki'));
self::assertSame(['http://client.abc.com'], $token->claims()->get(Token\RegisteredClaims::AUDIENCE));
self::assertSame('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertSame($user, $token->claims()->get('user'));

return $token;
}
Expand All @@ -85,7 +85,7 @@ public function parserCanReadAToken(Token $generated): void
assert($read instanceof Token\Plain);

self::assertEquals($generated, $read);
self::assertEquals('testing', $read->claims()->get('user')['name']);
self::assertSame('testing', $read->claims()->get('user')['name']);
}

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ public function everythingShouldWorkWhenUsingATokenGeneratedByOtherLibs(): void
$constraint = new SignedWith($config->signer(), $config->verificationKey());

self::assertTrue($config->validator()->validate($token, $constraint));
self::assertEquals('world', $token->claims()->get('hello'));
self::assertSame('world', $token->claims()->get('hello'));
}

/** @test */
Expand Down
2 changes: 1 addition & 1 deletion test/functional/MaliciousTamperingPreventionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function preventRegressionsThatAllowsMaliciousTampering(): void
$token = $this->config->parser()->parse($bad);
assert($token instanceof Plain);

self::assertEquals('world', $token->claims()->get('hello'), 'The claim content should not be modified');
self::assertSame('world', $token->claims()->get('hello'), 'The claim content should not be modified');

$validator = $this->config->validator();

Expand Down
12 changes: 6 additions & 6 deletions test/functional/RsaTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public function builderCanGenerateAToken(): Token
->withHeader('jki', '1234')
->getToken($this->config->signer(), $this->config->signingKey());

self::assertEquals('1234', $token->headers()->get('jki'));
self::assertEquals(['http://client.abc.com'], $token->claims()->get(Token\RegisteredClaims::AUDIENCE));
self::assertEquals('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertEquals($user, $token->claims()->get('user'));
self::assertSame('1234', $token->headers()->get('jki'));
self::assertSame(['http://client.abc.com'], $token->claims()->get(Token\RegisteredClaims::AUDIENCE));
self::assertSame('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertSame($user, $token->claims()->get('user'));

return $token;
}
Expand All @@ -117,7 +117,7 @@ public function parserCanReadAToken(Token $generated): void
assert($read instanceof Token\Plain);

self::assertEquals($generated, $read);
self::assertEquals('testing', $read->claims()->get('user')['name']);
self::assertSame('testing', $read->claims()->get('user')['name']);
}

/**
Expand Down Expand Up @@ -194,6 +194,6 @@ public function everythingShouldWorkWhenUsingATokenGeneratedByOtherLibs(): void
$constraint = new SignedWith($this->config->signer(), $this->config->verificationKey());

self::assertTrue($this->config->validator()->validate($token, $constraint));
self::assertEquals('world', $token->claims()->get('hello'));
self::assertSame('world', $token->claims()->get('hello'));
}
}
6 changes: 3 additions & 3 deletions test/functional/UnsignedTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public function builderCanGenerateAToken(): Token

self::assertEquals(new Token\Signature('', ''), $token->signature());
self::assertEquals(['http://client.abc.com'], $token->claims()->get(Token\RegisteredClaims::AUDIENCE));
self::assertEquals('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertSame($expiration, $token->claims()->get(Token\RegisteredClaims::EXPIRATION_TIME));
self::assertSame('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER));
self::assertEquals($expiration, $token->claims()->get(Token\RegisteredClaims::EXPIRATION_TIME));
self::assertEquals($user, $token->claims()->get('user'));

return $token;
Expand All @@ -86,7 +86,7 @@ public function parserCanReadAToken(Token $generated): void
assert($read instanceof Token\Plain);

self::assertEquals($generated, $read);
self::assertEquals('testing', $read->claims()->get('user')['name']);
self::assertSame('testing', $read->claims()->get('user')['name']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Signer/Blake2bTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function algorithmIdMustBeCorrect(): void
{
$signer = new Blake2b();

self::assertEquals('BLAKE2B', $signer->algorithmId());
self::assertSame('BLAKE2B', $signer->algorithmId());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Signer/EddsaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class EddsaTest extends TestCase
*/
public function algorithmIdMustBeCorrect(): void
{
self::assertEquals('EdDSA', $this->getSigner()->algorithmId());
self::assertSame('EdDSA', $this->getSigner()->algorithmId());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Signer/Hmac/Sha256Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function algorithmIdMustBeCorrect(): void
{
$signer = new Sha256();

self::assertEquals('HS256', $signer->algorithmId());
self::assertSame('HS256', $signer->algorithmId());
}

/**
Expand All @@ -29,7 +29,7 @@ public function algorithmMustBeCorrect(): void
{
$signer = new Sha256();

self::assertEquals('sha256', $signer->algorithm());
self::assertSame('sha256', $signer->algorithm());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Signer/Hmac/Sha384Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function algorithmIdMustBeCorrect(): void
{
$signer = new Sha384();

self::assertEquals('HS384', $signer->algorithmId());
self::assertSame('HS384', $signer->algorithmId());
}

/**
Expand All @@ -29,7 +29,7 @@ public function algorithmMustBeCorrect(): void
{
$signer = new Sha384();

self::assertEquals('sha384', $signer->algorithm());
self::assertSame('sha384', $signer->algorithm());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Signer/Hmac/Sha512Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function algorithmIdMustBeCorrect(): void
{
$signer = new Sha512();

self::assertEquals('HS512', $signer->algorithmId());
self::assertSame('HS512', $signer->algorithmId());
}

/**
Expand All @@ -29,7 +29,7 @@ public function algorithmMustBeCorrect(): void
{
$signer = new Sha512();

self::assertEquals('sha512', $signer->algorithm());
self::assertSame('sha512', $signer->algorithm());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Signer/HmacTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function signMustReturnAHashAccordingWithTheAlgorithm(): string
{
$hash = hash_hmac('sha256', 'test', '123', true);

self::assertEquals($hash, $this->signer->sign('test', InMemory::plainText('123')));
self::assertSame($hash, $this->signer->sign('test', InMemory::plainText('123')));

return $hash;
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Signer/NoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function algorithmIdMustBeCorrect(): void
{
$signer = new None();

self::assertEquals('none', $signer->algorithmId());
self::assertSame('none', $signer->algorithmId());
}

/**
Expand All @@ -32,7 +32,7 @@ public function signShouldReturnAnEmptyString(): void
{
$signer = new None();

self::assertEquals('', $signer->sign('test', InMemory::plainText('test')));
self::assertSame('', $signer->sign('test', InMemory::plainText('test')));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Signer/Rsa/Sha256Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function algorithmIdMustBeCorrect(): void
{
$signer = new Sha256();

self::assertEquals('RS256', $signer->algorithmId());
self::assertSame('RS256', $signer->algorithmId());
}

/**
Expand All @@ -31,6 +31,6 @@ public function algorithmMustBeCorrect(): void
{
$signer = new Sha256();

self::assertEquals(OPENSSL_ALGO_SHA256, $signer->algorithm());
self::assertSame(OPENSSL_ALGO_SHA256, $signer->algorithm());
}
}
4 changes: 2 additions & 2 deletions test/unit/Signer/Rsa/Sha384Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function algorithmIdMustBeCorrect(): void
{
$signer = new Sha384();

self::assertEquals('RS384', $signer->algorithmId());
self::assertSame('RS384', $signer->algorithmId());
}

/**
Expand All @@ -31,6 +31,6 @@ public function algorithmMustBeCorrect(): void
{
$signer = new Sha384();

self::assertEquals(OPENSSL_ALGO_SHA384, $signer->algorithm());
self::assertSame(OPENSSL_ALGO_SHA384, $signer->algorithm());
}
}
4 changes: 2 additions & 2 deletions test/unit/Signer/Rsa/Sha512Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function algorithmIdMustBeCorrect(): void
{
$signer = new Sha512();

self::assertEquals('RS512', $signer->algorithmId());
self::assertSame('RS512', $signer->algorithmId());
}

/**
Expand All @@ -31,6 +31,6 @@ public function algorithmMustBeCorrect(): void
{
$signer = new Sha512();

self::assertEquals(OPENSSL_ALGO_SHA512, $signer->algorithm());
self::assertSame(OPENSSL_ALGO_SHA512, $signer->algorithm());
}
}

0 comments on commit 0b66124

Please sign in to comment.