Failed Conditions
Push — experimental/sf ( 37b3aa...cc45c1 )
by chihiro
921:05 queued 894:01
created

EA09ShippingCest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 277
Duplicated Lines 2.89 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 8
loc 277
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 8

9 Methods

Rating   Name   Duplication   Size   Complexity  
A _before() 0 6 1
A _after() 0 3 1
A shipping出荷検索() 0 16 1
A shipping出荷編集() 0 53 1
A shipping出荷削除() 0 21 1
A shipping一括発送済み更新() 0 33 1
A shipping出荷登録() 0 51 1
B shipping_出荷CSV登録() 0 75 2
A shipping_出荷CSV雛形ファイルダウンロード() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
use Codeception\Util\Fixtures;
4
use Eccube\Entity\Customer;
5
use Eccube\Entity\Order;
6
use Page\Admin\OrderEditPage;
7
use Page\Admin\ShippingCsvUploadPage;
8
use Page\Admin\ShippingEditPage;
9
use Page\Admin\ShippingManagePage;
10
11
/**
12
 * @group admin
13
 * @group admin01
14
 * @group shipping
15
 * @group ea9
16
 */
17
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...
18
{
19
    public function _before(\AcceptanceTester $I)
20
    {
21
        // すべてのテストケース実施前にログインしておく
22
        // ログイン後は管理アプリのトップページに遷移している
23
        $I->loginAsAdmin();
24
    }
25
26
    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...
27
    {
28
    }
29
30
    public function shipping出荷検索(\AcceptanceTester $I)
0 ignored issues
show
Coding Style introduced by
Method name "EA09ShippingCest::shipping出荷検索" is not in camel caps format
Loading history...
31
    {
32
        $I->getScenario()->incomplete('受注管理画面に統合');
33
        $I->wantTo('EA0901-UC01-T01(& UC01-T02, UC01-T3) 出荷検索');
34
35
        $TargetShippings = Fixtures::get('findShippings'); // Closure
36
        $Shippings = $TargetShippings();
37
        ShippingManagePage::go($I);
38
        $I->see('検索結果 : '.count($Shippings).' 件が該当しました', ShippingManagePage::$検索結果_メッセージ);
39
40
        ShippingManagePage::go($I)->検索('[email protected]');
41
        $I->see('検索結果 : 0 件が該当しました', ShippingManagePage::$検索結果_メッセージ);
42
43
        ShippingManagePage::go($I)->詳細検索_電話番号('あああ');
44
        $I->see('検索条件に誤りがあります', ShippingManagePage::$検索結果_エラーメッセージ);
45
    }
46
47
    public function shipping出荷編集(\AcceptanceTester $I)
0 ignored issues
show
Coding Style introduced by
Method name "EA09ShippingCest::shipping出荷編集" is not in camel caps format
Loading history...
48
    {
49
        $I->getScenario()->incomplete('受注管理画面に統合');
50
        $I->wantTo('EA0901-UC03-T01(& UC03-T02) 出荷編集');
51
52
        $I->getScenario()->skip('お届け日を編集時にJSが走らない問題がありskip');
53
54
        $I->resetEmails();
55
56
        $TargetShippings = Fixtures::get('findShippings'); // Closure
57
        $Shippings = $TargetShippings();
58
        $ShippingListPage = ShippingManagePage::go($I);
59
        $I->see('検索結果 : '.count($Shippings).' 件が該当しました', ShippingManagePage::$検索結果_メッセージ);
60
61
        /* 編集 */
62
        $ShippingListPage->一覧_編集(1);
63
64
        $ShippingRegisterPage = ShippingEditPage::at($I)
65
            ->お届け先編集()
66
            ->入力_姓('')
67
            ->出荷情報登録();
68
69
        /* 異常系 */
70
        // FIXME お届け先編集が閉じてしまうため、エラーメッセージが表示されない
71
        // $I->see('入力されていません。', ShippingEditPage::$姓_エラーメッセージ);
72
73
        /* 正常系 */
74
        $ShippingRegisterPage
75
            ->お届け先編集()
76
            ->入力_姓('aaa')
77
            ->入力_セイ('アアア')
78
            ->入力_メイ('アアア')
79
            ->入力_郵便番号('060-0000')
80
            ->入力_都道府県(['1' => '北海道'])
81
            ->入力_市区町村名('bbb')
82
            ->入力_番地_ビル名('bbb')
83
            ->入力_電話番号('111-111-111')
84
            ->入力_番地_ビル名('address 2')
85
            ->出荷情報登録();
86
87
        $I->see('出荷情報を登録しました。', ShippingEditPage::$登録完了メッセージ);
88
89
        /* 出荷済みに変更 */
90
        $ShippingRegisterPage
91
            ->入力_出荷日('2018-09-04')
92
            ->出荷情報登録()
93
            ->変更を確定();
94
        $I->wait(1);
95
        $I->see('出荷情報を登録しました。', ShippingEditPage::$登録完了メッセージ);
96
97
        $I->wait(3);
98
        $I->seeEmailCount(2);
99
    }
100
101
    public function shipping出荷削除(\AcceptanceTester $I)
0 ignored issues
show
Coding Style introduced by
Method name "EA09ShippingCest::shipping出荷削除" is not in camel caps format
Loading history...
102
    {
103
        $I->getScenario()->incomplete('受注管理画面に統合');
104
        $I->wantTo('EA0901-UC04-T01(& UC04-T02) 出荷削除');
105
106
        $TargetShippings = Fixtures::get('findShippings'); // Closure
107
        $Shippings = $TargetShippings();
108
        $ShippingListPage = ShippingManagePage::go($I);
109
        $I->see('検索結果 : '.count($Shippings).' 件が該当しました', ShippingManagePage::$検索結果_メッセージ);
110
111
        // 削除
112
        $ShippingListPage->一覧_チェックボックス(1);
113
        $ShippingListPage->一覧_削除();
114
115
        $I->waitForElementVisible(['xpath' => '//*[@id="page_admin_shipping"]/div[1]/div[3]/div[2]/span']);
116
        $I->see('出荷情報を削除しました。', ['xpath' => '//*[@id="page_admin_shipping"]/div[1]/div[3]/div[2]/span']);
117
118
        // 削除キャンセル
119
        $ShippingListPage->一覧_チェックボックス(1);
120
        $ShippingListPage->一覧_削除キャンセル();
121
    }
122
123
    public function shipping一括発送済み更新(\AcceptanceTester $I)
0 ignored issues
show
Coding Style introduced by
Method name "EA09ShippingCest::shipping一括発送済み更新" is not in camel caps format
Loading history...
124
    {
125
        $I->getScenario()->incomplete('受注管理画面に統合');
126
        $I->wantTo('EA0902-UC01-T01 一括発送済み更新');
127
128
        // 一括操作用の受注を生成しておく
129
        $createCustomer = Fixtures::get('createCustomer');
130
        $createOrders = Fixtures::get('createOrders');
131
        $createOrders($createCustomer(), 10, array());
132
133
        $I->resetEmails();
134
135
        $config = Fixtures::get('config');
0 ignored issues
show
Unused Code introduced by
$config 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...
136
        // 未出荷にリセット
137
        $resetShippingDate = Fixtures::get('resetShippingDate'); // Closure
138
        $resetShippingDate();
139
140
        $TargetShippings = Fixtures::get('findShippings'); // Closure
141
        $Shippings = $TargetShippings();
142
        $ShippingListPage = ShippingManagePage::go($I);
143
        $I->see('検索結果 : '.count($Shippings).' 件が該当しました', ShippingManagePage::$検索結果_メッセージ);
144
145
        $ShippingListPage
146
            ->一覧_全選択()
147
            ->一括発送済み更新();
148
149
        $I->wait(5);
150
        $I->waitForElementVisible(['xpath' => '//*[@id="sentUpdateModal"]/div/div/div[2]/p']);
151
        $I->see('処理完了。10件のメールを送信しました', ['xpath' => '//*[@id="sentUpdateModal"]/div/div/div[2]/p']);
152
        $I->seeEmailCount(20);
153
154
        $I->click(['id' => 'bulkChangeComplete']);
155
    }
156
157
    public function shipping出荷登録(\AcceptanceTester $I)
0 ignored issues
show
Coding Style introduced by
Method name "EA09ShippingCest::shipping出荷登録" is not in camel caps format
Loading history...
158
    {
159
        $I->getScenario()->incomplete('受注管理画面に統合');
160
        $I->wantTo('EA0903-UC01-T01(& UC01-T02) 出荷登録');
161
162
        $OrderRegisterPage = OrderEditPage::go($I)->受注情報登録();
163
164
        /* 正常系 */
165
        $OrderRegisterPage
166
            ->入力_受注ステータス(['1' => '新規受付'])
167
            ->入力_姓('order1')
168
            ->入力_名('order1')
169
            ->入力_セイ('アアア')
170
            ->入力_メイ('アアア')
171
            ->入力_郵便番号('060-0000')
172
            ->入力_都道府県(['1' => '北海道'])
173
            ->入力_市区町村名('bbb')
174
            ->入力_番地_ビル名('bbb')
175
            ->入力_Eメール('[email protected]')
176
            ->入力_電話番号('111-111-111')
177
            ->商品検索('パーコレーター')
178
            ->商品検索結果_選択(1)
179
            ->入力_支払方法(['4'=> '郵便振替'])
180
            ->受注情報登録();
181
182
        $ShippingRegisterPage = ShippingEditPage::go($I)->出荷情報登録();
183
184
        /* 異常系 */
185
        $I->dontSee('出荷情報を保存しました。', ShippingEditPage::$登録完了メッセージ);
186
187
188
        /* 正常系 */
189
        $ShippingRegisterPage
190
            ->入力_姓('shipping1')
191
            ->入力_名('shipping1')
192
            ->入力_セイ('アアア')
193
            ->入力_メイ('アアア')
194
            ->入力_郵便番号('060-0000')
195
            ->入力_都道府県(['1' => '北海道'])
196
            ->入力_市区町村名('bbb')
197
            ->入力_番地_ビル名('bbb')
198
            ->入力_電話番号('111-111-111')
199
            ->入力_出荷伝票番号('1111-1111-1111')
200
            ->入力_配送業者([1 => 'サンプル業者'])
201
            ->入力_配達用メモ('メモ')
202
            ->商品検索()
203
            ->商品検索結果_選択(1)
204
            ->出荷情報登録();
205
206
        $I->see('出荷情報を登録しました。', ShippingEditPage::$登録完了メッセージ);
207
    }
208
209
    public function shipping_出荷CSV登録(\AcceptanceTester $I)
0 ignored issues
show
Coding Style introduced by
Method name "EA09ShippingCest::shipping_出荷CSV登録" is not in camel caps format
Loading history...
210
    {
211
        $I->wantTo('EA0903-UC04-T01 出荷CSV登録');
212
213
        /* @var Customer $Customer */
214
        $Customer = (Fixtures::get('createCustomer'))();
215
        /* @var Order[] $Orders */
216
        $Orders = (Fixtures::get('createOrders'))($Customer, 3);
217
218
        /*
219
         * 出荷再検索 出荷日/伝票番号が登録されていないことを確認
220
         */
221
222
        $ShippingManagePage = ShippingManagePage::go($I)
223
            ->詳細検索設定()
224
            ->入力_ご注文者お名前($Customer->getName01().$Customer->getName02())
225
            ->入力_ご注文者お名前フリガナ($Customer->getKana01().$Customer->getKana02())
226
            ->検索();
227
228
        $I->see('検索結果 : 3 件が該当しました', ShippingManagePage::$検索結果_メッセージ);
229
230
        $I->assertEquals('未登録', $ShippingManagePage->取得_出荷伝票番号(1));
231
        $I->assertEquals('未登録', $ShippingManagePage->取得_出荷伝票番号(2));
232
        $I->assertEquals('未登録', $ShippingManagePage->取得_出荷伝票番号(3));
233
        $I->assertEquals('-', $ShippingManagePage->取得_出荷日(1));
234
        $I->assertEquals('-', $ShippingManagePage->取得_出荷日(2));
235
        $I->assertEquals('-', $ShippingManagePage->取得_出荷日(3));
236
237
        /*
238
         * 出荷CSV登録
239
         */
240
241
        $csv = implode(PHP_EOL, [
242
            '出荷ID,出荷伝票番号,出荷日',
243
            $Orders[0]->getShippings()[0]->getId().',00001,2018-01-01',
244
            $Orders[1]->getShippings()[0]->getId().',00002,2018-02-02',
245
            $Orders[2]->getShippings()[0]->getId().',00003,2018-03-03',
246
        ]);
247
248
        $csvFileName = codecept_data_dir().'/shipping.csv';
249
        file_put_contents($csvFileName, $csv);
250
251
        try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
252
253
            ShippingCsvUploadPage::go($I)
254
                ->入力_CSVファイル('shipping.csv')
255
                ->CSVアップロード();
256
257
            $I->see('出荷登録CSVファイルをアップロードしました。', ShippingCsvUploadPage::$完了メッセージ);
258
259
            /*
260
             * 出荷再検索 出荷日/伝票番号が登録されたことを確認
261
             */
262
263
            $ShippingManagePage = ShippingManagePage::go($I)
264
                ->詳細検索設定()
265
                ->入力_ご注文者お名前($Customer->getName01().$Customer->getName02())
266
                ->入力_ご注文者お名前フリガナ($Customer->getKana01().$Customer->getKana02())
267
                ->検索();
268
269
            $I->see('検索結果 : 3 件が該当しました', ShippingManagePage::$検索結果_メッセージ);
270
271
            $I->assertEquals('00003', $ShippingManagePage->取得_出荷伝票番号(1));
272
            $I->assertEquals('00002', $ShippingManagePage->取得_出荷伝票番号(2));
273
            $I->assertEquals('00001', $ShippingManagePage->取得_出荷伝票番号(3));
274
            $I->assertEquals('2018/03/03', $ShippingManagePage->取得_出荷日(1));
275
            $I->assertEquals('2018/02/02', $ShippingManagePage->取得_出荷日(2));
276
            $I->assertEquals('2018/01/01', $ShippingManagePage->取得_出荷日(3));
277
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
278
        } finally {
279
            if (file_exists($csvFileName)) {
280
                unlink($csvFileName);
281
            }
282
        }
283
    }
284
285 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...
Coding Style introduced by
Method name "EA09ShippingCest::shipping_出荷CSV雛形ファイルダウンロード" is not in camel caps format
Loading history...
286
    {
287
        $I->wantTo('EA0093-UC04-T02 出荷CSV雛形ファイルのダウンロード');
288
289
        ShippingCsvUploadPage::go($I)->雛形ダウンロード();
290
        $csv = $I->getLastDownloadFile('/^shipping\.csv$/');
291
        $I->assertEquals(mb_convert_encoding(file_get_contents($csv), 'UTF-8', 'Shift_JIS'), '出荷ID,出荷伝票番号,出荷日'.PHP_EOL);
292
    }
293
}
294