DebitTest::setUp()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 36
rs 8.8571
cc 1
eloc 26
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\Block\Info;
28
29
use Magento\Sales\Model\Order;
30
use Payone\Core\Block\Info\Debit as ClassToTest;
31
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
32
use Magento\Payment\Model\Info;
33
use Payone\Core\Model\Entities\TransactionStatus;
34
use Payone\Core\Model\TransactionStatusRepository;
35
use Payone\Core\Test\Unit\BaseTestCase;
36
use Payone\Core\Model\Test\PayoneObjectManager;
37
38
class DebitTest extends BaseTestCase
39
{
40
    /**
41
     * @var ClassToTest
42
     */
43
    private $classToTest;
44
45
    /**
46
     * @var ObjectManager|PayoneObjectManager
47
     */
48
    private $objectManager;
49
50
    /**
51
     * @var Info|\PHPUnit_Framework_MockObject_MockObject
52
     */
53
    private $info;
54
55
    protected function setUp()
56
    {
57
        $this->objectManager = $this->getObjectManager();
58
59
        $order = $this->getMockBuilder(Order::class)
60
            ->disableOriginalConstructor()
61
            ->setMethods(['getPayoneTxid'])
62
            ->getMock();
63
        $order->method('getPayoneTxid')->willReturn('12345');
64
65
        $this->info = $this->getMockBuilder(Info::class)
66
            ->disableOriginalConstructor()
67
            ->setMethods(['getLastTransId', 'getOrder'])
68
            ->getMock();
69
        $this->info->method('getOrder')->willReturn($order);
70
71
        $rawStatus = [
72
            'iban' => '12345',
73
            'bic' => '12345',
74
            'bankaccount' => '12345',
75
            'bankcode' => '12345'
76
        ];
77
78
        $transactionStatus = $this->getMockBuilder(TransactionStatus::class)
79
            ->disableOriginalConstructor()
80
            ->getMock();
81
        $transactionStatus->method('getRawStatusArray')->willReturn($rawStatus);
82
83
        $transactionStatusRepository = $this->getMockBuilder(TransactionStatusRepository::class)->disableOriginalConstructor()->getMock();
84
        $transactionStatusRepository->method('getAppointedByTxid')->willReturn($transactionStatus);
85
86
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
87
            'transactionStatusRepository' => $transactionStatusRepository
88
        ]);
89
        $this->classToTest->setInfo($this->info);
90
    }
91
92
    public function testPrepareSpecificInformation()
93
    {
94
        $this->info->method('getLastTransId')->willReturn('12345');
95
96
        $result = $this->classToTest->getSpecificInformation();
97
        $this->assertArrayHasKey('IBAN:', $result);
98
99
        $result = $this->classToTest->getSpecificInformation();
100
        $this->assertNotEmpty($result);
101
    }
102
103
    public function testPrepareSpecificInformationNoLastTransId()
104
    {
105
        $this->info->method('getLastTransId')->willReturn('');
106
107
        $result = $this->classToTest->getSpecificInformation();
108
        $this->assertArrayHasKey('Payment has not been processed yet.', $result);
109
    }
110
}
111