Skip to content

Commit

Permalink
[shopsys] update of several packages and different way to install Phi…
Browse files Browse the repository at this point in the history
…ng (#3213)
  • Loading branch information
TomasLudvik authored Jul 3, 2024
2 parents aef47bb + 3802560 commit 3215526
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 42 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"phpstan/phpstan-doctrine": "^1.3.4",
"phpstan/phpstan-phpunit": "^1.1.1",
"phpstan/phpstan-symfony": "^1.1.8",
"phpunit/phpunit": "^9.5.20",
"phpunit/phpunit": "^11.2.1",
"shopsys/coding-standards": "15.0.x-dev"
},
"config": {
Expand Down
22 changes: 9 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
failOnWarning="true"
beStrictAboutTestsThatDoNotTestAnything="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<coverage/>

<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source/>
</phpunit>
82 changes: 54 additions & 28 deletions tests/Unit/Model/Token/TokenFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
use Lcobucci\JWT\Encoding\JoseEncoder;
use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Token\Builder;
use Lcobucci\JWT\UnencryptedToken;
use Lcobucci\JWT\Token\Plain;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
Expand All @@ -27,12 +28,19 @@
class TokenFacadeTest extends TestCase
{
/**
* @dataProvider tokensDataProvider
* @param \Lcobucci\JWT\UnencryptedToken $token
* @param string|null $issuedBy
* @param \Lcobucci\JWT\Signer\Key\InMemory|null $privateKey
* @param \DateTimeImmutable|null $expiresAt
* @param class-string|null $exceptionClass
*/
public function testTokenValidation(UnencryptedToken $token, ?string $exceptionClass): void
{
#[DataProvider('tokensDataProvider')]
public function testTokenValidation(
?string $issuedBy,
?InMemory $privateKey,
?DateTimeImmutable $expiresAt,
?string $exceptionClass,
): void {
$token = $this->createToken($issuedBy, $privateKey, $expiresAt);
$tokenFacade = $this->createTokenFacade();

if ($exceptionClass !== null) {
Expand All @@ -42,11 +50,14 @@ public function testTokenValidation(UnencryptedToken $token, ?string $exceptionC
}

/**
* @return iterable
* @param string|null $issuedBy
* @param \Lcobucci\JWT\Signer\Key\InMemory|null $privateKey
* @param \DateTimeImmutable|null $expiresAt
* @return \Lcobucci\JWT\Token\Plain
*/
public function tokensDataProvider(): iterable
protected function createToken(?string $issuedBy, ?InMemory $privateKey, ?DateTimeImmutable $expiresAt): Plain
{
$builderTemplate = (new Builder(new JoseEncoder(), ChainedFormatter::default()))
$builder = (new Builder(new JoseEncoder(), ChainedFormatter::default()))
->issuedBy('http://webserver:8080')
->permittedFor('http://webserver:8080')
->issuedAt(new DateTimeImmutable())
Expand All @@ -55,38 +66,53 @@ public function tokensDataProvider(): iterable

$jwtConfiguration = $this->createJwtConfiguration();
$signer = $jwtConfiguration->signer();
$privateKey = $jwtConfiguration->signingKey();

$builder = clone $builderTemplate;
if ($privateKey === null) {
$privateKey = $jwtConfiguration->signingKey();
}

yield [
$builder->getToken($signer, $privateKey),
null,
];
if ($issuedBy !== null) {
$builder->issuedBy($issuedBy);
}

if ($expiresAt !== null) {
$builder->expiresAt($expiresAt);
}

$builder = clone $builderTemplate;
return $builder->getToken($signer, $privateKey);
}

/**
* @return iterable
*/
public static function tokensDataProvider(): iterable
{
yield [
$builder
->issuedBy('http://another-server:8080')
->getToken($signer, $privateKey),
InvalidTokenUserMessageException::class,
'issuedBy' => null,
'privateKey' => null,
'expiresAt' => null,
'exceptionClass' => null,
];

$builder = clone $builderTemplate;

yield [
$builder->getToken($signer, InMemory::file(__DIR__ . '/testKeys/invalid-private.key')),
NotVerifiedTokenUserMessageException::class,
'issuedBy' => 'http://another-server:8080',
'privateKey' => null,
'expiresAt' => null,
'exceptionClass' => InvalidTokenUserMessageException::class,
];

$builder = clone $builderTemplate;
yield [
'issuedBy' => null,
'privateKey' => InMemory::file(__DIR__ . '/testKeys/invalid-private.key'),
'expiresAt' => null,
'exceptionClass' => NotVerifiedTokenUserMessageException::class,
];

yield [
$builder
->expiresAt(new DateTimeImmutable('- 5 minutes'))
->getToken($signer, $privateKey),
ExpiredTokenUserMessageException::class,
'issuedBy' => null,
'privateKey' => null,
'expiresAt' => new DateTimeImmutable('- 5 minutes'),
'exceptionClass' => ExpiredTokenUserMessageException::class,
];
}

Expand Down

0 comments on commit 3215526

Please sign in to comment.