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

ClassSignatureGeneratorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 47
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\ClassSignatureGenerator;
10
use ProxyManager\Signature\SignatureGeneratorInterface;
11
use Zend\Code\Generator\ClassGenerator;
12
use Zend\Code\Generator\PropertyGenerator;
13
14
/**
15
 * Tests for {@see \ProxyManager\Signature\ClassSignatureGenerator}
16
 *
17
 * @covers \ProxyManager\Signature\ClassSignatureGenerator
18
 * @group Coverage
19
 */
20
final class ClassSignatureGeneratorTest extends TestCase
21
{
22
    /** @var SignatureGeneratorInterface&MockObject */
23
    private SignatureGeneratorInterface $signatureGenerator;
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 ClassSignatureGenerator $classSignatureGenerator;
25
26
    /**
27
     * {@inheritDoc}
28
     */
29
    protected function setUp() : void
30
    {
31
        $this->signatureGenerator      = $this->createMock(SignatureGeneratorInterface::class);
32
        $this->classSignatureGenerator = new ClassSignatureGenerator($this->signatureGenerator);
33
    }
34
35
    public function testAddSignature() : void
36
    {
37
        /** @var ClassGenerator&MockObject $classGenerator */
38
        $classGenerator = $this->createMock(ClassGenerator::class);
39
40
        $classGenerator
41
            ->expects(self::once())
42
            ->method('addPropertyFromGenerator')
43
            ->with(self::callback(static function (PropertyGenerator $property) : bool {
44
                return $property->getName() === 'signaturePropertyName'
45
                    && $property->isStatic()
46
                    && $property->getVisibility() === 'private'
47
                    && $property->getDefaultValue()->getValue() === 'valid-signature';
48
            }));
49
50
        $this
51
            ->signatureGenerator
52
            ->method('generateSignature')
53
            ->with(['foo' => 'bar'])
54
            ->willReturn('valid-signature');
55
56
        $this
57
            ->signatureGenerator
58
            ->method('generateSignatureKey')
59
            ->with(['foo' => 'bar'])
60
            ->willReturn('PropertyName');
61
62
        $this->classSignatureGenerator->addSignature($classGenerator, ['foo' => 'bar']);
63
    }
64
}
65