Passed
Pull Request — master (#3)
by Timothy
11:06 queued 05:35
created

testFromConfigWithMultipleOrganizations()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 25
rs 8.8571
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\User;
22
23
use AmericanExpress\HyperledgerFabricClient\Config\ClientConfig;
24
use AmericanExpress\HyperledgerFabricClient\Organization\OrganizationOptionsInterface;
25
use AmericanExpress\HyperledgerFabricClient\User\UserContext;
26
use AmericanExpress\HyperledgerFabricClient\User\UserContextFactory;
27
use Hyperledger\Fabric\Protos\MSP\SerializedIdentity;
28
use PHPUnit\Framework\TestCase;
29
30
/**
31
 * @covers \AmericanExpress\HyperledgerFabricClient\User\UserContextFactory
32
 */
33
class UserContextFactoryTest extends TestCase
34
{
35 View Code Duplication
    public function testFromConfig()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $config = new ClientConfig([
38
            'organizations' => [
39
                [
40
                    'name' => 'peerOrg1',
41
                    'mspid' => 'Org1MSP',
42
                    'adminCerts' => __FILE__,
43
                ],
44
            ],
45
        ]);
46
47
        $result = UserContextFactory::fromConfig($config, 'peerOrg1');
48
49
        self::assertInstanceOf(UserContext::class, $result);
50
        self::assertInstanceOf(SerializedIdentity::class, $result->getIdentity());
51
        self::assertInstanceOf(OrganizationOptionsInterface::class, $result->getOrganization());
52
        self::assertSame('peerOrg1', $result->getOrganization()->getName());
53
        self::assertSame('Org1MSP', $result->getOrganization()->getMspId());
54
        self::assertSame(__FILE__, $result->getOrganization()->getAdminCerts());
55
    }
56
57 View Code Duplication
    public function testFromConfigWithDefaultOrganization()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $config = new ClientConfig([
60
            'organizations' => [
61
                [
62
                    'name' => 'peerOrg1',
63
                    'mspid' => 'Org1MSP',
64
                    'adminCerts' => __FILE__,
65
                ],
66
            ],
67
        ]);
68
69
        $result = UserContextFactory::fromConfig($config);
70
71
        self::assertInstanceOf(UserContext::class, $result);
72
        self::assertInstanceOf(SerializedIdentity::class, $result->getIdentity());
73
        self::assertInstanceOf(OrganizationOptionsInterface::class, $result->getOrganization());
74
        self::assertSame('peerOrg1', $result->getOrganization()->getName());
75
        self::assertSame('Org1MSP', $result->getOrganization()->getMspId());
76
        self::assertSame(__FILE__, $result->getOrganization()->getAdminCerts());
77
    }
78
79
    public function testFromConfigWithMultipleOrganizations()
80
    {
81
        $config = new ClientConfig([
82
            'organizations' => [
83
                [
84
                    'name' => 'peerOrg1',
85
                    'mspid' => 'Org1MSP',
86
                    'adminCerts' => __FILE__,
87
                ],
88
                [
89
                    'name' => 'peerOrg2',
90
                    'mspid' => 'Org2MSP',
91
                    'adminCerts' => __FILE__,
92
                ],
93
            ],
94
        ]);
95
96
        $result = UserContextFactory::fromConfig($config, 'peerOrg2');
97
98
        self::assertInstanceOf(UserContext::class, $result);
99
        self::assertInstanceOf(SerializedIdentity::class, $result->getIdentity());
100
        self::assertInstanceOf(OrganizationOptionsInterface::class, $result->getOrganization());
101
        self::assertSame('peerOrg2', $result->getOrganization()->getName());
102
        self::assertSame('Org2MSP', $result->getOrganization()->getMspId());
103
        self::assertSame(__FILE__, $result->getOrganization()->getAdminCerts());
104
    }
105
106
    /**
107
     * @expectedException \AmericanExpress\HyperledgerFabricClient\Exception\UnexpectedValueException
108
     */
109 View Code Duplication
    public function testFromConfigWithInvalidOrganization()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $config = new ClientConfig([
112
            'organizations' => [
113
                [
114
                    'name' => 'peerOrg1',
115
                    'mspid' => 'Org1MSP',
116
                    'adminCerts' => __FILE__,
117
                ],
118
            ],
119
        ]);
120
121
        UserContextFactory::fromConfig($config, 'FooBar');
122
    }
123
}
124