Passed
Push — master ( 90b052...30c7a3 )
by Radosław
02:26
created

HelperTest::testNewAuction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 65
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 65
rs 9.3571
c 0
b 0
f 0
cc 1
eloc 45
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Radowoj\Yaah;
4
5
use PHPUnit\Framework\TestCase;
6
use Radowoj\Yaah\Field;
7
use SoapClient;
8
9
class HelperTest extends TestCase
10
{
11
    public function testNewAuction()
12
    {
13
        $config = $this->getMockBuilder(Config::class)
14
            ->disableOriginalConstructor()
15
            ->getMock();
16
17
        $soapClient = $this->getMockBuilder(SoapClient::class)
18
            ->disableOriginalConstructor()
19
            ->setMethods(['doQuerySysStatus', 'doLogin', 'doNewAuctionExt', 'doVerifyItem'])
20
            ->getMock();
21
22
        $soapClient->expects($this->once())
23
            ->method('doQuerySysStatus')
24
            ->willReturn((object)['verKey' => 'someVersionKey']);
25
26
        $soapClient->expects($this->once())
27
            ->method('doLogin')
28
            ->willReturn((object)['userId' => 'someUserId', 'sessionHandlePart' => 'someSessionHandlePart']);
29
30
31
32
        $apiClient = $this->getMockBuilder(Client::class)
33
            ->setConstructorArgs([$config, $soapClient])
34
            ->setMethods(['newAuctionExt', 'verifyItem'])
35
            ->getMock();
36
37
        $apiClient->expects($this->once())
38
            ->method('newAuctionExt')
39
            ->with([
40
                'fields' => [
41
                    [
42
                        'fvalueString' => 'test title',
43
                        'fid' => 1,
44
                        'fvalueInt' => 0,
45
                        'fvalueFloat' => 0,
46
                        'fvalueImage' => '',
47
                        'fvalueDate' => '',
48
                        'fvalueDatetime' => 0,
49
                        'fvalueRangeInt' => [
50
                            'fvalueRangeIntMin' => 0,
51
                            'fvalueRangeIntMax' => 0,
52
                        ],
53
                        'fvalueRangeFloat' => [
54
                            'fvalueRangeFloatMin' => 0,
55
                            'fvalueRangeFloatMax' => 0,
56
                        ],
57
                        'fvalueRangeDate' => [
58
                            'fvalueRangeDateMin' => '',
59
                            'fvalueRangeDateMax' => '',
60
                        ]
61
                    ]
62
                ],
63
                'localId' => 1
64
            ]);
65
66
        $apiClient->expects($this->once())
67
            ->method('verifyItem')
68
            ->willReturn((object)['itemId' => 1234]);
69
70
        $helper = new Helper($apiClient);
71
72
        $result = $helper->newAuction(new Auction([1 => 'test title']), 1);
73
74
        $this->assertSame(1234, $result);
75
    }
76
}
77