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