Completed
Pull Request — master (#72)
by Mario
05:41
created

ManagemandateTest::testSendRequest()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 30
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\Api\Request;
28
29
use Magento\Quote\Model\Quote;
30
use Payone\Core\Helper\Database;
31
use Payone\Core\Helper\Shop;
32
use Payone\Core\Model\Api\Request\Managemandate as ClassToTest;
33
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
34
use Payone\Core\Model\Methods\PayoneMethod;
35
use Magento\Payment\Model\Info;
36
use Payone\Core\Helper\Api;
37
use Magento\Customer\Api\Data\CustomerInterface;
38
use Magento\Quote\Model\Quote\Address;
39
40
class ManagemandateTest extends \PHPUnit_Framework_TestCase
41
{
42
    /**
43
     * @var ClassToTest
44
     */
45
    private $classToTest;
46
47
    /**
48
     * @var Api|\PHPUnit_Framework_MockObject_MockObject
49
     */
50
    private $apiHelper;
51
52
    /**
53
     * @var Shop|\PHPUnit_Framework_MockObject_MockObject
54
     */
55
    private $shopHelper;
56
57 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...
58
    {
59
        $objectManager = new ObjectManager($this);
60
61
        $databaseHelper = $this->getMockBuilder(Database::class)->disableOriginalConstructor()->getMock();
62
        $databaseHelper->method('getPayoneUserIdByCustNr')->willReturn('15');
63
64
        $this->apiHelper = $this->getMockBuilder(Api::class)->disableOriginalConstructor()->getMock();
65
        $this->shopHelper = $this->getMockBuilder(Shop::class)->disableOriginalConstructor()->getMock();
66
67
        $this->classToTest = $objectManager->getObject(ClassToTest::class, [
68
            'databaseHelper' => $databaseHelper,
69
            'shopHelper' => $this->shopHelper,
70
            'apiHelper' => $this->apiHelper
71
        ]);
72
    }
73
74
    public function testSendRequest()
75
    {
76
        $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->getMock();
77
        $paymentInfo->method('getAdditionalInformation')->willReturn('test value');
78
79
        $payment = $this->getMockBuilder(PayoneMethod::class)->disableOriginalConstructor()->getMock();
80
        $payment->method('getOperationMode')->willReturn('test');
81
        $payment->method('getInfoInstance')->willReturn($paymentInfo);
82
83
        $customer = $this->getMockBuilder(CustomerInterface::class)->disableOriginalConstructor()->getMock();
84
        $customer->method('getId')->willReturn('12345');
85
        $customer->method('getGender')->willReturn('m');
86
        $customer->method('getEmail')->willReturn('[email protected]');
87
        $customer->method('getDob')->willReturn('20000101');
88
89
        $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
90
        $address->method('getCountryId')->willReturn('DE');
91
        $address->method('getFirstname')->willReturn('Paul');
92
        $address->method('getLastname')->willReturn('Paytest');
93
        $address->method('getCompany')->willReturn('Testcompany Ltd.');
94
        $address->method('getStreet')->willReturn(['Teststr. 5', '1st floor']);
95
        $address->method('getPostcode')->willReturn('12345');
96
        $address->method('getCity')->willReturn('Berlin');
97
        $address->method('getRegionCode')->willReturn('Berlin');
98
        $address->method('getTelephone')->willReturn('0301234567');
99
        $address->method('getVatId')->willReturn('12345');
100
101
        $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock();
102
        $quote->method('getCustomer')->willReturn($customer);
103
        $quote->method('getQuoteCurrencyCode')->willReturn('EUR');
104
        $quote->method('getBillingAddress')->willReturn($address);
105
106
        $response = ['status' => 'APPROVED'];
107
        $this->apiHelper->method('sendApiRequest')->willReturn($response);
108
109
        $result = $this->classToTest->sendRequest($payment, $quote);
110
        $this->assertArrayHasKey('status', $result);
111
    }
112
}
113