ChannelFactoryTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateWithoutPeers() 0 11 1
A setUp() 0 12 1
A testCreateWithPeers() 0 20 1
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\Channel;
22
23
use AmericanExpress\HyperledgerFabricClient\Channel\Channel;
24
use AmericanExpress\HyperledgerFabricClient\Channel\ChannelFactory;
25
use AmericanExpress\HyperledgerFabricClient\Header\HeaderGeneratorInterface;
26
use AmericanExpress\HyperledgerFabricClient\Organization\OrganizationOptions;
27
use AmericanExpress\HyperledgerFabricClient\Peer\PeerFactoryInterface;
28
use AmericanExpress\HyperledgerFabricClient\Proposal\ProposalProcessorInterface;
29
use AmericanExpress\HyperledgerFabricClient\User\UserContext;
30
use Hyperledger\Fabric\Protos\MSP\SerializedIdentity;
31
use PHPUnit\Framework\TestCase;
32
33
/**
34
 * @covers \AmericanExpress\HyperledgerFabricClient\Channel\ChannelFactory
35
 */
36
class ChannelFactoryTest extends TestCase
37
{
38
    /**
39
     * @var ProposalProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
40
     */
41
    private $proposalProcessor;
42
43
    /**
44
     * @var PeerFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
45
     */
46
    private $peerFactory;
47
48
    /**
49
     * @var HeaderGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
50
     */
51
    private $headerGenerator;
52
53
    /**
54
     * @var ChannelFactory
55
     */
56
    private $sut;
57
58
    protected function setUp()
59
    {
60
        $this->proposalProcessor = $this->getMockBuilder(ProposalProcessorInterface::class)
61
            ->getMock();
62
63
        $this->headerGenerator = $this->getMockBuilder(HeaderGeneratorInterface::class)
64
            ->getMock();
65
66
        $this->peerFactory = $this->getMockBuilder(PeerFactoryInterface::class)
67
            ->getMock();
68
69
        $this->sut = new ChannelFactory($this->headerGenerator, $this->peerFactory);
70
    }
71
72
    public function testCreateWithPeers()
73
    {
74
        $user = new UserContext(
75
            new SerializedIdentity(),
76
            new OrganizationOptions([
77
                'peers' => [
78
                    [
79
                        'requests' => 'localhost:8000',
80
                    ],
81
                    [
82
                        'requests' => 'localhost:9000',
83
                    ],
84
                ],
85
            ])
86
        );
87
88
        $result = $this->sut->create('FooBar', $this->proposalProcessor, $user);
89
90
        self::assertInstanceOf(Channel::class, $result);
91
        self::assertCount(2, $result->getPeers());
92
    }
93
94
    public function testCreateWithoutPeers()
95
    {
96
        $user = new UserContext(
97
            new SerializedIdentity(),
98
            new OrganizationOptions()
99
        );
100
101
        $result = $this->sut->create('FooBar', $this->proposalProcessor, $user);
102
103
        self::assertInstanceOf(Channel::class, $result);
104
        self::assertCount(0, $result->getPeers());
105
    }
106
}
107