Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use attributes for PHPUnit #1056

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ endif

.PHONY: phpbench
phpbench:
@vendor/bin/phpbench run -l dots --report=$(PHPBENCH_REPORT) $(PHPBENCH_FLAGS)
@vendor/bin/phpbench run -l dots --retry-threshold=5 --report=$(PHPBENCH_REPORT) $(PHPBENCH_FLAGS)
131 changes: 21 additions & 110 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@
use Lcobucci\JWT\Token\Parser as ParserImpl;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validator;
use PHPUnit\Framework\Attributes as PHPUnit;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* @covers ::__construct
* @coversDefaultClass \Lcobucci\JWT\Configuration
*
* @uses \Lcobucci\JWT\Encoding\ChainedFormatter
* @uses \Lcobucci\JWT\Encoding\MicrosecondBasedDateConversion
* @uses \Lcobucci\JWT\Encoding\UnifyAudience
* @uses \Lcobucci\JWT\Signer\Key\InMemory
* @uses \Lcobucci\JWT\Token\Builder
* @uses \Lcobucci\JWT\Token\Parser
* @uses \Lcobucci\JWT\Validation\Validator
*/
#[PHPUnit\CoversClass(Configuration::class)]
lcobucci marked this conversation as resolved.
Show resolved Hide resolved
#[PHPUnit\UsesClass(ChainedFormatter::class)]
#[PHPUnit\UsesClass(InMemory::class)]
#[PHPUnit\UsesClass(BuilderImpl::class)]
#[PHPUnit\UsesClass(ParserImpl::class)]
#[PHPUnit\UsesClass(\Lcobucci\JWT\Validation\Validator::class)]
final class ConfigurationTest extends TestCase
{
private Parser&MockObject $parser;
Expand All @@ -41,7 +36,7 @@ final class ConfigurationTest extends TestCase
private Validator&MockObject $validator;
private Constraint&MockObject $validationConstraints;

/** @before */
#[PHPUnit\Before]
public function createDependencies(): void
{
$this->signer = $this->createMock(Signer::class);
Expand All @@ -52,14 +47,7 @@ public function createDependencies(): void
$this->validationConstraints = $this->createMock(Constraint::class);
}

/**
* @test
*
* @covers ::forAsymmetricSigner
* @covers ::signer
* @covers ::signingKey
* @covers ::verificationKey
*/
#[PHPUnit\Test]
public function forAsymmetricSignerShouldConfigureSignerAndBothKeys(): void
{
$signingKey = InMemory::plainText('private');
Expand All @@ -72,14 +60,7 @@ public function forAsymmetricSignerShouldConfigureSignerAndBothKeys(): void
self::assertSame($verificationKey, $config->verificationKey());
}

/**
* @test
*
* @covers ::forSymmetricSigner
* @covers ::signer
* @covers ::signingKey
* @covers ::verificationKey
*/
#[PHPUnit\Test]
public function forSymmetricSignerShouldConfigureSignerAndBothKeys(): void
{
$key = InMemory::plainText('private');
Expand All @@ -90,13 +71,7 @@ public function forSymmetricSignerShouldConfigureSignerAndBothKeys(): void
self::assertSame($key, $config->verificationKey());
}

/**
* @test
*
* @covers ::builder
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function builderShouldCreateABuilderWithDefaultEncoderAndClaimFactory(): void
{
$config = Configuration::forSymmetricSigner(
Expand All @@ -110,13 +85,7 @@ public function builderShouldCreateABuilderWithDefaultEncoderAndClaimFactory():
self::assertEquals(new BuilderImpl(new JoseEncoder(), ChainedFormatter::default()), $builder);
}

/**
* @test
*
* @covers ::builder
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function builderShouldCreateABuilderWithCustomizedEncoderAndClaimFactory(): void
{
$config = Configuration::forSymmetricSigner(
Expand All @@ -130,14 +99,7 @@ public function builderShouldCreateABuilderWithCustomizedEncoderAndClaimFactory(
self::assertEquals(new BuilderImpl($this->encoder, ChainedFormatter::default()), $builder);
}

/**
* @test
*
* @covers ::builder
* @covers ::setBuilderFactory
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function builderShouldUseBuilderFactoryWhenThatIsConfigured(): void
{
$builder = $this->createMock(Builder::class);
Expand All @@ -154,13 +116,7 @@ static function () use ($builder): Builder {
self::assertSame($builder, $config->builder());
}

/**
* @test
*
* @covers ::parser
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function parserShouldReturnAParserWithDefaultDecoder(): void
{
$config = Configuration::forSymmetricSigner(
Expand All @@ -172,13 +128,7 @@ public function parserShouldReturnAParserWithDefaultDecoder(): void
self::assertNotEquals(new ParserImpl($this->decoder), $parser);
}

/**
* @test
*
* @covers ::parser
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function parserShouldReturnAParserWithCustomizedDecoder(): void
{
$config = Configuration::forSymmetricSigner(
Expand All @@ -191,14 +141,7 @@ public function parserShouldReturnAParserWithCustomizedDecoder(): void
self::assertEquals(new ParserImpl($this->decoder), $parser);
}

/**
* @test
*
* @covers ::parser
* @covers ::setParser
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function parserShouldNotCreateAnInstanceIfItWasConfigured(): void
{
$config = Configuration::forSymmetricSigner(
Expand All @@ -210,13 +153,7 @@ public function parserShouldNotCreateAnInstanceIfItWasConfigured(): void
self::assertSame($this->parser, $config->parser());
}

/**
* @test
*
* @covers ::validator
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function validatorShouldReturnTheDefaultWhenItWasNotConfigured(): void
{
$config = Configuration::forSymmetricSigner(
Expand All @@ -228,14 +165,7 @@ public function validatorShouldReturnTheDefaultWhenItWasNotConfigured(): void
self::assertNotSame($this->validator, $validator);
}

/**
* @test
*
* @covers ::validator
* @covers ::setValidator
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function validatorShouldReturnTheConfiguredValidator(): void
{
$config = Configuration::forSymmetricSigner(
Expand All @@ -247,13 +177,7 @@ public function validatorShouldReturnTheConfiguredValidator(): void
self::assertSame($this->validator, $config->validator());
}

/**
* @test
*
* @covers ::validationConstraints
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function validationConstraintsShouldReturnAnEmptyArrayWhenItWasNotConfigured(): void
{
$config = Configuration::forSymmetricSigner(
Expand All @@ -264,14 +188,7 @@ public function validationConstraintsShouldReturnAnEmptyArrayWhenItWasNotConfigu
self::assertSame([], $config->validationConstraints());
}

/**
* @test
*
* @covers ::validationConstraints
* @covers ::setValidationConstraints
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function validationConstraintsShouldReturnTheConfiguredValidator(): void
{
$config = Configuration::forSymmetricSigner(
Expand All @@ -283,13 +200,7 @@ public function validationConstraintsShouldReturnTheConfiguredValidator(): void
self::assertSame([$this->validationConstraints], $config->validationConstraints());
}

/**
* @test
*
* @covers ::builder
*
* @uses \Lcobucci\JWT\Configuration::forSymmetricSigner
*/
#[PHPUnit\Test]
public function customClaimFormatterCanBeUsed(): void
{
$formatter = $this->createMock(ClaimsFormatter::class);
Expand Down
Loading
Loading