Test Failed
Pull Request — master (#46)
by Yuji
04:29
created

GetItemStockInfoRequestTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 175
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 175
rs 10
c 2
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A seller_id_is_not_set() 0 7 1
A item_code_is_not_set() 0 7 1
A it_cannot_set_seller_id_more_than_once() 0 7 1
A it_cannot_set_item_code_more_than_1000() 0 11 2
A it_cannot_set_item_code_duplicately() 0 10 1
A it_cannot_set_an_item_code_of_empty_character() 0 7 1
A it_cannot_set_an_item_code_of_100_characters_or_more() 0 7 1
1
<?php
2
3
namespace Shippinno\YahooShoppingJp\Request;
4
5
use PHPUnit\Framework\TestCase;
6
7
class GetItemStockInfoRequestTest extends TestCase
8
{
9
    /**
10
     * @test
11
     * @expectedException \LogicException
12
     * @expectedExceptionMessage seller_id is already set.
13
     */
14
    public function it_cannot_set_seller_id_more_than_once()
15
    {
16
        $request = new GetItemStockInfoRequest;
17
        $this->assertSame($request, $request->setSellerId('SELLER_ID_1'));
18
19
        $request->setSellerId('SELLER_ID_2');
20
    }
21
22
    /**
23
     * @test
24
     * @expectedException \LogicException
25
     * @expectedExceptionMessage The number of the item_code must be less than 1000.
26
     */
27
    public function it_cannot_set_item_code_more_than_1000()
28
    {
29
        $request = new GetItemStockInfoRequest;
30
        $this->assertSame($request, $request->setSellerId('VALID_SELLER_ID'));
31
32
        for ($i = 1; $i <= 1001; $i++) {
33
            $request->addItemCode('AN_ITEM_CODE_' . $i);
34
        }
35
36
        $request->getParams();
37
    }
38
39
    /**
40
     * @test
41
     * @expectedException \LogicException
42
     * @expectedExceptionMessage Some of item_code are duplicated.
43
     */
44
    public function it_cannot_set_item_code_duplicately()
45
    {
46
        $request = new GetItemStockInfoRequest;
47
        $this->assertSame($request, $request->setSellerId('VALID_SELLER_ID'));
48
49
        $request->addItemCode('AN_ITEM_CODE');
50
        $request->addItemCode('AN_ITEM_CODE');
51
52
        $request->getParams();
53
    }
54
55
    /**
56
     * @test
57
     * @expectedException \InvalidArgumentException
58
     * @expectedExceptionMessage The item_code cannot be empty.
59
     */
60
    public function it_cannot_set_an_item_code_of_empty_character()
61
    {
62
        $request = new GetItemStockInfoRequest;
63
        $this->assertSame($request, $request->setSellerId('VALID_SELLER_ID'));
64
65
        $request->addItemCode('');
66
    }
67
68
    /**
69
     * @test
70
     * @expectedException \InvalidArgumentException
71
     * @expectedExceptionMessage The item_code must be less than 99 characters.
72
     */
73
    public function it_cannot_set_an_item_code_of_100_characters_or_more()
74
    {
75
        $request = new GetItemStockInfoRequest;
76
        $this->assertSame($request, $request->setSellerId('VALID_SELLER_ID'));
77
78
        $request->addItemCode(str_repeat('a', 100));
79
    }
80
81
    /**
82
     * @test
83
     * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException
84
     * @expectedExceptionMessage seller_id is not set.
85
     */
86
    public function seller_id_is_not_set()
87
    {
88
        $request = new GetItemStockInfoRequest;
89
90
        $this->assertSame($request, $request->addItemCode('VALID-ITEM-CODE'));
91
        $request->getParams();
92
    }
93
94
    /**
95
     * @test
96
     * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException
97
     * @expectedExceptionMessage item_code is not set.
98
     */
99
    public function item_code_is_not_set()
100
    {
101
        $request = new GetItemStockInfoRequest;
102
103
        $this->assertSame($request, $request->setSellerId('valid-seller-id'));
104
        $request->getParams();
105
    }
106
107
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
108
//     * @test
109
//     */
110
//    public function seller_id_is_number_or_alphabet_lowercase_or_dash_set()
111
//    {
112
//        $request = new UpdateItemStockInfoRequest;
113
//        $this->assertSame($request, $request->setSellerId('valid-seller-id'));
114
//    }
115
116
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
117
//     * @test
118
//     */
119
//    public function item_code_and_sub_code_is_number_or_alphabet_upper_or_lowercase_or_dash_set()
120
//    {
121
//        $request = new UpdateItemStockInfoRequest;
122
//        $this->assertSame($request, $request->setItemCode('VALID-ITEM-CODE', 'SUB-CODE'));
123
//    }
124
125
//    /**
126
//     * @test
127
//     * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException
128
//     * @expectedExceptionMessage item_code error.
129
//     */
130
//    public function item_code_is_only_number_or_alphabet_upper_or_lowercase_or_dash_set()
131
//    {
132
//        $request = new UpdateItemStockInfoRequest;
133
//        $this->assertSame($request, $request->setItemCode('VALID_ITEM_CODE'));
134
//    }
135
136
//    /**
137
//     * @test
138
//     * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException
139
//     * @expectedExceptionMessage sub_code error.
140
//     */
141
//    public function sub_code_is_only_number_or_alphabet_upper_or_lowercase_or_dash_set()
142
//    {
143
//        $request = new UpdateItemStockInfoRequest;
144
//        $this->assertSame($request, $request->setItemCode('VALID-ITEM-CODE', 'SUB_CODE'));
145
//    }
146
147
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
148
//     * @test
149
//     * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException
150
//     * @expectedExceptionMessage Only number or INI can be set.
151
//     */
152
//    public function quantity_is_only_number_or_string_ini_set()
153
//    {
154
//        $request = new UpdateItemStockInfoRequest;
155
//        $this->assertSame($request, $request->setQuantity('INT'));
156
//    }
157
//    /**
158
//     * @test
159
//     */
160
//    public function allow_overdraft_is_boolean_set()
161
//    {
162
//        $request = new UpdateItemStockInfoRequest;
163
//        $this->assertSame($request, $request->setAllowOverdraft(true));
164
//    }
165
//    /**
166
//     * @test
167
//     */
168
//    public function get_params_is_set()
169
//    {
170
//        $request = new UpdateItemStockInfoRequest;
171
//        $this->assertSame($request, $request->setSellerId('valid-seller-id'));
172
//        $this->assertSame($request, $request->setItemCode('VALID-ITEM-CODE', 'SUB-CODE'));
173
//        $this->assertSame($request, $request->setQuantity(999999999));
174
//        $this->assertSame($request, $request->setAllowOverdraft(true));
175
//        $params = $request->getParams();
176
//        $this->assertSame('valid-seller-id', $params['seller_id']);
177
//        $this->assertSame('VALID-ITEM-CODE:SUB-CODE', $params['item_code']);
178
//        $this->assertSame('999999999', $params['quantity']);
179
//        $this->assertSame(1, $params['allow_overdraft']);
180
//    }
181
}
182