Completed
Push — master ( 1a26ad...341936 )
by Florian
04:37
created

CaptureTest::testSendRequestBase()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 32
rs 8.8571
cc 1
eloc 23
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\Sales\Model\Order;
30
use Payone\Core\Helper\Database;
31
use Payone\Core\Model\Api\Request\Capture as ClassToTest;
32
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
33
use Payone\Core\Model\Methods\PayoneMethod;
34
use Magento\Payment\Model\Info;
35
use Payone\Core\Helper\Api;
36
37
class CaptureTest extends \PHPUnit_Framework_TestCase
38
{
39
    /**
40
     * @var ClassToTest
41
     */
42
    private $classToTest;
43
44
    /**
45
     * @var Api|\PHPUnit_Framework_MockObject_MockObject
46
     */
47
    private $apiHelper;
48
49 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...
50
    {
51
        $objectManager = new ObjectManager($this);
52
53
        $databaseHelper = $this->getMockBuilder(Database::class)->disableOriginalConstructor()->getMock();
54
        $databaseHelper->method('getSequenceNumber')->willReturn('0');
55
56
        $this->apiHelper = $this->getMockBuilder(Api::class)->disableOriginalConstructor()->getMock();
57
58
        $this->classToTest = $objectManager->getObject(ClassToTest::class, [
59
            'databaseHelper' => $databaseHelper,
60
            'apiHelper' => $this->apiHelper
61
        ]);
62
    }
63
64
    public function testSendRequest()
65
    {
66
        $payment = $this->getMockBuilder(PayoneMethod::class)->disableOriginalConstructor()->getMock();
67
        $payment->method('getOperationMode')->willReturn('test');
68
69
        $order = $this->getMockBuilder(Order::class)
70
            ->disableOriginalConstructor()
71
            ->setMethods(['getRealOrderId', 'getOrderCurrencyCode'])
72
            ->getMock();
73
        $order->method('getRealOrderId')->willReturn('54321');
74
        $order->method('getOrderCurrencyCode')->willReturn('EUR');
75
76
        $paymentInfo = $this->getMockBuilder(Info::class)
77
            ->disableOriginalConstructor()
78
            ->setMethods(['getOrder', 'getParentTransactionId'])
79
            ->getMock();
80
        $paymentInfo->method('getOrder')->willReturn($order);
81
        $paymentInfo->method('getParentTransactionId')->willReturn('12345');
82
83
        $response = ['status' => 'APPROVED'];
84
        $this->apiHelper->method('sendApiRequest')->willReturn($response);
85
86
        $result = $this->classToTest->sendRequest($payment, $paymentInfo, 100);
87
        $this->assertArrayHasKey('status', $result);
88
    }
89
90
    public function testSendRequestBase()
91
    {
92
        $payment = $this->getMockBuilder(PayoneMethod::class)->disableOriginalConstructor()->getMock();
93
        $payment->method('getOperationMode')->willReturn('test');
94
95
        $order = $this->getMockBuilder(Order::class)
96
            ->disableOriginalConstructor()
97
            ->setMethods(['getRealOrderId', 'getOrderCurrencyCode'])
98
            ->getMock();
99
        $order->method('getRealOrderId')->willReturn('54321');
100
        $order->method('getOrderCurrencyCode')->willReturn('EUR');
101
102
        $paymentInfo = $this->getMockBuilder(Info::class)
103
            ->disableOriginalConstructor()
104
            ->setMethods(['getOrder', 'getParentTransactionId'])
105
            ->getMock();
106
        $paymentInfo->method('getOrder')->willReturn($order);
107
        $paymentInfo->method('getParentTransactionId')->willReturn('12345');
108
109
        $response = ['status' => 'APPROVED'];
110
        $this->apiHelper->method('sendApiRequest')->willReturn($response);
111
112
        $this->classToTest->addParameter('test', '', true);
113
114
        $resultMissing = $this->classToTest->getParameter('missing');
115
        $this->assertFalse($resultMissing);
116
117
        $this->classToTest->removeParameter('mid');
118
119
        $result = $this->classToTest->sendRequest($payment, $paymentInfo, 100);
120
        $this->assertArrayHasKey('errormessage', $result);
121
    }
122
}
123