-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCryptographyExtensionTest.php
More file actions
71 lines (57 loc) · 3.05 KB
/
Copy pathCryptographyExtensionTest.php
File metadata and controls
71 lines (57 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace Patchlevel\Hydrator\Tests\Unit\Extension\Cryptography;
use Patchlevel\Hydrator\Cryptography\PayloadCryptographer;
use Patchlevel\Hydrator\Extension\Cryptography\Cryptographer;
use Patchlevel\Hydrator\Extension\Cryptography\CryptographyExtension;
use Patchlevel\Hydrator\Extension\Cryptography\CryptographyMetadataEnricher;
use Patchlevel\Hydrator\Extension\Cryptography\CryptographyMiddleware;
use Patchlevel\Hydrator\Extension\Cryptography\LegacyCryptographyDecryptMiddleware;
use Patchlevel\Hydrator\Extension\Cryptography\LegacyCryptographyMetadataEnricher;
use Patchlevel\Hydrator\StackHydratorBuilder;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(CryptographyExtension::class)]
final class CryptographyExtensionTest extends TestCase
{
public function testConfigureWithoutLegacyOptions(): void
{
$builder = new StackHydratorBuilder();
$cryptographer = $this->createMock(Cryptographer::class);
$extension = new CryptographyExtension($cryptographer);
$extension->configure($builder);
$middlewares = $builder->middlewares();
self::assertCount(1, $middlewares);
self::assertInstanceOf(CryptographyMiddleware::class, $middlewares[0]);
$metadataEnrichers = $builder->metadataEnrichers();
self::assertCount(1, $metadataEnrichers);
self::assertInstanceOf(CryptographyMetadataEnricher::class, $metadataEnrichers[0]);
}
public function testConfigureWithLegacyMetadataMapping(): void
{
$builder = new StackHydratorBuilder();
$cryptographer = $this->createMock(Cryptographer::class);
$extension = new CryptographyExtension($cryptographer, legacyMetadataMapping: true);
$extension->configure($builder);
$metadataEnrichers = $builder->metadataEnrichers();
self::assertCount(2, $metadataEnrichers);
self::assertInstanceOf(CryptographyMetadataEnricher::class, $metadataEnrichers[0]);
self::assertInstanceOf(LegacyCryptographyMetadataEnricher::class, $metadataEnrichers[1]);
}
public function testConfigureWithLegacyCryptographerAndMetadataMapping(): void
{
$builder = new StackHydratorBuilder();
$cryptographer = $this->createMock(Cryptographer::class);
$legacyCryptographer = $this->createMock(PayloadCryptographer::class);
$extension = new CryptographyExtension($cryptographer, $legacyCryptographer, true);
$extension->configure($builder);
$middlewares = $builder->middlewares();
self::assertCount(2, $middlewares);
self::assertInstanceOf(LegacyCryptographyDecryptMiddleware::class, $middlewares[0]);
self::assertInstanceOf(CryptographyMiddleware::class, $middlewares[1]);
$metadataEnrichers = $builder->metadataEnrichers();
self::assertCount(2, $metadataEnrichers);
self::assertInstanceOf(CryptographyMetadataEnricher::class, $metadataEnrichers[0]);
self::assertInstanceOf(LegacyCryptographyMetadataEnricher::class, $metadataEnrichers[1]);
}
}