testIsCreditratingNeededWrongEvent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 1
eloc 8
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\Consumerscore;
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\Store\Model\ScopeInterface;
35
use Magento\Framework\App\Config\ScopeConfigInterface;
36
use Payone\Core\Helper\Database;
37
use Magento\Quote\Model\Quote\Address;
38
use Payone\Core\Test\Unit\BaseTestCase;
39
use Payone\Core\Model\Test\PayoneObjectManager;
40
41
class ConsumerscoreTest extends BaseTestCase
42
{
43
    /**
44
     * @var ObjectManager|PayoneObjectManager
45
     */
46
    private $objectManager;
47
48
    /**
49
     * @var Consumerscore
50
     */
51
    private $consumerscore;
52
53
    /**
54
     * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
55
     */
56
    private $scopeConfig;
57
58
    /**
59
     * @var Database|\PHPUnit_Framework_MockObject_MockObject
60
     */
61
    private $databaseHelper;
62
63 View Code Duplication
    protected function setUp()
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...
64
    {
65
        $this->objectManager = $this->getObjectManager();
66
67
        $this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock();
68
        $context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]);
69
70
        $store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock();
71
        $store->method('getCode')->willReturn(null);
72
        $store->method('getId')->willReturn(5);
73
74
        $storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock();
75
        $storeManager->method('getStore')->willReturn($store);
76
77
        $this->databaseHelper = $this->getMockBuilder(Database::class)->disableOriginalConstructor()->getMock();
78
79
        $this->consumerscore = $this->objectManager->getObject(Consumerscore::class, [
80
            'context' => $context,
81
            'storeManager' => $storeManager,
82
            'databaseHelper' => $this->databaseHelper
83
        ]);
84
    }
85
86 View Code Duplication
    public function testGetConsumerscoreSampleCounterFilled()
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...
87
    {
88
        $expected = 5;
89
        $this->databaseHelper->method('getConfigParamWithoutCache')->willReturn($expected);
90
        $result = $this->consumerscore->getConsumerscoreSampleCounter();
91
        $this->assertEquals($expected, $result);
92
    }
93
94 View Code Duplication
    public function testGetConsumerscoreSampleCounterNotFilled()
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...
95
    {
96
        $expected = 0;
97
        $this->databaseHelper->method('getConfigParamWithoutCache')->willReturn(false);
98
        $result = $this->consumerscore->getConsumerscoreSampleCounter();
99
        $this->assertEquals($expected, $result);
100
    }
101
102
    public function testSetConsumerscoreSampleCounter()
103
    {
104
        $result = $this->consumerscore->setConsumerscoreSampleCounter(5);
105
        $expected = true;
106
        $this->assertEquals($expected, $result);
107
    }
108
109 View Code Duplication
    public function testIncrementConsumerscoreSampleCounter()
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...
110
    {
111
        $this->databaseHelper->method('getConfigParamWithoutCache')->willReturn(5);
112
        $result = $this->consumerscore->incrementConsumerscoreSampleCounter();
113
        $expected = 6;
114
        $this->assertEquals($expected, $result);
115
    }
116
117 View Code Duplication
    public function testIsSampleNeeded()
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...
118
    {
119
        $this->databaseHelper->method('getConfigParamWithoutCache')->willReturn(5);
120
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
121
            ->method('getValue')
122
            ->willReturnMap(
123
                [
124
                    ['payone_protect/creditrating/sample_mode_frequency', ScopeInterface::SCOPE_STORE, null, 5],
125
                    ['payone_protect/creditrating/sample_mode_enabled', ScopeInterface::SCOPE_STORE, null, 1]
126
                ]
127
            );
128
        $result = $this->consumerscore->isSampleNeeded();
129
        $this->assertTrue($result);
130
    }
131
132 View Code Duplication
    public function testIsSampleNotNeeded()
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...
133
    {
134
        $this->databaseHelper->method('getConfigParamWithoutCache')->willReturn(3);
135
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
136
            ->method('getValue')
137
            ->willReturnMap(
138
                [
139
                    ['payone_protect/creditrating/sample_mode_frequency', ScopeInterface::SCOPE_STORE, null, 5],
140
                    ['payone_protect/creditrating/sample_mode_enabled', ScopeInterface::SCOPE_STORE, null, 1]
141
                ]
142
            );
143
        $result = $this->consumerscore->isSampleNeeded();
144
        $this->assertFalse($result);
145
    }
146
147 View Code Duplication
    public function testCanShowPaymentHintText()
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...
148
    {
149
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
150
            ->method('getValue')
151
            ->willReturnMap(
152
                [
153
                    ['payone_protect/creditrating/enabled', ScopeInterface::SCOPE_STORE, null, 1],
154
                    ['payone_protect/creditrating/payment_hint_enabled', ScopeInterface::SCOPE_STORE, null, 1],
155
                    ['payone_protect/creditrating/integration_event', ScopeInterface::SCOPE_STORE, null, 'after_payment']
156
                ]
157
            );
158
        $result = $this->consumerscore->canShowPaymentHintText();
159
        $this->assertTrue($result);
160
    }
