Completed
Pull Request — master (#114)
by Florian
03:49
created

testIsCheckNeededForQuoteMinBasket()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 1
eloc 6
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\Model\Risk;
28
29
use Payone\Core\Model\Risk\Addresscheck as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Payone\Core\Model\Api\Request\Addresscheck;
32
use Payone\Core\Helper\Database;
33
use Payone\Core\Helper\Toolkit;
34
use Magento\Checkout\Model\Session;
35
use Magento\Quote\Model\Quote\Address;
36
use Magento\Quote\Model\Quote;
37
use Magento\Framework\Exception\LocalizedException;
38
use Payone\Core\Test\Unit\BaseTestCase;
39
use Payone\Core\Model\Test\PayoneObjectManager;
40
41
class AddresscheckTest extends BaseTestCase
42
{
43
    /**
44
     * @var ClassToTest
45
     */
46
    private $classToTest;
47
48
    /**
49
     * @var ObjectManager|PayoneObjectManager
50
     */
51
    private $objectManager;
52
53
    /**
54
     * @var Addresscheck|\PHPUnit_Framework_MockObject_MockObject
55
     */
56
    private $addresscheck;
57
58
    /**
59
     * @var Database|\PHPUnit_Framework_MockObject_MockObject
60
     */
61
    private $databaseHelper;
62
63
    /**
64
     * @var Quote|\PHPUnit_Framework_MockObject_MockObject
65
     */
66
    private $quote;
67
68
    /**
69
     * @var Toolkit
70
     */
71
    private $toolkitHelper;
72
73
    protected function setUp()
74
    {
75
        $this->objectManager = $this->getObjectManager();
76
77
        $this->addresscheck = $this->getMockBuilder(Addresscheck::class)->disableOriginalConstructor()->getMock();
78
        $this->databaseHelper = $this->getMockBuilder(Database::class)->disableOriginalConstructor()->getMock();
79
80
        $this->quote = $this->getMockBuilder(Quote::class)
81
            ->disableOriginalConstructor()
82
            ->setMethods(['isVirtual', 'getSubtotal'])
83
            ->getMock();
84
        $this->quote->method('isVirtual')->willReturn(false);
85
        $this->quote->method('getSubtotal')->willReturn(100);
86
87
        #$this->toolkitHelper = $this->getMockBuilder(Toolkit::class)->disableOriginalConstructor()->getMock();
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
88
        #$this->toolkitHelper->method('handleSubstituteReplacement')->willReturn('Invalid message');
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
89
        $this->toolkitHelper = $this->objectManager->getObject(Toolkit::class);
90
91
        $checkoutSession = $this->getMockBuilder(Session::class)
92
            ->disableOriginalConstructor()
93
            ->setMethods([
94
                'getPayoneBillingAddresscheckScore',
95
                'getPayoneShippingAddresscheckScore',
96
                'unsPayoneBillingAddresscheckScore',
97
                'unsPayoneShippingAddresscheckScore'])
98
            ->getMock();
99
        $checkoutSession->method('getPayoneShippingAddresscheckScore')->willReturn(null);
100
101
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
102
            'addresscheck' => $this->addresscheck,
103
            'databaseHelper' => $this->databaseHelper,
104
            'toolkitHelper' => $this->toolkitHelper,
105
            'checkoutSession' => $checkoutSession
106
        ]);
107
    }
108
109 View Code Duplication
    public function testIsCheckNeededForQuoteMinBasket()
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->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
112
            ->method('getConfigParam')
113
            ->willReturnMap([['min_order_total', 'address_check', 'payone_protect', null, 10]]);
114
115
        $result = $this->classToTest->isCheckNeededForQuote(true, true, 5);
116
        $this->assertFalse($result);
117
    }
118
119 View Code Duplication
    public function testIsCheckNeededForQuoteMaxBasket()
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...
120
    {
121
        $this->databaseHelper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
122
            ->method('getConfigParam')
123
            ->willReturnMap([['max_order_total', 'address_check', 'payone_protect', null, 10]]);
124
125
        $result = $this->classToTest->isCheckNeededForQuote(true, true, 15);
126
        $this->assertFalse($result);
127
    }
