Completed
Push — dev/store-tests ( 90db53...f6786d )
by Kiyotaka
05:43
created

EA10PluginCest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 200
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
dl 0
loc 200
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A _before() 0 8 1
B installFromStore() 0 83 1
B installFromLocal() 0 84 1
A tableExists() 0 4 1
A columnExists() 0 4 1
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2018 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
use Codeception\Util\Fixtures;
25
use Doctrine\ORM\EntityManager;
26
use Eccube\Entity\Plugin;
27
use Eccube\Repository\PluginRepository;
28
use Page\Admin\PluginLocalInstallPage;
29
use Page\Admin\PluginManagePage;
30
use Page\Admin\PluginSearchPage;
31
32
class EA10PluginCest
33
{
34
35
    /** @var EntityManager */
36
    private $em;
37
38
    /** @var \Doctrine\DBAL\Connection */
39
    private $conn;
40
41
    /** @var PluginRepository */
42
    private $pluginRepository;
43
44
    public function _before(\AcceptanceTester $I)
45
    {
46
        $I->loginAsAdmin();
47
48
        $this->em = Fixtures::get('entityManager');
49
        $this->conn = $this->em->getConnection();
50
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
51
    }
52
53
    public function installFromStore(\AcceptanceTester $I)
54
    {
55
        /*
56
         * インストール
57
         */
58
59
        $ManagePage = PluginSearchPage::go($I)
60
            ->入手する('SamplePayment')
61
            ->インストール();
62
63
        $I->assertFalse($this->tableExists('plg_sample_payment_config'));
64
        $I->assertFalse($this->columnExists('dtb_customer', 'sample_payment_cards'));
65
66
        $Plugin = $this->pluginRepository->findByCode('SamplePayment');
67
        $I->assertFalse($Plugin->isInitialized(), '初期化されていない');
68
        $I->assertFalse($Plugin->isEnabled(), '有効化されていない');
69
70
        /*
71
         * 有効化
72
         */
73
        $ManagePage->ストアプラグイン_有効化('SamplePayment');
74
75
        $I->see('「EC-CUBE Payment Sample Plugin」を有効にしました。', PluginManagePage::完了メーッセージ);
76
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
77
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
78
79
80
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 66 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
81
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
82
        $I->assertTrue($Plugin->isEnabled(), '有効化されている');
83
84
        /*
85
         * 無効化
86
         */
87
        $ManagePage->ストアプラグイン_無効化('SamplePayment');
88
89
        $I->see('「EC-CUBE Payment Sample Plugin」を無効にしました。', PluginManagePage::完了メーッセージ);
90
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
91
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
92
93
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 66 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
94
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
95
        $I->assertFalse($Plugin->isEnabled(), '無効化されている');
96
97
        /*
98
         * 再度有効化
99
         */
100
        $ManagePage->ストアプラグイン_有効化('SamplePayment');
101
102
        $I->see('「EC-CUBE Payment Sample Plugin」を有効にしました。', PluginManagePage::完了メーッセージ);
103
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
104
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
105
106
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 66 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
107
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
108
        $I->assertTrue($Plugin->isEnabled(), '有効化されている');
109
110
111
        /*
112
         * 再度無効化
113
         */
114
        $ManagePage->ストアプラグイン_無効化('SamplePayment');
115
116
        $I->see('「EC-CUBE Payment Sample Plugin」を無効にしました。', PluginManagePage::完了メーッセージ);
117
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
118
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
119
120
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 66 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
121
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
122
        $I->assertFalse($Plugin->isEnabled(), '無効化されている');
123
124
        /*
125
         * 削除
126
         */
127
        $ManagePage->ストアプラグイン_削除('SamplePayment');
128
129
        $I->assertFalse($this->tableExists('plg_sample_payment_config'));
130
        $I->assertFalse($this->columnExists('dtb_customer', 'sample_payment_cards'));
131
132
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 66 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
133
        $Plugin = $this->pluginRepository->findByCode('SamplePayment');
134
        $I->assertNull($Plugin);
135
    }
136
137
    public function installFromLocal(\AcceptanceTester $I)
138
    {
139
        /*
140
         * インストール
141
         */
142
        $ManagePage = PluginLocalInstallPage::go($I)
143
            ->アップロード('SamplePayment-0.9.0.tgz');
144
145
        $I->see('プラグインをインストールしました。', PluginManagePage::完了メーッセージ);
146
147
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
148
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
149
150
        $Plugin = $this->pluginRepository->findByCode('SamplePayment');
151
        $I->assertTrue($Plugin->isInitialized(), '初期化されていない');
152
        $I->assertFalse($Plugin->isEnabled(), '有効化されていない');
153
154
        /*
155
         * 有効化
156
         */
157
        $ManagePage->独自プラグイン_有効化('SamplePayment');
158
159
        $I->see('「EC-CUBE Payment Sample Plugin」を有効にしました。', PluginManagePage::完了メーッセージ);
160
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
161
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
162
163
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 150 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
164
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
165
        $I->assertTrue($Plugin->isEnabled(), '有効化されている');
166
167
        /*
168
         * 無効化
169
         */
170
        $ManagePage->独自プラグイン_無効化('SamplePayment');
171
172
        $I->see('「EC-CUBE Payment Sample Plugin」を無効にしました。', PluginManagePage::完了メーッセージ);
173
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
174
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
175
176
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 150 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
177
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
178
        $I->assertFalse($Plugin->isEnabled(), '無効化されている');
179
180
        /*
181
         * 再度有効化
182
        */
183
        $ManagePage->独自プラグイン_有効化('SamplePayment');
184
185
        $I->see('「EC-CUBE Payment Sample Plugin」を有効にしました。', PluginManagePage::完了メーッセージ);
186
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
187
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
188
189
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 150 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
190
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
191
        $I->assertTrue($Plugin->isEnabled(), '有効化されている');
192
193
        /*
194
         * 再度無効化
195
         */
196
        $ManagePage->独自プラグイン_無効化('SamplePayment');
197
198
        $I->see('「EC-CUBE Payment Sample Plugin」を無効にしました。', PluginManagePage::完了メーッセージ);
199
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
200
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
201
202
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 150 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
203
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
204
        $I->assertFalse($Plugin->isEnabled(), '無効化されている');
205
206
        /*
207
         * 削除
208
         */
209
        $ManagePage->独自プラグイン_削除('SamplePayment');
210
211
        $I->see('プラグインを削除しました。', PluginManagePage::完了メーッセージ);
212
213
        $I->assertFalse($this->tableExists('plg_sample_payment_config'));
214
        $I->assertFalse($this->columnExists('dtb_customer', 'sample_payment_cards'));
215
216
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 150 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
217
        $Plugin = $this->pluginRepository->findByCode('SamplePayment');
218
        $I->assertNull($Plugin);
219
220
    }
221
222
    private function tableExists($tableName)
223
    {
224
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}';")->fetch()['count'] > 0;
225
    }
226
227
    private function columnExists($tableName, $columnName)
228
    {
229
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
230
    }
231
}