Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaspt committed Apr 22, 2024
1 parent 34c7790 commit 3afbf2f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Services/PayloadEnrichment/ChainEnrichment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichmentInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class ChainEnrichment implements PayaloadEnrichmentInterface
class ChainEnrichment implements PayloadEnrichmentInterface
{
private $enrichments;

Expand Down
34 changes: 34 additions & 0 deletions Tests/PayloadEnrichment/ChainEnrichmentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichment;

use Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichmentInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\User\UserInterface;

class ChainEnrichmentTest extends TestCase
{
public function testEnrich(): void
{
$payload = ['foo' => 'bar'];

$enrichmentFoo = new class () implements PayloadEnrichmentInterface {
public function enrich(UserInterface $user, array &$payload): void
{
$payload['foo'] = 'baz';
}
};

$enrichmentBar = new class () implements PayloadEnrichmentInterface {
public function enrich(UserInterface $user, array &$payload): void
{
$payload['bar'] = 'qux';
}
};

$chainEnrichment = new ChainEnrichment([$enrichmentFoo, $enrichmentBar]);
$chainEnrichment->enrich($this->createMock(UserInterface::class), $payload);

$this->assertEquals(['foo' => 'baz', 'bar' => 'qux'], $payload);
}
}
18 changes: 18 additions & 0 deletions Tests/PayloadEnrichment/NullEnrichmentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichment;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\User\UserInterface;

class NullEnrichmentTest extends TestCase
{
public function testEnrich(): void
{
$payload = ['foo' => 'bar'];
$enrichment = new NullEnrichment();
$enrichment->enrich($this->createMock(UserInterface::class), $payload);

$this->assertEquals(['foo' => 'bar'], $payload);
}
}
3 changes: 2 additions & 1 deletion Tests/PayloadEnrichment/RandomJtiEnrichmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ class RandomJtiEnrichmentTest extends TestCase
{
public function testEnrich(): void
{
$payload = [];
$payload = ['foo' => 'bar'];
$enrichment = new RandomJtiEnrichment();
$enrichment->enrich($this->createMock(UserInterface::class), $payload);

$this->assertArrayHasKey('jti', $payload);
$this->assertIsString($payload['jti']);
$this->assertArrayHasKey('foo', $payload);
}
}

0 comments on commit 3afbf2f

Please sign in to comment.