DownloadTest::testExecute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
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\Controller\Mandate;
28
29
use Payone\Core\Controller\Mandate\Download as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Checkout\Model\Session;
32
use Payone\Core\Model\Api\Request\Getfile;
33
use Payone\Core\Helper\Payment;
34
use Magento\Framework\Controller\Result\RawFactory;
35
use Magento\Framework\Controller\Result\Raw;
36
use Magento\Sales\Model\Order;
37
use Magento\Sales\Model\Order\Payment AS OrderPayment;
38
use Payone\Core\Model\Methods\Debit;
39
use Payone\Core\Model\Methods\PayoneMethod;
40
use Payone\Core\Test\Unit\BaseTestCase;
41
use Payone\Core\Model\Test\PayoneObjectManager;
42
43
class DownloadTest extends BaseTestCase
44
{
45
    /**
46
     * @var ClassToTest
47
     */
48
    private $classToTest;
49
50
    /**
51
     * @var ObjectManager|PayoneObjectManager
52
     */
53
    private $objectManager;
54
55
    protected function setUp()
56
    {
57
        $this->objectManager = $this->getObjectManager();
58
59
        $payonePayment = $this->getMockBuilder(Debit::class)->disableOriginalConstructor()->getMock();
60
61
        $payment = $this->getMockBuilder(OrderPayment::class)->disableOriginalConstructor()->getMock();
62
        $payment->method('getMethodInstance')->willReturn($payonePayment);
63
64
        $order = $this->getMockBuilder(Order::class)
65
            ->disableOriginalConstructor()
66
            ->setMethods(['getPayoneMandateId', 'getPayment'])
67
            ->getMock();
68
        $order->method('getPayoneMandateId')->willReturn('12345');
69
        $order->method('getPayment')->willReturn($payment);
70
71
        $checkoutSession = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
72
        $checkoutSession->method('getLastRealOrder')->willReturn($order);
73
74
        $getfileRequest = $this->getMockBuilder(Getfile::class)->disableOriginalConstructor()->getMock();
75
        $getfileRequest->method('sendRequest')->willReturn('Mandate Test Text');
76
77
        $paymentHelper = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock();
78
        $paymentHelper->method('isMandateManagementDownloadActive')->willReturn(true);
79
80
        $rawResponse = $this->getMockBuilder(Raw::class)->disableOriginalConstructor()->getMock();
81
        $resultRawFactory = $this->getMockBuilder(RawFactory::class)
82
            ->disableOriginalConstructor()
83
            ->setMethods(['create'])
84
            ->getMock();
85
        $resultRawFactory->method('create')->willReturn($rawResponse);
86
87
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
88
            'checkoutSession' => $checkoutSession,
89
            'getfileRequest' => $getfileRequest,
90
            'paymentHelper' => $paymentHelper,
91
            'resultRawFactory' => $resultRawFactory
92
        ]);
93
    }
94
95
    public function testExecute()
96
    {
97
        $result = $this->classToTest->execute();
98
        $this->assertInstanceOf(Raw::class, $result);
99
    }
100
}
101