testGeneratorProxyPassesIdentityToHeaderGenerator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2017 American Express Travel Related Services Company, Inc.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15
 * or implied. See the License for the specific language governing
16
 * permissions and limitations under the License.
17
 */
18
19
declare(strict_types=1);
20
21
namespace AmericanExpressTest\HyperledgerFabricClient\Identity;
22
23
use AmericanExpress\HyperledgerFabricClient\Header\HeaderGeneratorInterface;
24
use AmericanExpress\HyperledgerFabricClient\Identity\SerializedIdentityAwareHeaderGenerator;
25
use Hyperledger\Fabric\Protos\Common\ChannelHeader;
26
use Hyperledger\Fabric\Protos\Common\Header;
27
use Hyperledger\Fabric\Protos\MSP\SerializedIdentity;
28
use PHPUnit\Framework\TestCase;
29
30
/**
31
 * @covers \AmericanExpress\HyperledgerFabricClient\Identity\SerializedIdentityAwareHeaderGenerator
32
 */
33
class SerializedIdentityAwareHeaderGeneratorTest extends TestCase
34
{
35
    /**
36
     * @var SerializedIdentity $identity
37
     */
38
    private $identity;
39
40
    /**
41
     * @var HeaderGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject $headerGenerator
42
     */
43
    private $headerGenerator;
44
45
    /**
46
     * @var SerializedIdentityAwareHeaderGenerator $sut
47
     */
48
    private $sut;
49
50
    protected function setUp()
51
    {
52
        $this->identity = new SerializedIdentity();
53
        $this->headerGenerator = $this->getMockBuilder(HeaderGeneratorInterface::class)
54
            ->getMock();
55
        $this->sut = new SerializedIdentityAwareHeaderGenerator($this->identity, $this->headerGenerator);
56
    }
57
58
    public function testGeneratorProxyPassesIdentityToHeaderGenerator()
59
    {
60
        $channelHeader = new ChannelHeader();
61
62
        $this->headerGenerator->expects(self::once())
63
            ->method('fromChannelHeader')
64
            ->with($this->identity, $channelHeader);
0 ignored issues
show
Bug introduced by
$this->identity of type Hyperledger\Fabric\Protos\MSP\SerializedIdentity is incompatible with the type array expected by parameter $arguments of PHPUnit\Framework\MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
            ->with(/** @scrutinizer ignore-type */ $this->identity, $channelHeader);
Loading history...
Bug introduced by
$channelHeader of type Hyperledger\Fabric\Protos\Common\ChannelHeader is incompatible with the type array expected by parameter $arguments of PHPUnit\Framework\MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
            ->with($this->identity, /** @scrutinizer ignore-type */ $channelHeader);
Loading history...
65
66
        $this->sut->generateHeader($channelHeader);
67
    }
68
69
    public function testGeneratorProxyReturnsHeaderFromGenerator()
70
    {
71
        $channelHeader = new ChannelHeader();
72
73
        $this->headerGenerator->method('fromChannelHeader')
0 ignored issues
show
Bug introduced by
The method method() does not exist on AmericanExpress\Hyperled...eaderGeneratorInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $this->headerGenerator->/** @scrutinizer ignore-call */ 
74
                                method('fromChannelHeader')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
74
            ->willReturn($header = new Header());
75
76
        $result = $this->sut->generateHeader($channelHeader);
77
        self::assertSame($header, $result);
78
    }
79
}
80