Completed
Push — master ( 3be072...ba2d3a )
by Marco
231:32 queued 209:55
created

SignatureCheckerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 75
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\Signature;
6
7
use PHPUnit\Framework\MockObject\MockObject;
8
use PHPUnit\Framework\TestCase;
9
use ProxyManager\Signature\Exception\InvalidSignatureException;
10
use ProxyManager\Signature\Exception\MissingSignatureException;
11
use ProxyManager\Signature\SignatureChecker;
12
use ProxyManager\Signature\SignatureGeneratorInterface;
13
use ReflectionClass;
14
15
/**
16
 * Tests for {@see \ProxyManager\Signature\SignatureChecker}
17
 *
18
 * @covers \ProxyManager\Signature\SignatureChecker
19
 * @group Coverage
20
 */
21
final class SignatureCheckerTest extends TestCase
22
{
23
    private string $signatureExample = 'valid-signature';
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
24
    private SignatureChecker $signatureChecker;
25
26
    /** @var SignatureGeneratorInterface&MockObject */
27
    private SignatureGeneratorInterface $signatureGenerator;
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    protected function setUp() : void
33
    {
34
        $this->signatureGenerator = $this->createMock(SignatureGeneratorInterface::class);
35
        $this->signatureChecker   = new SignatureChecker($this->signatureGenerator);
36
    }
37
38
    public function testCheckSignatureWithValidKey() : void
39
    {
40
        $this
41
            ->signatureGenerator
42
            ->expects(self::atLeastOnce())
43
            ->method('generateSignatureKey')
44
            ->with(['foo' => 'bar'])
45
            ->willReturn('Example');
46
        $this
47
            ->signatureGenerator
48
            ->expects(self::atLeastOnce())
49
            ->method('generateSignature')
50
            ->with(['foo' => 'bar'])
51
            ->willReturn('valid-signature');
52
53
        $this->signatureChecker->checkSignature(new ReflectionClass($this), ['foo' => 'bar']);
54
    }
55
56
    public function testCheckSignatureWithInvalidKey() : void
57
    {
58
        $this
59
            ->signatureGenerator
60
61
            ->method('generateSignatureKey')
62
            ->with(['foo' => 'bar'])
63
            ->willReturn('InvalidKey');
64
        $this
65
            ->signatureGenerator
66
            ->method('generateSignature')
67
            ->with(['foo' => 'bar'])
68
            ->willReturn('valid-signature');
69
70
        $this->expectException(MissingSignatureException::class);
71
72
        $this->signatureChecker->checkSignature(new ReflectionClass($this), ['foo' => 'bar']);
73
    }
74
75
    public function testCheckSignatureWithInvalidValue() : void
76
    {
77
        $this
78
            ->signatureGenerator
79
            ->method('generateSignatureKey')
80
            ->with(['foo' => 'bar'])
81
            ->willReturn('Example');
82
        $this
83
            ->signatureGenerator
84
            ->method('generateSignature')
85
            ->with(['foo' => 'bar'])
86
            ->willReturn('invalid-signature');
87
88
        $this->expectException(InvalidSignatureException::class);
89
90
        $this->signatureChecker->checkSignature(new ReflectionClass($this), ['foo' => 'bar']);
91
    }
92
}
93