ShippingAddressManagementTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 4
dl 0
loc 48
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 23 1
A testBeforeAssign() 0 11 1
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\Plugins;
28
29
use Payone\Core\Model\Plugins\ShippingAddressManagement as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Quote\Api\CartRepositoryInterface;
32
use Payone\Core\Model\Risk\Addresscheck;
33
use Magento\Quote\Model\Quote;
34
use Magento\Quote\Api\Data\AddressInterface;
35
use Magento\Quote\Model\ShippingAddressManagement;
36
use Magento\Framework\App\Request\Http;
37
use Payone\Core\Test\Unit\BaseTestCase;
38
use Payone\Core\Model\Test\PayoneObjectManager;
39
40
class ShippingAddressManagementTest extends BaseTestCase
41
{
42
    /**
43
     * @var ClassToTest
44
     */
45
    private $classToTest;
46
47
    /**
48
     * @var ObjectManager|PayoneObjectManager
49
     */
50
    private $objectManager;
51
52
    protected function setUp()
53
    {
54
        $this->objectManager = $this->getObjectManager();
55
56
        $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock();
57
58
        $quoteRepository = $this->getMockBuilder(CartRepositoryInterface::class)->disableOriginalConstructor()->getMock();
59
        $quoteRepository->method('getActive')->willReturn($quote);
60
61
        $address = $this->getMockBuilder(AddressInterface::class)->disableOriginalConstructor()->getMock();
62
63
        $addresscheck = $this->getMockBuilder(Addresscheck::class)->disableOriginalConstructor()->getMock();
64
        $addresscheck->method('handleAddressManagement')->willReturn($address);
65
66
        $request = $this->getMockBuilder(Http::class)->disableOriginalConstructor()->getMock();
67
        $request->method('getPathInfo')->willReturn('/rest/default/V1/carts/mine/shipping-information');
68
69
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
70
            'quoteRepository' => $quoteRepository,
71
            'addresscheck' => $addresscheck,
72
            'request' => $request
73
        ]);
74
    }
75
76
    public function testBeforeAssign()
77
    {
78
        $cartId = '12345';
79
80
        $source = $this->getMockBuilder(ShippingAddressManagement::class)->disableOriginalConstructor()->getMock();
81
        $address = $this->getMockBuilder(AddressInterface::class)->disableOriginalConstructor()->getMock();
82
83
        $result = $this->classToTest->beforeAssign($source, $cartId, $address);
84
        $this->assertEquals($cartId, $result[0]);
85
        $this->assertInstanceOf(AddressInterface::class, $result[1]);
86
    }
87
}
88