161
162 View Code Duplication
    public function testMustNotShowPaymentHintText()
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...
163
    {
164
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
165
            ->method('getValue')
166
            ->willReturnMap(
167
                [
168
                    ['payone_protect/creditrating/enabled', ScopeInterface::SCOPE_STORE, null, 1],
169
                    ['payone_protect/creditrating/payment_hint_enabled', ScopeInterface::SCOPE_STORE, null, 1],
170
                    ['payone_protect/creditrating/integration_event', ScopeInterface::SCOPE_STORE, null, 'before_payment']
171
                ]
172
            );
173
        $result = $this->consumerscore->canShowPaymentHintText();
174
        $this->assertFalse($result);
175
    }
176
177 View Code Duplication
    public function testCanShowAgreementMessage()
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...
178
    {
179
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
180
            ->method('getValue')
181
            ->willReturnMap(
182
                [
183
                    ['payone_protect/creditrating/enabled', ScopeInterface::SCOPE_STORE, null, 1],
184
                    ['payone_protect/creditrating/agreement_enabled', ScopeInterface::SCOPE_STORE, null, 1],
185
                    ['payone_protect/creditrating/integration_event', ScopeInterface::SCOPE_STORE, null, 'after_payment']
186
                ]
187
            );
188
        $result = $this->consumerscore->canShowAgreementMessage();
189
        $this->assertTrue($result);
190
    }
191
192 View Code Duplication
    public function testMustNotShowAgreementMessage()
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...
193
    {
194
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
195
            ->method('getValue')
196
            ->willReturnMap(
197
                [
198
                    ['payone_protect/creditrating/enabled', ScopeInterface::SCOPE_STORE, null, 1],
199
                    ['payone_protect/creditrating/agreement_enabled', ScopeInterface::SCOPE_STORE, null, 1],
200
                    ['payone_protect/creditrating/integration_event', ScopeInterface::SCOPE_STORE, null, 'before_payment']
201
                ]
202
            );
203
        $result = $this->consumerscore->canShowAgreementMessage();
204
        $this->assertFalse($result);
205
    }
206
207
    /**
208
     * @return array
209
     */
210
    public function getScoreArrays()
211
    {
212
        return [
213
            [['Y', 'G', 'R'], 'R'],
214
            [['G', 'Y'], 'Y'],
215
            [['G'], 'G']
216
        ];
217
    }
218
219
    /**
220
     * @param array $scores
221
     * @param string $expected
222
     *
223
     * @dataProvider getScoreArrays
224
     */
225
    public function testGetWorstScore($scores, $expected)
226
    {
227
        $result = $this->consumerscore->getWorstScore($scores);
228
        $this->assertEquals($expected, $result);
229
    }
230
231
    public function testGetAllowedMethodsForScore()
232
    {
233
        $yellowMethods = 'payone_creditcard,payone_debit';
234
        $redMethods = 'payone_paypal,payone_invoice';
235
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
236
            ->method('getValue')
237
            ->willReturnMap(
238
                [
239
                    ['payone_protect/creditrating/allow_payment_methods_yellow', ScopeInterface::SCOPE_STORE, null, $yellowMethods],
240
                    ['payone_protect/creditrating/allow_payment_methods_red', ScopeInterface::SCOPE_STORE, null, $redMethods]
241
                ]
242
            );
243
        $result = $this->consumerscore->getAllowedMethodsForScore('Y');
244
        $expected = explode(',', $yellowMethods);
245
        $this->assertEquals($expected, $result);
246
247
        $result = $this->consumerscore->getAllowedMethodsForScore('R');
248
        $expected = explode(',', $redMethods);
249
        $this->assertEquals($expected, $result);
250
    }
251
252
    public function testCopyOldStatusToNewAddress()
253
    {
254
        $expected = 'Y';
255
256
        $this->databaseHelper->method('getOldAddressStatus')->willReturn($expected);
257
        $address = $this->getMockBuilder(Address::class)
258
            ->disableOriginalConstructor()
259
            ->setMethods(['setPayoneProtectScore', 'save', 'getPayoneProtectScore'])
260
            ->getMock();
261
        $address->method('setPayoneProtectScore')->willReturn($address);
262
        $address->method('save')->willReturn(true);
263
        $address->method('getPayoneProtectScore')->willReturn($expected);
264
265
        $this->consumerscore->copyOldStatusToNewAddress($address);
266
        $this->assertEquals($expected, $address->getPayoneProtectScore());
267
    }
268
269
    public function testIsCheckNeededForPrice()
