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\Proposal; |
22
|
|
|
|
23
|
|
|
use AmericanExpress\HyperledgerFabricClient\Proposal\Response; |
24
|
|
|
use AmericanExpress\HyperledgerFabricClient\Proposal\ResponseCollection; |
25
|
|
|
use Hyperledger\Fabric\Protos\Peer\ProposalResponse; |
26
|
|
|
use PHPUnit\Framework\TestCase; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @covers \AmericanExpress\HyperledgerFabricClient\Proposal\ResponseCollection |
30
|
|
|
*/ |
31
|
|
|
class ResponseCollectionTest extends TestCase |
32
|
|
|
{ |
33
|
|
|
public function testGetDefaults() |
34
|
|
|
{ |
35
|
|
|
$sut = new ResponseCollection(); |
36
|
|
|
|
37
|
|
|
self::assertFalse($sut->hasProposalResponses()); |
38
|
|
|
self::assertCount(0, $sut->getProposalResponses()); |
39
|
|
|
|
40
|
|
|
self::assertFalse($sut->hasExceptions()); |
41
|
|
|
self::assertCount(0, $sut->getExceptions()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGetResponses() |
45
|
|
|
{ |
46
|
|
|
$sut = new ResponseCollection([ |
47
|
|
|
Response::fromException(new \Exception()), |
48
|
|
|
Response::fromProposalResponse(new ProposalResponse()), |
49
|
|
|
Response::fromException(new \Exception()), |
50
|
|
|
Response::fromProposalResponse(new ProposalResponse()), |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
self::assertTrue($sut->hasProposalResponses()); |
54
|
|
|
self::assertCount(2, $sut->getProposalResponses()); |
55
|
|
|
|
56
|
|
|
self::assertTrue($sut->hasExceptions()); |
57
|
|
|
self::assertCount(2, $sut->getExceptions()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetSingleResponse() |
61
|
|
|
{ |
62
|
|
|
$sut = new ResponseCollection([ |
63
|
|
|
Response::fromProposalResponse(new ProposalResponse()), |
64
|
|
|
]); |
65
|
|
|
|
66
|
|
|
self::assertTrue($sut->hasProposalResponses()); |
67
|
|
|
self::assertCount(1, $sut->getProposalResponses()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testGetExceptionResponse() |
71
|
|
|
{ |
72
|
|
|
$sut = new ResponseCollection([ |
73
|
|
|
Response::fromException(new \Exception()), |
74
|
|
|
]); |
75
|
|
|
|
76
|
|
|
self::assertTrue($sut->hasExceptions()); |
77
|
|
|
self::assertCount(1, $sut->getExceptions()); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|