Passed
Push — master ( ea2827...0aa822 )
by Radosław
13:02
created

ClientTest::getPlainPasswordConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Radowoj\Yaah;
4
5
use PHPUnit\Framework\TestCase;
6
use Radowoj\Yaah\Config;
7
use Radowoj\Yaah\Client;
8
9
use SoapClient;
10
11
class ClientTest extends TestCase
12
{
13
14
    protected $defaultConfigParams = [
15
        'apiKey' => 'some api key',
16
        'login' => 'someLogin',
17
        'passwordHash' => 'passwordHash',
18
        'isSandbox' => true,
19
        'countryCode' => 1,
20
    ];
21
22
23
    protected function getConfig()
24
    {
25
        return new Config($this->defaultConfigParams);
26
    }
27
28
    protected function getPlainPasswordConfig()
29
    {
30
        $params = $this->defaultConfigParams;
31
        $params['passwordHash'] = '';
32
33
        $config = new Config($params);
34
        $config->setPasswordPlain('somePasswordPlain');
35
        return $config;
36
    }
37
38
39 View Code Duplication
    public function testLoginEncFlow()
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...
40
    {
41
        $config = $this->getConfig();
42
43
        $soapClient = $this->getMockBuilder(SoapClient::class)
44
            ->disableOriginalConstructor()
45
            ->setMethods(['doLoginEnc', 'doQuerySysStatus', 'doSomethingAfterLogin'])
46
            ->getMock();
47
48
        //Allegro version key should be requested for first login per request
49
        $soapClient->expects($this->once())
50
            ->method('doQuerySysStatus')
51
            ->willReturn((object)['verKey' => 'someVersionKey']);
52
53
        //login
54
        $soapClient->expects($this->once())
55
            ->method('doLoginEnc')
56
            ->willReturn((object)['sessionHandlePart' => 'foo', 'userId' => 'bar']);
57
58
        $client = new Client($config, $soapClient);
59
60
        //check session handle
61
        $soapClient->expects($this->once())
62
            ->method('doSomethingAfterLogin')
63
            ->with($this->equalTo([
64
                'webapiKey' => $this->defaultConfigParams['apiKey'],
65
                'localVersion' => 'someVersionKey',
66
                'countryId' => $this->defaultConfigParams['countryCode'],
67
                'sessionId' => 'foo',
68
                'countryCode' => $this->defaultConfigParams['countryCode'],
69
                'sessionHandle' => 'foo',
70
                'someFakeRequestParam' => 'someFakeRequestValue'
71
            ]));
72
73
        $client->somethingAfterLogin(['someFakeRequestParam' => 'someFakeRequestValue']);
0 ignored issues
show
Documentation Bug introduced by
The method somethingAfterLogin does not exist on object<Radowoj\Yaah\Client>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
74
    }
75
76
77 View Code Duplication
    public function testLoginFlow()
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...
78
    {
79
        $config = $this->getPlainPasswordConfig();
80
81
        $soapClient = $this->getMockBuilder(SoapClient::class)
82
            ->disableOriginalConstructor()
83
            ->setMethods(['doLogin', 'doQuerySysStatus', 'doSomethingAfterLogin'])
84
            ->getMock();
85
86
        //Allegro version key should be requested for first login per request
87
        $soapClient->expects($this->once())
88
            ->method('doQuerySysStatus')
89
            ->willReturn((object)['verKey' => 'someVersionKey']);
90
91
        //login
92
        $soapClient->expects($this->once())
93
            ->method('doLogin')
94
            ->willReturn((object)['sessionHandlePart' => 'foo', 'userId' => 'bar']);
95
96
        $client = new Client($config, $soapClient);
97
98
        //check session handle
99
        $soapClient->expects($this->once())
100
            ->method('doSomethingAfterLogin')
101
            ->with($this->equalTo([
102
                'webapiKey' => $this->defaultConfigParams['apiKey'],
103
                'localVersion' => 'someVersionKey',
104
                'countryId' => $this->defaultConfigParams['countryCode'],
105
                'sessionId' => 'foo',
106
                'countryCode' => $this->defaultConfigParams['countryCode'],
107
                'sessionHandle' => 'foo',
108
                'someFakeRequestParam' => 'someFakeRequestValue'
109
            ]));
110
111
        $client->somethingAfterLogin(['someFakeRequestParam' => 'someFakeRequestValue']);
0 ignored issues
show
Documentation Bug introduced by
The method somethingAfterLogin does not exist on object<Radowoj\Yaah\Client>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
112
    }
113
114
115
    /**
116
     * @expectedException Radowoj\Yaah\Exception
117
     * @expectedExceptionMessage Invalid WebAPI doLogin[Enc]() response
118
     */
119 View Code Duplication
    public function testExceptionOnInvalidLoginResponseMissingUserId()
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...
120
    {
121
        $config = $this->getConfig();
122
123
        $soapClient = $this->getMockBuilder(SoapClient::class)
124
            ->disableOriginalConstructor()
125
            ->setMethods(['doLoginEnc', 'doQuerySysStatus', 'doSomethingAfterLogin'])
126
            ->getMock();
127
128
        //Allegro version key should be requested for first login per request
129
        $soapClient->expects($this->once())
130
            ->method('doQuerySysStatus')
131
            ->willReturn((object)['verKey' => 'someVersionKey']);
132
133
        //login
134
        $soapClient->expects($this->once())
135
            ->method('doLoginEnc')
136
            ->willReturn((object)['sessionHandlePart' => 'foo']);
137
138
        $client = new Client($config, $soapClient);
0 ignored issues
show
Unused Code introduced by
$client is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
139
    }
140
141
142
    /**
143
     * @expectedException Radowoj\Yaah\Exception
144
     * @expectedExceptionMessage Invalid WebAPI doLogin[Enc]() response
145
     */
146 View Code Duplication
    public function testExceptionOnInvalidLoginResponseMissingSessionHandlePart()
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...
147
    {
148
        $config = $this->getConfig();
149
150
        $soapClient = $this->getMockBuilder(SoapClient::class)
151
            ->disableOriginalConstructor()
152
            ->setMethods(['doLoginEnc', 'doQuerySysStatus', 'doSomethingAfterLogin'])
153
            ->getMock();
154
155
        //Allegro version key should be requested for first login per request
156
        $soapClient->expects($this->once())
157
            ->method('doQuerySysStatus')
158
            ->willReturn((object)['verKey' => 'someVersionKey']);
159
160
        //login
161
        $soapClient->expects($this->once())
162
            ->method('doLoginEnc')
163
            ->willReturn((object)['userId' => 'bar']);
164
165
        $client = new Client($config, $soapClient);
0 ignored issues
show
Unused Code introduced by
$client is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
166
    }
167
168
169
    /**
170
     * @expectedException Radowoj\Yaah\Exception
171
     * @expectedExceptionMessage Invalid WebAPI doQuerySysStatus() response
172
     */
173
    public function testExceptionOnInvalidQuerySysStatusResponse()
174
    {
175
        $config = $this->getConfig();
176
177
        $soapClient = $this->getMockBuilder(SoapClient::class)
178
            ->disableOriginalConstructor()
179
            ->setMethods(['doQuerySysStatus', 'doSomethingAfterLogin'])
180
            ->getMock();
181
182
        //Allegro version key should be requested for first login per request
183
        $soapClient->expects($this->once())
184
            ->method('doQuerySysStatus')
185
            ->willReturn((object)['trololo' => 'thisIsNotAVersionKey']);
186
187
        $client = new Client($config, $soapClient);
0 ignored issues
show
Unused Code introduced by
$client is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
188
    }
189
190
191
192
}
193