Completed
Push — master ( 6c4da9...442164 )
by Florian
14s queued 11s
created

PaymentBanTest::testGetPaymentBans()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
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\ResourceModel;
28
29
use Payone\Core\Model\ResourceModel\PaymentBan as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Payone\Core\Helper\Shop;
32
use Magento\Quote\Api\Data\AddressInterface;
33
use Magento\Framework\Model\ResourceModel\Db\Context;
34
use Magento\Framework\App\ResourceConnection;
35
use Payone\Core\Test\Unit\BaseTestCase;
36
use Payone\Core\Test\Unit\PayoneObjectManager;
37
use Magento\Framework\DB\Select;
38
39
class PaymentBanTest extends BaseTestCase
40
{
41
    /**
42
     * @var ClassToTest
43
     */
44
    private $classToTest;
45
46
    /**
47
     * @var ObjectManager|PayoneObjectManager
48
     */
49
    private $objectManager;
50
51
    /**
52
     * @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
53
     */
54
    private $connection;
55
56
    protected function setUp()
57
    {
58
        $this->objectManager = $this->getObjectManager();
59
60
        $this->connection = $this->getMockBuilder(Select::class)
61
            ->disableOriginalConstructor()
62
            ->setMethods(['fetchAll', 'select', 'from', 'where', 'insert', 'order'])
63
            ->getMock();
64
        $this->connection->method('select')->willReturn($this->connection);
65
        $this->connection->method('from')->willReturn($this->connection);
66
        $this->connection->method('where')->willReturn($this->connection);
67
        $this->connection->method('order')->willReturn($this->connection);
68
69
        $resource = $this->getMockBuilder(ResourceConnection::class)->disableOriginalConstructor()->getMock();
70
        $resource->method('getConnection')->willReturn($this->connection);
71
72
        $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
73
        $context->method('getResources')->willReturn($resource);
74
75
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
76
            'context' => $context
77
        ]);
78
    }
79
80
    public function testGetBanEndDate()
81
    {
82
        $time = time();
83
        $result = $this->classToTest->getBanEndDate(24);
84
        $this->assertGreaterThan($time, strtotime($result));
85
    }
86
87
    public function testAddPaymentBan()
88
    {
89
        $result = $this->classToTest->addPaymentBan('payone_debit', 5, 24);
90
        $this->assertInstanceOf(ClassToTest::class, $result);
91
    }
92
93
    public function testGetPaymentBans()
94
    {
95
        $fetchReturn = [['payment_method' => 'payone_debit', 'to_date' => '2020-12-12 12:20:00']];
96
        $this->connection->method('fetchAll')->willReturn($fetchReturn);
97
        $expected = ['payone_debit' => '2020-12-12 12:20:00'];
98
        $result = $this->classToTest->getPaymentBans(5);
99
        $this->assertEquals($expected, $result);
100
    }
101
}
102