Completed
Push — master ( fe4d16...77dac1 )
by Florian
26:03
created

DatabaseTest::testGetOldAddressStatus()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2017 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Test\Unit\Helper;
28
29
use Payone\Core\Helper\Database;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Store\Model\StoreManagerInterface;
32
use Magento\Store\Api\Data\StoreInterface;
33
use Magento\Framework\App\Helper\Context;
34
use Magento\Framework\App\Config\ScopeConfigInterface;
35
use Magento\Framework\App\ResourceConnection;
36
use Magento\Framework\DB\Adapter\AdapterInterface;
37
use Magento\Quote\Model\Quote\Address;
38
39
class DatabaseTest extends \PHPUnit_Framework_TestCase
40
{
41
    /**
42
     * @var ObjectManager
43
     */
44
    private $objectManager;
45
46
    /**
47
     * @var Database
48
     */
49
    private $database;
50
51
    /**
52
     * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
53
     */
54
    private $scopeConfig;
55
56
    /**
57
     * @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
58
     */
59
    private $connection;
60
61
    /**
62
     * @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
63
     */
64
    private $databaseResource;
65
66
    protected function setUp()
67
    {
68
        $this->objectManager = new ObjectManager($this);
69
70
        $this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock();
71
        $context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]);
72
73
        $store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock();
74
        $store->method('getId')->willReturn(15);
75
76
        $storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock();
77
        $storeManager->method('getStore')->willReturn($store);
78
79
        $this->connection = $this->getMockBuilder(AdapterInterface::class)->disableOriginalConstructor()->getMock();
80
81
        $this->databaseResource = $this->getMockBuilder(ResourceConnection::class)->disableOriginalConstructor()->getMock();
82
        $this->databaseResource->method('getConnection')->willReturn($this->connection);
83
84
        $this->database = $this->objectManager->getObject(Database::class, [
85
            'context' => $context,
86
            'storeManager' => $storeManager,
87
            'databaseResource' => $this->databaseResource
88
        ]);
89
    }
90
91 View Code Duplication
    public function testGetStateByStatus()
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...
92
    {
93
        $expected = 'complete';
94
95
        $this->databaseResource->method('getTableName')->willReturn('sales_order_status_state');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\App\ResourceConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
96
        $this->connection->method('fetchOne')->willReturn($expected);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework...apter\AdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
98
        $result = $this->database->getStateByStatus($expected);
99
        $this->assertEquals($expected, $result);
100
    }
101
102 View Code Duplication
    public function testGetOrderIncrementIdByTxid()
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...
103
    {
104
        $expected = '000000123';
105
106
        $this->databaseResource->method('getTableName')->willReturn('payone_protocol_api');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\App\ResourceConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
107
        $this->connection->method('fetchOne')->willReturn($expected);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework...apter\AdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
109
        $result = $this->database->getOrderIncrementIdByTxid('200001234');
110
        $this->assertEquals($expected, $result);
111
    }
112
113
    public function testGetModuleInfo()
114
    {
115
        $expected = [
116
            ['module' => 'Test_Module', 'schema_version' => '1.2.3'],
117
            ['module' => 'Another_Module', 'schema_version' => '2.1.7']
118
        ];
119
120
        $this->databaseResource->method('getTableName')->willReturn('setup_module');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\App\ResourceConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
121
        $this->connection->method('fetchAll')->willReturn($expected);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework...apter\AdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
122
123
        $result = $this->database->getModuleInfo();
124
        $this->assertEquals($expected, $result);
125
    }
126
127 View Code Duplication
    public function testGetIncrementIdByOrderId()
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...
128
    {
129
        $expected = '000000001';
130
131
        $this->databaseResource->method('getTableName')->willReturn('sales_order');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\App\ResourceConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
132
        $this->connection->method('fetchOne')->willReturn($expected);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework...apter\AdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
133
134
        $result = $this->database->getIncrementIdByOrderId('1');
135
        $this->assertEquals($expected, $result);
136
    }
137
138 View Code Duplication
    public function testGetPayoneUserIdByCustNr()
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...
139
    {
140
        $expected = '15';
141
142
        $this->databaseResource->method('getTableName')->willReturn('payone_protocol_transactionstatus');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\App\ResourceConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
143
        $this->connection->method('fetchOne')->willReturn($expected);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework...apter\AdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
144
145
        $result = $this->database->getPayoneUserIdByCustNr('803');
146
        $this->assertEquals($expected, $result);
147
    }
148
149 View Code Duplication
    public function testGetSequenceNumber()
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...
150
    {
151
        $expected = 38;
152
153
        $this->databaseResource->method('getTableName')->willReturn('payone_protocol_transactionstatus');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\App\ResourceConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
        $this->connection->method('fetchOne')->willReturn($expected - 1);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework...apter\AdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
155
156
        $result = $this->database->getSequenceNumber('1207');
157
        $this->assertEquals($expected, $result);
158
    }
159
160 View Code Duplication
    public function testGetSequenceNumberNull()
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...
161
    {
162
        $expected = 0;
163
164
        $this->databaseResource->method('getTableName')->willReturn('payone_protocol_transactionstatus');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\App\ResourceConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
165
        $this->connection->method('fetchOne')->willReturn(null);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework...apter\AdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
166
167
        $result = $this->database->getSequenceNumber('1207');
168
        $this->assertEquals($expected, $result);
169
    }
170
171 View Code Duplication
    public function testGetConfigParamWithoutCache()
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...
172
    {
173
        $expected = '17123';
174
175
        $this->databaseResource->method('getTableName')->willReturn('payone_protocol_transactionstatus');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\App\ResourceConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
176
        $this->connection->method('fetchOne')->willReturn($expected);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework...apter\AdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
177
178
        $result = $this->database->getConfigParamWithoutCache('mid');
179
        $this->assertEquals($expected, $result);
180
    }
181
182
    public function testGetOldAddressStatus()
183
    {
184
        $expected = 'G';
185
186
        $address = $this->getMockBuilder(Address::class)
187
            ->disableOriginalConstructor()
188
            ->setMethods(['getFirstname', 'getLastname', 'getStreet', 'getCity', 'getRegion', 'getPostcode', 'getCountryId', 'getId', 'getCustomerId', 'getAddressType'])
189
            ->getMock();
190
        $address->method('getFirstname')->willReturn('Paul');
191
        $address->method('getLastname')->willReturn('Payer');
192
        $address->method('getStreet')->willReturn(['Teststr. 3']);
193
        $address->method('getCity')->willReturn('Paycity');
194
        $address->method('getRegion')->willReturn('Bremen');
195
        $address->method('getPostcode')->willReturn('12345');
196
        $address->method('getCountryId')->willReturn('DE');
197
        $address->method('getId')->willReturn('5');
198
        $address->method('getCustomerId')->willReturn('18');
199
        $address->method('getAddressType')->willReturn('billing');
200
201
        $this->databaseResource->method('getTableName')->willReturn('quote_address');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework\App\ResourceConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
202
        $this->connection->method('fetchOne')->willReturn($expected);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Magento\Framework...apter\AdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
203
204
        $result = $this->database->getOldAddressStatus($address);
205
        $this->assertEquals($expected, $result);
206
207
        $result = $this->database->getOldAddressStatus($address, false);
208
        $this->assertEquals($expected, $result);
209
    }
210
}
211