Test Failed
Branch develop (847a84)
by Hirofumi
07:53 queued 05:07
created

SearchOrdersRequestTest::it_sets_limit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 11
loc 11
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Shippinno\YahooShoppingJp\Request;
4
5
use DateTimeImmutable;
6
use PHPUnit\Framework\TestCase;
7
8
class SearchOrdersRequestTest extends TestCase
9
{
10
    /**
11
     * @test
12
     */
13 View Code Duplication
    public function it_sets_seller_id_and_returns_itself()
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...
14
    {
15
        $request = new SearchOrdersRequest;
16
17
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
18
        $simpleXml = simplexml_load_string($request->getParams());
19
20
        $this->assertEquals('SELLER_ID', $simpleXml->SellerId->__toString());
21
    }
22
23
    /**
24
     * @test
25
     * @expectedException \LogicException
26
     */
27
    public function it_cannot_set_seller_id_more_than_once()
28
    {
29
        $request = new SearchOrdersRequest;
30
        $this->assertSame($request, $request->setSellerId('SELLER_ID_1'));
31
32
        $request->setSellerId('SELLER_ID_2');
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function it_sets_ordered_datetime_range_and_returns_itself()
39
    {
40
        $request = new SearchOrdersRequest;
41
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
42
        $from = new DateTimeImmutable('2000-01-01 00:00:00');
43
        $to = new DateTimeImmutable('2000-01-01 00:00:01');
44
45
        $this->assertSame($request, $request->setOrderedDateTimeRange($from, $to));
46
        $simpleXml = simplexml_load_string($request->getParams());
47
48
        $this->assertEquals($from->format('YmdHis'), $simpleXml->Search->Condition->OrderTimeFrom->__toString());
49
        $this->assertEquals($to->format('YmdHis'), $simpleXml->Search->Condition->OrderTimeTo->__toString());
50
    }
51
52
    /**
53
     * @test
54
     * @expectedException \LogicException
55
     */
56
    public function it_cannot_set_ordered_datetime_range_when_to_is_earlier_than_from()
57
    {
58
        $request = new SearchOrdersRequest;
59
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
60
        $from = new DateTimeImmutable('2000-01-01 00:00:01');
61
        $to = new DateTimeImmutable('2000-01-01 00:00:00');
62
63
        $request->setOrderedDateTimeRange($from, $to);
64
    }
65
66
    /**
67
     * @test
68
     */
69
    public function it_does_not_set_ordered_datetime_range_when_null()
70
    {
71
        $request = new SearchOrdersRequest;
72
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
73
74
        $this->assertSame($request, $request->setOrderedDateTimeRange(null, new DateTimeImmutable()));
75
        $simpleXml = simplexml_load_string($request->getParams());
76
        $this->assertFalse(isset($simpleXml->Search->Condition->OrderTimeFrom));
77
78
79
        $request = new SearchOrdersRequest;
80
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
81
82
        $this->assertSame($request, $request->setOrderedDateTimeRange(new DateTimeImmutable(), null));
83
        $simpleXml = simplexml_load_string($request->getParams());
84
85
        $this->assertFalse(isset($simpleXml->Search->Condition->OrderTimeTo));
86
    }
87
88
    /**
89
     * @test
90
     * @expectedException \LogicException
91
     */
92 View Code Duplication
    public function it_cannot_set_from_of_ordered_datetime_range_more_than_once()
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...
93
    {
94
        $request = new SearchOrdersRequest;
95
        $this->assertSame($request, $request->setOrderedDateTimeRange(new DateTimeImmutable, null));
96
97
        $request->setOrderedDateTimeRange(new DateTimeImmutable, null);
98
    }
99
100
    /**
101
     * @test
102
     * @expectedException \LogicException
103
     */
104 View Code Duplication
    public function it_cannot_set_to_of_ordered_datetime_range_more_than_once()
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...
105
    {
106
        $request = new SearchOrdersRequest;
107
        $this->assertSame($request, $request->setOrderedDateTimeRange(null, new DateTimeImmutable));
108
109
        $request->setOrderedDateTimeRange(null, new DateTimeImmutable);
110
    }
111
112
    /**
113
     * @test
114
     * @expectedException \InvalidArgumentException
115
     */
116
    public function it_cannot_set_ordered_datetime_range_to_both_null()
117
    {
118
        $request = new SearchOrdersRequest;
119
120
        $request->setOrderedDateTimeRange(null, null);
121
    }
122
123
    /**
124
     * @test
125
     */
126 View Code Duplication
    public function it_sets_offset()
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...
127
    {
128
        $request = new SearchOrdersRequest;
129
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
130
131
        $request->setOffset(5);
132
        $simpleXml = simplexml_load_string($request->getParams());
133
134
        $this->assertEquals(6, $simpleXml->Search->Start->__toString());
135
136
    }
137
138
    /**
139
     * @test
140
     * @expectedException \LogicException
141
     */
142 View Code Duplication
    public function it_cannot_set_offset_more_than_once()
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...
143
    {
144
        $request = new SearchOrdersRequest;
145
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
146
        $this->assertSame($request, $request->setOffset(5));
147
148
        $request->setOffset(5);
149
    }
150
151
    /**
152
     * @test
153
     * @expectedException \InvalidArgumentException
154
     */
155
    public function it_cannot_set_offset_to_less_than_zero()
156
    {
157
        $request = new SearchOrdersRequest;
158
159
        $request->setOffset(-1);
160
    }
161
162
163
164
165
    /**
166
     * @test
167
     */
168 View Code Duplication
    public function it_sets_limit()
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...
169
    {
170
        $request = new SearchOrdersRequest;
171
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
172
173
        $request->setLimit(5);
174
        $simpleXml = simplexml_load_string($request->getParams());
175
176
        $this->assertEquals(5, $simpleXml->Search->Result->__toString());
177
178
    }
179
180
    /**
181
     * @test
182
     * @expectedException \LogicException
183
     */
184 View Code Duplication
    public function it_cannot_set_limit_more_than_once()
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...
185
    {
186
        $request = new SearchOrdersRequest;
187
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
188
        $this->assertSame($request, $request->setLimit(5));
189
190
        $request->setLimit(5);
191
    }
192
193
    /**
194
     * @test
195
     * @expectedException \InvalidArgumentException
196
     */
197
    public function it_cannot_set_limit_to_less_than_zero()
198
    {
199
        $request = new SearchOrdersRequest;
200
201
        $request->setLimit(-1);
202
    }
203
204
    /**
205
     * @test
206
     * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException
207
     */
208
    public function it_validates_that_seller_id_is_set()
209
    {
210
        $request = new SearchOrdersRequest;
211
212
        $request->getParams();
213
    }
214
}
215