128
129 View Code Duplication
    public function testIsCheckNeededForQuoteVirtual()
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...
130
    {
131
        $this->databaseHelper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
132
            ->method('getConfigParam')
133
            ->willReturnMap([['check_billing_for_virtual_order', 'address_check', 'payone_protect', null, 0]]);
134
135
        $result = $this->classToTest->isCheckNeededForQuote(true, true, 15);
136
        $this->assertFalse($result);
137
    }
138
139 View Code Duplication
    public function testIsCheckNeededForQuote()
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...
140
    {
141
        $this->databaseHelper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
142
            ->method('getConfigParam')
143
            ->willReturnMap([['check_billing_for_virtual_order', 'address_check', 'payone_protect', null, 0]]);
144
145
        $result = $this->classToTest->isCheckNeededForQuote(true, false, 15);
146
        $this->assertTrue($result);
147
    }
148
149 View Code Duplication
    public function testCorrectAddress()
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
        $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
152
        $this->addresscheck->method('sendRequest')->willReturn(true);
153
154
        $result = $this->classToTest->correctAddress($address);
155
        $this->assertEquals($address, $result);
156
    }
157
158
    public function testHandleAddressManagement()
159
    {
160
        $address = $this->getMockBuilder(Address::class)
161
            ->disableOriginalConstructor()
162
            ->setMethods(['getPayoneAddresscheckScore', 'setPayoneAddresscheckScore', 'getStreet', 'setStreet', 'getData', 'setData'])
163
            ->getMock();
164
        $address->method('getPayoneAddresscheckScore')->willReturn(null);
165
        $address->method('getStreet')->willReturn(['Teststr. 12', '3rd floor']);
166
167
        $this->addresscheck->method('sendRequest')->willReturn(['status' => 'VALID', 'street' => 'Another str. 7', 'firstname' => 'Patrick']);
168
169
        $result = $this->classToTest->handleAddressManagement($address, $this->quote, false);
170
        $this->assertInstanceOf(Address::class, $result);
171
172
        $result = $this->classToTest->isAddressCorrected();
173
        $this->assertTrue($result);
174
    }
175
176
    public function testHandleAddressManagementExceptionError()
177
    {
178
        $address = $this->getMockBuilder(Address::class)
179
            ->disableOriginalConstructor()
180
            ->setMethods(['getPayoneAddresscheckScore', 'setPayoneAddresscheckScore', 'getStreet', 'setStreet', 'getData', 'setData'])
181
            ->getMock();
182
        $address->method('getPayoneAddresscheckScore')->willReturn(null);
183
184
        $this->addresscheck->method('sendRequest')->willReturn(['status' => 'ERROR']);
185
        $this->databaseHelper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
186
            ->method('getConfigParam')
187
            ->willReturnMap([
188
                ['handle_response_error', 'address_check', 'payone_protect', null, 'stop_checkout'],
189
                ['stop_checkout_message', 'address_check', 'payone_protect', null, null]
190
            ]);
191
192
        $this->expectException(LocalizedException::class);
193
        $this->classToTest->handleAddressManagement($address, $this->quote, false);
194
    }
195
196 View Code Duplication
    public function testHandleAddressManagementExceptionInvalid()
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...
197
    {
198
        $address = $this->getMockBuilder(Address::class)
199
            ->disableOriginalConstructor()
200
            ->setMethods(['getPayoneAddresscheckScore', 'setPayoneAddresscheckScore', 'getStreet', 'setStreet', 'getData', 'setData'])
201
            ->getMock();
202
        $address->method('getPayoneAddresscheckScore')->willReturn(null);
203
204
        $this->addresscheck->method('sendRequest')->willReturn(['status' => 'INVALID', 'customermessage' => 'Address invalid']);
205
        $this->databaseHelper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
206
            ->method('getConfigParam')
207
            ->willReturnMap([
208
                ['message_response_invalid', 'address_check', 'payone_protect', null, null]
209
            ]);
210
211
        $this->expectException(LocalizedException::class);
212
        $this->classToTest->handleAddressManagement($address, $this->quote, false);
213
    }
214
215
    public function testHandleAddressManagementExceptionNoStatus()
