Failed Conditions
Pull Request — experimental/sf (#29)
by Kentaro
50:12 queued 39:05
created

EA09ShippingCest::shipping出荷編集()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 57
rs 8.9381
c 0
b 0
f 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
use Codeception\Util\Fixtures;
4
use Eccube\Entity\Customer;
5
use Eccube\Entity\Order;
6
use Eccube\Entity\Master\OrderStatus;
7
use Page\Admin\OrderEditPage;
8
use Page\Admin\OrderManagePage;
9
use Page\Admin\ShippingCsvUploadPage;
10
use Page\Admin\ShippingEditPage;
11
12
/**
13
 * @group admin
14
 * @group admin01
15
 * @group shipping
16
 * @group ea9
17
 */
18
class EA09ShippingCest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
19
{
20
    public function _before(\AcceptanceTester $I)
21
    {
22
        // すべてのテストケース実施前にログインしておく
23
        // ログイン後は管理アプリのトップページに遷移している
24
        $I->loginAsAdmin();
25
    }
26
27
    public function _after(\AcceptanceTester $I)
0 ignored issues
show
Unused Code introduced by
The parameter $I is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29
    }
30
31
    public function shipping出荷編集(\AcceptanceTester $I)
32
    {
33
        $I->wantTo('EA0901-UC03-T01(& UC03-T02) 出荷編集');
34
35
        $I->resetEmails();
36
37
        // 対応中ステータスの受注を作る
38
        $createCustomer = Fixtures::get('createCustomer');
39
        $createOrders = Fixtures::get('createOrders');
40
        $newOrders = $createOrders($createCustomer(), 1, array(), OrderStatus::IN_PROGRESS);
41
42
        $OrderListPage = OrderManagePage::go($I)->検索($newOrders[0]->getOrderNo());
43
44
        $I->see('検索結果:1件が該当しました', OrderManagePage::$検索結果_メッセージ);
45
46
        /* 編集 */
47
        $OrderListPage->一覧_編集(1);
48
49
        $OrderRegisterPage = OrderEditPage::at($I)
0 ignored issues
show
Unused Code introduced by
$OrderRegisterPage is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
50
            ->お届け先の追加();
51
52
53
        $TargetShippings = Fixtures::get('findShippings'); // Closure
54
        $Shippings = $TargetShippings();
0 ignored issues
show
Unused Code introduced by
$Shippings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
56
        $ShippingRegisterPage = ShippingEditPage::at($I)
57
            ->入力_姓('')
58
            ->出荷情報登録();
59
60
        /* 異常系 */
61
        // FIXME お届け先編集が閉じてしまうため、エラーメッセージが表示されない
62
        $I->see('入力されていません。', ShippingEditPage::$姓_エラーメッセージ);
63
64
        /* 正常系 */
65
        $ShippingRegisterPage
66
            // ->お届け先編集()
67
            ->入力_姓('aaa')
68
            ->入力_セイ('アアア')
69
            ->入力_メイ('アアア')
70
            ->入力_郵便番号('060-0000')
71
            ->入力_都道府県(['1' => '北海道'])
72
            ->入力_市区町村名('bbb')
73
            ->入力_番地_ビル名('bbb')
74
            ->入力_電話番号('111-111-111')
75
            ->入力_番地_ビル名('address 2')
76
            ->出荷情報登録();
77
78
        $I->see('出荷情報を登録しました。', ShippingEditPage::$登録完了メッセージ);
79
80
        $I->wait(10);
81
82
        // 出荷済みに変更
83
        $ShippingRegisterPage
84
            ->出荷完了にする()
85
            ->変更を確定()
86
            ->出荷日を確認();
87
    }
88
89
    public function shippingお届け先追加(\AcceptanceTester $I)
90
    {
91
        $I->wantTo('EA0901-UC03-T03 お届け先追加');
92
93
        $I->resetEmails();
94
95
        // 対応中ステータスの受注を作る
96
        $createCustomer = Fixtures::get('createCustomer');
97
        $createOrders = Fixtures::get('createOrders');
98
        $newOrders = $createOrders($createCustomer(), 1, array(), OrderStatus::IN_PROGRESS);
99
100
        $OrderListPage = OrderManagePage::go($I)->検索($newOrders[0]->getOrderNo());
101
102
        $I->see('検索結果:1件が該当しました', OrderManagePage::$検索結果_メッセージ);
103
104
        /* 編集 */
105
        $OrderListPage->一覧_編集(1);
106
107
        $OrderRegisterPage = OrderEditPage::at($I)
0 ignored issues
show
Unused Code introduced by
$OrderRegisterPage is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
108
            ->お届け先の追加();
109
110
111
        $TargetShippings = Fixtures::get('findShippings'); // Closure
112
        $Shippings = $TargetShippings();
0 ignored issues
show
Unused Code introduced by
$Shippings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
113
114
        $ShippingRegisterPage = ShippingEditPage::at($I);
115
        $ShippingRegisterPage
116
            ->出荷先を追加();
117
118
        /* 正常系 */
119
        $ShippingRegisterPage
120
            // ->お届け先編集()
121
            ->入力_姓('aaa', 1)
122
            ->入力_名('bbb', 1)
123
            ->入力_セイ('アアア', 1)
124
            ->入力_メイ('アアア', 1)
125
            ->入力_郵便番号('060-0000', 1)
126
            ->入力_都道府県(['1' => '北海道'], 1)
127
            ->入力_市区町村名('bbb', 1)
128
            ->入力_番地_ビル名('bbb', 1)
129
            ->入力_電話番号('111-111-111', 1)
130
            ->入力_番地_ビル名('address 2', 1)
131
            ->出荷情報登録();
132
133
        $I->see('出荷情報を登録しました。', ShippingEditPage::$登録完了メッセージ);
134
135
        $I->wait(10);
136
        // 出荷済みに変更
137
        $ShippingRegisterPage
138
            ->出荷完了にする()
139
            ->変更を確定()
140
            ->出荷日を確認();
141
142
        // 出荷済みに変更
143
        $ShippingRegisterPage
144
            ->出荷完了にする(1)
145
            ->変更を確定(1);
0 ignored issues
show
Unused Code introduced by
The call to ShippingEditPage::変更を確定() has too many arguments starting with 1.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
146
        // TODO ステータス変更スキップしました
147
148
    }
149
150
    public function shipping_出荷CSV登録(\AcceptanceTester $I)
151
    {
152
        $I->wantTo('EA0903-UC04-T01 出荷CSV登録');
153
154
        $entityManager = Fixtures::get('entityManager');
155
        /* @var Customer $Customer */
156
        $Customer = (Fixtures::get('createCustomer'))();
157
        /* @var Order[] $Orders */
158
        $Orders = (Fixtures::get('createOrders'))($Customer, 3);
159
        // 入金済みに更新しておく
160
        $Status = $entityManager->getRepository('Eccube\Entity\Master\OrderStatus')->find(OrderStatus::PAID);
161
        foreach ($Orders as $newOrder) {
162
            $newOrder->setOrderStatus($Status);
163
        }
164
        $entityManager->flush();
165
166
        /*
167
         * 出荷再検索 出荷日/伝票番号が登録されていないことを確認
168
         */
169
170
        $OrderManagePage = OrderManagePage::go($I)
171
            ->詳細検索設定()
172
            ->入力_ご注文者お名前($Customer->getName01().$Customer->getName02())
173
            ->入力_ご注文者お名前フリガナ($Customer->getKana01().$Customer->getKana02())
174
            ->検索();
175
176
        $I->see('検索結果:3件が該当しました', OrderManagePage::$検索結果_メッセージ);
177
178
        $I->assertEmpty($OrderManagePage->取得_出荷伝票番号(1));
179
        $I->assertEmpty($OrderManagePage->取得_出荷伝票番号(2));
180
        $I->assertEmpty($OrderManagePage->取得_出荷伝票番号(3));
181
        $I->assertEquals('未発送', $OrderManagePage->取得_出荷日(1));
182
        $I->assertEquals('未発送', $OrderManagePage->取得_出荷日(2));
183
        $I->assertEquals('未発送', $OrderManagePage->取得_出荷日(3));
184
185
        /*
186
         * 出荷CSV登録
187
         */
188
189
        $csv = implode(PHP_EOL, [
190
            '出荷ID,出荷伝票番号,出荷日',
191
            $Orders[0]->getShippings()[0]->getId().',00001,2018-01-01',
192
            $Orders[1]->getShippings()[0]->getId().',00002,2018-02-02',
193
            $Orders[2]->getShippings()[0]->getId().',00003,2018-03-03',
194
        ]);
195
196
        $csvFileName = codecept_data_dir().'/shipping.csv';
197
        file_put_contents($csvFileName, $csv);
198
199
        try {
200
            ShippingCsvUploadPage::go($I)
201
                ->入力_CSVファイル('shipping.csv')
202
                ->CSVアップロード();
203
204
            $I->see('出荷登録CSVファイルをアップロードしました。', ShippingCsvUploadPage::$完了メッセージ);
205
206
            /*
207
             * 出荷再検索 出荷日/伝票番号が登録されたことを確認
208
             */
209
210
            $OrderManagePage = OrderManagePage::go($I)
211
            ->詳細検索設定()
212
            ->入力_ご注文者お名前($Customer->getName01().$Customer->getName02())
213
            ->入力_ご注文者お名前フリガナ($Customer->getKana01().$Customer->getKana02())
214
            ->検索();
215
216
            $I->see('検索結果:3件が該当しました', OrderManagePage::$検索結果_メッセージ);
217
218
            $I->assertEquals('00003', $OrderManagePage->取得_出荷伝票番号(1));
219
            $I->assertEquals('00002', $OrderManagePage->取得_出荷伝票番号(2));
220
            $I->assertEquals('00001', $OrderManagePage->取得_出荷伝票番号(3));
221
            $I->assertEquals('2018/03/03', $OrderManagePage->取得_出荷日(1));
222
            $I->assertEquals('2018/02/02', $OrderManagePage->取得_出荷日(2));
223
            $I->assertEquals('2018/01/01', $OrderManagePage->取得_出荷日(3));
224
            $I->assertEquals('発送済み', $OrderManagePage->取得_ステータス(1));
225
            $I->assertEquals('発送済み', $OrderManagePage->取得_ステータス(2));
226
            $I->assertEquals('発送済み', $OrderManagePage->取得_ステータス(3));
227
        } finally {
228
            if (file_exists($csvFileName)) {
229
                unlink($csvFileName);
230
            }
231
        }
232
    }
233
234
    public function shipping_出荷CSV登録失敗(\AcceptanceTester $I)
235
    {
236
        $I->wantTo('EA0903-UC04-T02 出荷CSV登録失敗');
237
238
        $entityManager = Fixtures::get('entityManager');
239
        /* @var Customer $Customer */
240
        $Customer = (Fixtures::get('createCustomer'))();
241
        /* @var Order[] $Orders */
242
        $Orders = (Fixtures::get('createOrders'))($Customer, 3);
243
        // 決済処理中に更新しておく
244
        $Status = $entityManager->getRepository('Eccube\Entity\Master\OrderStatus')->find(OrderStatus::PENDING);
245
        foreach ($Orders as $newOrder) {
246
            $newOrder->setOrderStatus($Status);
247
        }
248
        $entityManager->flush();
249
250
        /*
251
         * 出荷再検索 出荷日/伝票番号が登録されていないことを確認
252
         */
253
254
        $OrderManagePage = OrderManagePage::go($I)
255
            ->詳細検索設定()
256
            ->入力_ご注文者お名前($Customer->getName01().$Customer->getName02())
257
            ->入力_ご注文者お名前フリガナ($Customer->getKana01().$Customer->getKana02())
258
            ->検索();
259
260
        $I->see('検索結果:3件が該当しました', OrderManagePage::$検索結果_メッセージ);
261
262
        $I->assertEmpty($OrderManagePage->取得_出荷伝票番号(1));
263
        $I->assertEmpty($OrderManagePage->取得_出荷伝票番号(2));
264
        $I->assertEmpty($OrderManagePage->取得_出荷伝票番号(3));
265
        $I->assertEquals('未発送', $OrderManagePage->取得_出荷日(1));
266
        $I->assertEquals('未発送', $OrderManagePage->取得_出荷日(2));
267
        $I->assertEquals('未発送', $OrderManagePage->取得_出荷日(3));
268
269
        /*
270
         * 出荷CSV登録
271
         */
272
273
        $csv = implode(PHP_EOL, [
274
            '出荷ID,出荷伝票番号,出荷日',
275
            $Orders[0]->getShippings()[0]->getId().',00001,2018-01-01',
276
            $Orders[1]->getShippings()[0]->getId().',00002,2018-02-02',
277
            $Orders[2]->getShippings()[0]->getId().',00003,2018-03-03',
278
        ]);
279
280
        $csvFileName = codecept_data_dir().'/shipping.csv';
281
        file_put_contents($csvFileName, $csv);
282
283
        try {
284
            ShippingCsvUploadPage::go($I)
285
                ->入力_CSVファイル('shipping.csv')
286
                ->CSVアップロード();
287
288
            $I->see(sprintf('%s: %s から %s へステータス変更できませんでした', $Orders[0]->getShippings()[0]->getId(), '決済処理中', '発送済み'),
289
                    '#upload_file_box__upload_error--1');
290
            $I->see(sprintf('%s: %s から %s へステータス変更できませんでした', $Orders[1]->getShippings()[0]->getId(), '決済処理中', '発送済み'),
291
                    '#upload_file_box__upload_error--2');
292
            $I->see(sprintf('%s: %s から %s へステータス変更できませんでした', $Orders[2]->getShippings()[0]->getId(), '決済処理中', '発送済み'),
293
                    '#upload_file_box__upload_error--3');
294
        } finally {
295
            if (file_exists($csvFileName)) {
296
                unlink($csvFileName);
297
            }
298
        }
299
    }
300
301 View Code Duplication
    public function shipping_出荷CSV雛形ファイルダウンロード(\AcceptanceTester $I)
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...
302
    {
303
        $I->wantTo('EA0093-UC04-T02 出荷CSV雛形ファイルのダウンロード');
304
305
        ShippingCsvUploadPage::go($I)->雛形ダウンロード();
306
        $csv = $I->getLastDownloadFile('/^shipping\.csv$/');
307
        $I->assertEquals(mb_convert_encoding(file_get_contents($csv), 'UTF-8', 'Shift_JIS'), '出荷ID,出荷伝票番号,出荷日'.PHP_EOL);
308
    }
309
}
310