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); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$this->sut->generateHeader($channelHeader); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGeneratorProxyReturnsHeaderFromGenerator() |
70
|
|
|
{ |
71
|
|
|
$channelHeader = new ChannelHeader(); |
72
|
|
|
|
73
|
|
|
$this->headerGenerator->method('fromChannelHeader') |
|
|
|
|
74
|
|
|
->willReturn($header = new Header()); |
75
|
|
|
|
76
|
|
|
$result = $this->sut->generateHeader($channelHeader); |
77
|
|
|
self::assertSame($header, $result); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|