216
    {
217
        $address = $this->getMockBuilder(Address::class)
218
            ->disableOriginalConstructor()
219
            ->setMethods(['getPayoneAddresscheckScore', 'setPayoneAddresscheckScore', 'getStreet', 'setStreet', 'getData', 'setData'])
220
            ->getMock();
221
        $address->method('getPayoneAddresscheckScore')->willReturn(null);
222
223
        $this->addresscheck->method('sendRequest')->willReturn([]);
224
        $this->databaseHelper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
225
            ->method('getConfigParam')
226
            ->willReturnMap([
227
                ['message_response_invalid', 'address_check', 'payone_protect', null, null]
228
            ]);
229
230
        $this->expectException(LocalizedException::class);
231
        $this->classToTest->handleAddressManagement($address, $this->quote, false);
232
    }
233
234 View Code Duplication
    public function testHandleAddressManagementExceptionInvalidDefault()
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...
235
    {
236
        $address = $this->getMockBuilder(Address::class)
237
            ->disableOriginalConstructor()
238
            ->setMethods(['getPayoneAddresscheckScore', 'setPayoneAddresscheckScore', 'getStreet', 'setStreet', 'getData', 'setData'])
239
            ->getMock();
240
        $address->method('getPayoneAddresscheckScore')->willReturn(null);
241
242
        $this->addresscheck->method('sendRequest')->willReturn(['status' => 'INVALID', 'customermessage' => 'Address invalid']);
243
        $this->databaseHelper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
244
            ->method('getConfigParam')
245
            ->willReturnMap([
246
                ['message_response_invalid', 'address_check', 'payone_protect', null, 'Address invalid: {{payone_customermessage}}']
247
            ]);
248
249
        $this->expectException(LocalizedException::class);
250
        $this->classToTest->handleAddressManagement($address, $this->quote, false);
251
    }
252
253 View Code Duplication
    public function testGetScoreR()
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...
254
    {
255
        $this->addresscheck->method('sendRequest')->willReturn(['status' => 'INVALID']);
256
        $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
257
258
        $result = $this->classToTest->getScore($address);
259
        $expected = 'R';
260
        $this->assertEquals($expected, $result);
261
    }
262
263
    public function testGetScorePersonstatusNoMapping()
264
    {
265
        $status = 'x';
266
        $this->databaseHelper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
267
            ->method('getConfigParam')
268
            ->willReturnMap([['mapping_personstatus', 'address_check', 'payone_protect', null, $this->toolkitHelper->serialize($status)]]);
269
270
        $this->addresscheck->method('sendRequest')->willReturn(['personstatus' => 'ABC']);
271
        $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
272
273
        $result = $this->classToTest->getScore($address);
274
        $expected = 'G';
275
        $this->assertEquals($expected, $result);
276
    }
277
278
    public function testGetScorePersonstatus()
279
    {
280
        $status = [
281
            ['personstatus' => 'ABC', 'score' => 'D']
282
        ];
283
        $this->databaseHelper->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Payone\Core\Helper\Database.

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...
284
            ->method('getConfigParam')
285
            ->willReturnMap([['mapping_personstatus', 'address_check', 'payone_protect', null, $this->toolkitHelper->serialize($status)]]);
286
287
        $this->addresscheck->method('sendRequest')->willReturn(['personstatus' => 'ABC']);
288
        $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
289
290
        $result = $this->classToTest->getScore($address);
291
        $expected = 'D';
292
        $this->assertEquals($expected, $result);
293
    }
294
295 View Code Duplication
    public function testGetScoreStillValid()
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...
296
    {
297
        $this->addresscheck->method('sendRequest')->willReturn(true);
298
        $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
299
300
        $expected = 'X';
301
        $this->databaseHelper->method('getOldAddressStatus')->willReturn($expected);
302
303
        $result = $this->classToTest->getScore($address);
304
        $this->assertEquals($expected, $result);
305
    }
306
307 View Code Duplication
    public function testGetResponse()
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...
308
    {
309
        $this->addresscheck->method('sendRequest')->willReturn(true);
310
311
        $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
312
313
        $result = $this->classToTest->getResponse($address);
314
        $this->assertTrue($result);
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->classToTest->getResponse($address) on line 313 can also be of type array; however, PHPUnit\Framework\Assert::assertTrue() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
315
    }
316
}
317