270
    {
271
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
272
            ->method('getValue')
273
            ->willReturnMap(
274
                [
275
                    ['payone_protect/creditrating/min_order_total', ScopeInterface::SCOPE_STORE, null, 10],
276
                    ['payone_protect/creditrating/max_order_total', ScopeInterface::SCOPE_STORE, null, 1000]
277
                ]
278
            );
279
        $result = $this->consumerscore->isCheckNeededForPrice(500);
280
        $this->assertTrue($result);
281
282
        $result = $this->consumerscore->isCheckNeededForPrice(5000);
283
        $this->assertFalse($result);
284
    }
285
286 View Code Duplication
    public function testIsCreditratingNeededNotEnabled()
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...
287
    {
288
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
289
            ->method('getValue')
290
            ->willReturnMap(
291
                [
292
                    ['payone_protect/creditrating/enabled', ScopeInterface::SCOPE_STORE, null, 0]
293
                ]
294
            );
295
        $result = $this->consumerscore->isCreditratingNeeded('after_payment', 500);
296
        $this->assertFalse($result);
297
    }
298
299 View Code Duplication
    public function testIsCreditratingNeededWrongEvent()
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...
300
    {
301
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
302
            ->method('getValue')
303
            ->willReturnMap(
304
                [
305
                    ['payone_protect/creditrating/enabled', ScopeInterface::SCOPE_STORE, null, 1],
306
                    ['payone_protect/creditrating/integration_event', ScopeInterface::SCOPE_STORE, null, 'before_payment']
307
                ]
308
            );
309
        $result = $this->consumerscore->isCreditratingNeeded('after_payment', 500);
310
        $this->assertFalse($result);
311
    }
312
313
    public function testIsCreditratingNeededWrongPrice()
314
    {
315
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
316
            ->method('getValue')
317
            ->willReturnMap(
318
                [
319
                    ['payone_protect/creditrating/enabled', ScopeInterface::SCOPE_STORE, null, 1],
320
                    ['payone_protect/creditrating/integration_event', ScopeInterface::SCOPE_STORE, null, 'before_payment'],
321
                    ['payone_protect/creditrating/min_order_total', ScopeInterface::SCOPE_STORE, null, 10],
322
                    ['payone_protect/creditrating/max_order_total', ScopeInterface::SCOPE_STORE, null, 1000]
323
                ]
324
            );
325
        $result = $this->consumerscore->isCreditratingNeeded('before_payment', 5000);
326
        $this->assertFalse($result);
327
    }
328
329 View Code Duplication
    public function testIsCreditratingNeededSampleNotNeeded()
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...
330
    {
331
        $this->databaseHelper->method('getConfigParamWithoutCache')->willReturn(3);
332
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
333
            ->method('getValue')
334
            ->willReturnMap(
335
                [
336
                    ['payone_protect/creditrating/enabled', ScopeInterface::SCOPE_STORE, null, 1],
337
                    ['payone_protect/creditrating/integration_event', ScopeInterface::SCOPE_STORE, null, 'before_payment'],
338
                    ['payone_protect/creditrating/min_order_total', ScopeInterface::SCOPE_STORE, null, 10],
339
                    ['payone_protect/creditrating/max_order_total', ScopeInterface::SCOPE_STORE, null, 1000],
340
                    ['payone_protect/creditrating/sample_mode_frequency', ScopeInterface::SCOPE_STORE, null, 5],
341
                    ['payone_protect/creditrating/sample_mode_enabled', ScopeInterface::SCOPE_STORE, null, 1]
342
                ]
343
            );
344
        $result = $this->consumerscore->isCreditratingNeeded('before_payment', 500);
345
        $this->assertFalse($result);
346
    }
347
348 View Code Duplication
    public function testIsCreditratingNeeded()
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...
349
    {
350
        $this->databaseHelper->method('getConfigParamWithoutCache')->willReturn(5);
351
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Magento\Framework\App\Config\ScopeConfigInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
352
            ->method('getValue')
353
            ->willReturnMap(
354
                [
355
                    ['payone_protect/creditrating/enabled', ScopeInterface::SCOPE_STORE, null, 1],
356
                    ['payone_protect/creditrating/integration_event', ScopeInterface::SCOPE_STORE, null, 'before_payment'],
357
                    ['payone_protect/creditrating/min_order_total', ScopeInterface::SCOPE_STORE, null, 10],
358
                    ['payone_protect/creditrating/max_order_total', ScopeInterface::SCOPE_STORE, null, 1000],
359
                    ['payone_protect/creditrating/sample_mode_frequency', ScopeInterface::SCOPE_STORE, null, 5],
360
                    ['payone_protect/creditrating/sample_mode_enabled', ScopeInterface::SCOPE_STORE, null, 1]
361
                ]
362
            );
363
        $result = $this->consumerscore->isCreditratingNeeded('before_payment', 500);
364
        $this->assertTrue($result);
365
    }
366
}
367