|
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\Organization; |
|
22
|
|
|
|
|
23
|
|
|
use AmericanExpress\HyperledgerFabricClient\Organization\OrganizationOptions; |
|
24
|
|
|
use AmericanExpress\HyperledgerFabricClient\Peer\PeerOptionsInterface; |
|
25
|
|
|
use PHPUnit\Framework\TestCase; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @covers \AmericanExpress\HyperledgerFabricClient\Organization\OrganizationOptions |
|
29
|
|
|
*/ |
|
30
|
|
|
class OrganizationOptionsTest extends TestCase |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var OrganizationOptions |
|
34
|
|
|
*/ |
|
35
|
|
|
private $sut; |
|
36
|
|
|
|
|
37
|
|
|
protected function setUp() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->sut = new OrganizationOptions(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testName() |
|
43
|
|
|
{ |
|
44
|
|
|
self::assertNull($this->sut->getName()); |
|
45
|
|
|
|
|
46
|
|
|
$this->sut->setName('FooBar'); |
|
47
|
|
|
|
|
48
|
|
|
self::assertSame('FooBar', $this->sut->getName()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testMspId() |
|
52
|
|
|
{ |
|
53
|
|
|
self::assertNull($this->sut->getMspId()); |
|
54
|
|
|
|
|
55
|
|
|
$this->sut->setMspId('FooBar'); |
|
56
|
|
|
|
|
57
|
|
|
self::assertSame('FooBar', $this->sut->getMspId()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testCa() |
|
61
|
|
|
{ |
|
62
|
|
|
self::assertCount(0, $this->sut->getCa()); |
|
63
|
|
|
|
|
64
|
|
|
$this->sut->setCa([ |
|
65
|
|
|
'url' => 'https://localhost:7054', |
|
66
|
|
|
'name' => 'ca-org1' |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
self::assertSame([ |
|
70
|
|
|
'url' => 'https://localhost:7054', |
|
71
|
|
|
'name' => 'ca-org1' |
|
72
|
|
|
], $this->sut->getCa()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testAdminCerts() |
|
76
|
|
|
{ |
|
77
|
|
|
self::assertNull($this->sut->getAdminCerts()); |
|
78
|
|
|
|
|
79
|
|
|
$this->sut->setAdminCerts('FooBar'); |
|
80
|
|
|
|
|
81
|
|
|
self::assertSame('FooBar', $this->sut->getAdminCerts()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testPrivateKey() |
|
85
|
|
|
{ |
|
86
|
|
|
self::assertNull($this->sut->getPrivateKey()); |
|
87
|
|
|
|
|
88
|
|
|
$this->sut->setPrivateKey('FooBar'); |
|
89
|
|
|
|
|
90
|
|
|
self::assertSame('FooBar', $this->sut->getPrivateKey()); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function testPeers() |
|
94
|
|
|
{ |
|
95
|
|
|
self::assertCount(0, $this->sut->getPeers()); |
|
96
|
|
|
|
|
97
|
|
|
$this->sut->setPeers([ |
|
98
|
|
|
[ |
|
99
|
|
|
'name' => 'peer1', |
|
100
|
|
|
'requests' => 'localhost:7051', |
|
101
|
|
|
'events' => 'localhost:7053', |
|
102
|
|
|
'server-hostname' => 'peer1.org1.example.com', |
|
103
|
|
|
'tls_cacerts' => __FILE__, |
|
104
|
|
|
], |
|
105
|
|
|
[ |
|
106
|
|
|
'name' => 'peer2', |
|
107
|
|
|
'requests' => 'localhost:8051', |
|
108
|
|
|
'events' => 'localhost:8053', |
|
109
|
|
|
'server-hostname' => 'peer2.org1.example.com', |
|
110
|
|
|
'tls_cacerts' => __FILE__, |
|
111
|
|
|
], |
|
112
|
|
|
]); |
|
113
|
|
|
|
|
114
|
|
|
self::assertCount(2, $this->sut->getPeers()); |
|
115
|
|
|
self::assertInstanceOf(PeerOptionsInterface::class, $this->sut->getPeers()[0]); |
|
116
|
|
|
self::assertInstanceOf(PeerOptionsInterface::class, $this->sut->getPeers()[1]); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testFromArray() |
|
120
|
|
|
{ |
|
121
|
|
|
$sut = new OrganizationOptions([ |
|
122
|
|
|
'name' => 'peerOrg1', |
|
123
|
|
|
'mspid' => 'Org1MSP', |
|
124
|
|
|
'ca' => [ |
|
125
|
|
|
'url' => 'https://localhost:7054', |
|
126
|
|
|
'name' => 'ca-org1', |
|
127
|
|
|
], |
|
128
|
|
|
'admin_certs' => __FILE__, |
|
129
|
|
|
'private_key' => __FILE__, |
|
130
|
|
|
'peers' => [ |
|
131
|
|
|
[ |
|
132
|
|
|
'name' => 'peer1', |
|
133
|
|
|
'requests' => 'localhost:7051', |
|
134
|
|
|
'events' => 'localhost:7053', |
|
135
|
|
|
'server-hostname' => 'peer1.org1.example.com', |
|
136
|
|
|
'tls_cacerts' => __FILE__, |
|
137
|
|
|
], |
|
138
|
|
|
[ |
|
139
|
|
|
'name' => 'peer2', |
|
140
|
|
|
'requests' => 'localhost:8051', |
|
141
|
|
|
'events' => 'localhost:8053', |
|
142
|
|
|
'server-hostname' => 'peer2.org1.example.com', |
|
143
|
|
|
'tls_cacerts' => __FILE__, |
|
144
|
|
|
], |
|
145
|
|
|
], |
|
146
|
|
|
]); |
|
147
|
|
|
|
|
148
|
|
|
self::assertSame('peerOrg1', $sut->getName()); |
|
149
|
|
|
self::assertSame('Org1MSP', $sut->getMspId()); |
|
150
|
|
|
self::assertSame('https://localhost:7054', $sut->getCa()['url']); |
|
151
|
|
|
self::assertSame('ca-org1', $sut->getCa()['name']); |
|
152
|
|
|
self::assertSame(__FILE__, $sut->getAdminCerts()); |
|
153
|
|
|
self::assertSame(__FILE__, $sut->getPrivateKey()); |
|
154
|
|
|
self::assertCount(2, $sut->getPeers()); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|