testFromArrayThrowsExceptionOnInvalidConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 9.4285
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\Peer;
22
23
use AmericanExpress\HyperledgerFabricClient\EndorserClient\EndorserClientManagerInterface;
24
use AmericanExpress\HyperledgerFabricClient\Exception\InvalidArgumentException;
25
use AmericanExpress\HyperledgerFabricClient\Peer\Peer;
26
use AmericanExpress\HyperledgerFabricClient\Peer\PeerFactory;
27
use AmericanExpress\HyperledgerFabricClient\Peer\PeerOptions;
28
use Hyperledger\Fabric\Protos\Peer\EndorserClient;
29
use PHPUnit\Framework\TestCase;
30
31
/**
32
 * @covers \AmericanExpress\HyperledgerFabricClient\Peer\PeerFactory
33
 */
34
class PeerFactoryTest extends TestCase
35
{
36
    /**
37
     * @var EndorserClient|\PHPUnit_Framework_MockObject_MockObject
38
     */
39
    private $endorserClient;
40
41
    /**
42
     * @var EndorserClientManagerInterface|\PHPUnit_Framework_MockObject_MockObject
43
     */
44
    private $endorserClients;
45
46
    /**
47
     * @var PeerFactory
48
     */
49
    private $sut;
50
51
    protected function setUp()
52
    {
53
        $this->endorserClients = $this->getMockBuilder(EndorserClientManagerInterface::class)
54
            ->getMock();
55
56
        $this->endorserClient = $this->getMockBuilder(EndorserClient::class)
57
            ->disableOriginalConstructor()
58
            ->getMock();
59
60
        $this->sut = new PeerFactory($this->endorserClients);
61
    }
62
63 View Code Duplication
    public function testFromPeerOptions()
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...
64
    {
65
        $this->endorserClients->method('get')
0 ignored issues
show
Bug introduced by
The method method() does not exist on AmericanExpress\Hyperled...rClientManagerInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        $this->endorserClients->/** @scrutinizer ignore-call */ 
66
                                method('get')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
            ->with('localhost:8080')
67
            ->willReturn($this->endorserClient);
68
69
        $result = $this->sut->fromPeerOptions(new PeerOptions([
70
            'requests' => 'localhost:8080',
71
        ]));
72
73
        self::assertInstanceOf(Peer::class, $result);
74
    }
75
76 View Code Duplication
    public function testFromArray()
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...
77
    {
78
        $this->endorserClients->method('get')
79
            ->with('localhost:8080')
80
            ->willReturn($this->endorserClient);
81
82
        $result = $this->sut->fromArray([
83
            'requests' => 'localhost:8080',
84
        ]);
85
86
        self::assertInstanceOf(Peer::class, $result);
87
    }
88
89
    /**
90
     * @expectedException InvalidArgumentException
91
     */
92
    public function testFromArrayThrowsExceptionOnInvalidConfig()
93
    {
94
        $this->sut->fromArray([
95
            'not' => 'useful',
96
            'configuration' => 'values'
97
        ]);
98
    }
99
}
100