Passed
Push — master ( 00ab5d...b6c1c8 )
by Radosław
02:21
created

ClientTest::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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
    public function testLoginEncFlow()
29
    {
30
        $config = $this->getConfig();
31
32
        $soapClient = $this->getMockBuilder(SoapClient::class)
33
            ->disableOriginalConstructor()
34
            ->setMethods(['doLoginEnc', 'doQuerySysStatus', 'doSomethingAfterLogin'])
35
            ->getMock();
36
37
        //Allegro version key should be requested for first login per request
38
        $soapClient->expects($this->once())
39
            ->method('doQuerySysStatus')
40
            ->willReturn((object)['verKey' => 'someVersionKey']);
41
42
        //login
43
        $soapClient->expects($this->once())
44
            ->method('doLoginEnc')
45
            ->willReturn((object)['sessionHandlePart' => 'foo', 'userId' => 'bar']);
46
47
        $client = new Client($config, $soapClient);
48
49
        //check session handle
50
        $soapClient->expects($this->once())
51
            ->method('doSomethingAfterLogin')
52
            ->with($this->equalTo([
53
                'webapiKey' => $this->defaultConfigParams['apiKey'],
54
                'localVersion' => 'someVersionKey',
55
                'countryId' => $this->defaultConfigParams['countryCode'],
56
                'sessionId' => 'foo',
57
                'countryCode' => $this->defaultConfigParams['countryCode'],
58
                'sessionHandle' => 'foo',
59
                'someFakeRequestParam' => 'someFakeRequestValue'
60
            ]));
61
62
        $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...
63
64
    }
65
}
66