Passed
Push — master ( 30c7a3...43ad44 )
by Radosław
02:25
created

HelperTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
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
    protected $config = null;
12
13
    protected $soapClient = null;
14
15
    public function setUp()
16
    {
17
        $this->config = $this->getMockBuilder(Config::class)
18
            ->disableOriginalConstructor()
19
            ->getMock();
20
21
        $this->soapClient = $this->getMockBuilder(SoapClient::class)
22
            ->disableOriginalConstructor()
23
            ->setMethods(['doQuerySysStatus', 'doLogin', 'doNewAuctionExt', 'doVerifyItem'])
24
            ->getMock();
25
26
        $this->soapClient->expects($this->once())
27
            ->method('doQuerySysStatus')
28
            ->willReturn((object)['verKey' => 'someVersionKey']);
29
30
        $this->soapClient->expects($this->once())
31
            ->method('doLogin')
32
            ->willReturn((object)['userId' => 'someUserId', 'sessionHandlePart' => 'someSessionHandlePart']);
33
34
    }
35
36
37
    public function testNewAuction()
38
    {
39
        $apiClient = $this->getMockBuilder(Client::class)
40
            ->setConstructorArgs([$this->config, $this->soapClient])
41
            ->setMethods(['newAuctionExt', 'verifyItem'])
42
            ->getMock();
43
44
        $apiClient->expects($this->once())
45
            ->method('newAuctionExt')
46
            ->with([
47
                'fields' => [
48
                    [
49
                        'fvalueString' => 'test title',
50
                        'fid' => 1,
51
                        'fvalueInt' => 0,
52
                        'fvalueFloat' => 0,
53
                        'fvalueImage' => '',
54
                        'fvalueDate' => '',
55
                        'fvalueDatetime' => 0,
56
                        'fvalueRangeInt' => [
57
                            'fvalueRangeIntMin' => 0,
58
                            'fvalueRangeIntMax' => 0,
59
                        ],
60
                        'fvalueRangeFloat' => [
61
                            'fvalueRangeFloatMin' => 0,
62
                            'fvalueRangeFloatMax' => 0,
63
                        ],
64
                        'fvalueRangeDate' => [
65
                            'fvalueRangeDateMin' => '',
66
                            'fvalueRangeDateMax' => '',
67
                        ]
68
                    ]
69
                ],
70
                'localId' => 1
71
            ]);
72
73
        $apiClient->expects($this->once())
74
            ->method('verifyItem')
75
            ->willReturn((object)['itemId' => 1234]);
76
77
        $helper = new Helper($apiClient);
78
79
        $result = $helper->newAuction(new Auction([1 => 'test title']), 1);
80
81
        $this->assertSame(1234, $result);
82
    }
83
84
    /**
85
     * @expectedException Radowoj\Yaah\Exception
86
     * @expectedExceptionMessage Auction has not been created
87
     */
88
    public function testExceptionOnInvalidNewAuctionResponse()
89
    {
90
        $apiClient = $this->getMockBuilder(Client::class)
91
            ->setConstructorArgs([$this->config, $this->soapClient])
92
            ->setMethods(['newAuctionExt', 'verifyItem'])
93
            ->getMock();
94
95
        $apiClient->expects($this->once())
96
            ->method('newAuctionExt')
97
            ->willReturn((object)['whatever' => 1]);
98
99
        $apiClient->expects($this->once())
100
            ->method('verifyItem')
101
            ->willReturn((object)['definitelyNotItemId' => 1234]);
102
103
        $helper = new Helper($apiClient);
104
        $helper->newAuction(new Auction([1 => 'test title']), 1);
105
    }
106
}
107