Test Setup Failed
Branch dev-master (287e12)
by Petr
04:25
created

RequestTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 8.16 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 8
loc 98
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A _before() 0 4 1
A _after() 0 3 1
A testBuildBasePayload() 0 15 1
B testCreateCallPayLoad() 4 27 2
B testBuildXMLPayload() 4 33 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
use P2A\YourMembership\Core\Request;
4
5
class RequestTest extends \Codeception\Test\Unit
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    /**
8
     * @var \UnitTester
9
     */
10
    protected $tester;
11
12
    protected function _before()
13
    {
14
        require_once (__DIR__ . '/../../../vendor/autoload.php'); // Autoload files using Composer autoload
15
    }
16
17
    protected function _after()
18
    {
19
    }
20
21
22
    public function testBuildBasePayload() {
23
24
        $apiKey = 'A';
25
        $saPasscode  ='B';
26
        $request = new Request($apiKey, $saPasscode);
27
28
        $xml =  $request->buildBasePayload();
29
30
        $this->assertEquals(Request::$API_VERSION, $xml->Version, 'Versions Do Not Match');
31
        $this->assertEquals($apiKey, $xml->ApiKey, 'API Key Does not Match');
32
        $this->assertEquals($saPasscode, $xml->SaPasscode,'Sa Passcode Does not match');
33
        $this->assertEquals('1', $xml->CallID, 'Call ID does not match');
34
35
        codecept_debug($xml->asXML());
36
    }
37
38
39
    public function testCreateCallPayLoad()
40
    {
41
        //Setup
42
        $apiKey = 'A';
43
        $saPasscode  ='B';
44
        $method = 'testMethod';
45
        $arguments = ['arg1' => 'value1', 'arg2' => 'value2'];
46
        $request = new Request($apiKey, $saPasscode);
47
        //Execute
48
        $xml = $request->createCallPayload($method, $arguments);
49
50
        $attributes = $xml->attributes();
51
52
        //Verify Method Signature
53
        $this->assertNotEmpty($attributes['method'], 'Call Method Incorrect');
54
        $this->assertEquals($method, $attributes['method'], 'Call Method Incorrect');
55
56
        $children = $xml->children();
57
        //Verify Method Arguments
58
        //Invert Children and Arguments because Children is not Array Iterable...
59 View Code Duplication
        foreach ($children as $key => $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
60
                $this->assertArrayHasKey($key, $arguments, 'Argument Does Not Exist');
61
                $this->assertEquals($value, $arguments[$key], 'Invalid Argument');
62
        }
63
64
        codecept_debug($xml->asXML());
65
    }
66
67
    public function testBuildXMLPayload() {
68
69
        $apiKey = 'A';
70
        $saPasscode  ='B';
71
        $method = 'testMethod';
72
        $arguments = ['arg1' => 'value1', 'arg2' => 'value2'];
73
        $request = new Request($apiKey, $saPasscode);
74
75
        $xml = $request->buildXMLPayload($method,$arguments);
76
        codecept_debug($xml->asXML());
77
        //Verify
78
        $this->assertEquals(Request::$API_VERSION, $xml->Version, 'Versions Do Not Match');
79
        $this->assertEquals($apiKey, $xml->ApiKey, 'API Key Does not Match');
80
        $this->assertEquals($saPasscode, $xml->SaPasscode,'Sa Passcode Does not match');
81
        $this->assertEquals('1', $xml->CallID, 'Call ID does not match');
82
83
84
        $attributes = $xml->Call->attributes();
85
86
        //Verify Method Signature
87
        $this->assertNotEmpty($attributes['method'], 'Call Method Incorrect');
88
        $this->assertEquals($method, $attributes['method'], 'Call Method Incorrect');
89
90
        $children = $xml->Call->children();
91
        //Verify Method Arguments
92
        //Invert Children and Arguments because Children is not Array Iterable...
93 View Code Duplication
        foreach ($children as $key => $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
94
                $this->assertArrayHasKey($key, $arguments, 'Argument Does Not Exist');
95
                $this->assertEquals($value, $arguments[$key], 'Invalid Argument');
96
        }
97
98
        codecept_debug($xml->asXML());
99
    }
100
101
102
}
103