SignedProposalFactoryTest::testFromProposal()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 23

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 0
dl 32
loc 32
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\ProtoFactory;
22
23
use AmericanExpress\HyperledgerFabricClient\ProtoFactory\ChaincodeProposalPayloadFactory;
24
use AmericanExpress\HyperledgerFabricClient\ProtoFactory\ChannelHeaderFactory;
25
use AmericanExpress\HyperledgerFabricClient\ProtoFactory\HeaderFactory;
26
use AmericanExpress\HyperledgerFabricClient\ProtoFactory\ProposalFactory;
27
use AmericanExpress\HyperledgerFabricClient\ProtoFactory\SerializedIdentityFactory;
28
use AmericanExpress\HyperledgerFabricClient\ProtoFactory\SignatureHeaderFactory;
29
use AmericanExpress\HyperledgerFabricClient\ProtoFactory\SignedProposalFactory;
30
use Hyperledger\Fabric\Protos\Peer\SignedProposal;
31
use PHPUnit\Framework\TestCase;
32
33
/**
34
 * @covers \AmericanExpress\HyperledgerFabricClient\ProtoFactory\SignedProposalFactory
35
 */
36
class SignedProposalFactoryTest extends TestCase
37
{
38 View Code Duplication
    public function testFromProposal()
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...
39
    {
40
        $serializedIdentity = SerializedIdentityFactory::fromBytes('Alice', 'Bob');
41
        $nonce = 'u58920du89f';
42
        $txId = 'MyTransactionId';
43
44
        $channelHeader = ChannelHeaderFactory::create('MyChannelId');
45
        $channelHeader->setTxId($txId);
46
47
        $header = HeaderFactory::create(SignatureHeaderFactory::create(
48
            $serializedIdentity,
49
            $nonce
50
        ), $channelHeader);
51
52
        $chaincodeProposalPayload = ChaincodeProposalPayloadFactory::fromChaincodeInvocationSpecArgs([
53
            'foo',
54
            'bar',
55
        ]);
56
57
        $proposal = ProposalFactory::create($header, $chaincodeProposalPayload->serializeToString());
58
59
        $result = SignedProposalFactory::fromProposal($proposal, 'MySignature');
60
61
        self::assertInstanceOf(SignedProposal::class, $result);
62
        self::assertContains('Alice', $result->getProposalBytes());
63
        self::assertContains('Bob', $result->getProposalBytes());
64
        self::assertContains('MyChannelId', $result->getProposalBytes());
65
        self::assertContains('MyTransactionId', $result->getProposalBytes());
66
        self::assertContains('u58920du89f', $result->getProposalBytes());
67
        self::assertContains('foo', $result->getProposalBytes());
68
        self::assertContains('bar', $result->getProposalBytes());
69
        self::assertSame('MySignature', $result->getSignature());
70
    }
71
}
72