IndexTest::setUp()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 1
eloc 17
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\Adminhtml\Config\Export;
28
29
use Payone\Core\Controller\Adminhtml\Config\Export\Index as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Backend\App\Action\Context;
32
use Magento\Framework\View\Result\PageFactory;
33
use Magento\Framework\View\Result\Page;
34
use Magento\Framework\View\Page\Config;
35
use Magento\Framework\View\Page\Title;
36
use Magento\Framework\AuthorizationInterface;
37
use Payone\Core\Model\Config\Export;
38
use Magento\Framework\Controller\Result\RawFactory;
39
use Magento\Framework\Controller\Result\Raw;
40
use Payone\Core\Test\Unit\BaseTestCase;
41
use Payone\Core\Model\Test\PayoneObjectManager;
42
43
class IndexTest extends BaseTestCase
44
{
45
    /**
46
     * @var ClassToTest
47
     */
48
    private $classToTest;
49
50
    /**
51
     * @var ObjectManager|PayoneObjectManager
52
     */
53
    private $objectManager;
54
55
    /**
56
     * @var Export|\PHPUnit_Framework_MockObject_MockObject
57
     */
58
    private $configExport;
59
60
    protected function setUp()
61
    {
62
        $this->objectManager = $this->getObjectManager();
63
64
        $authorization = $this->getMockBuilder(AuthorizationInterface::class)->disableOriginalConstructor()->getMock();
65
        $authorization->method('isAllowed')->willReturn(true);
66
67
        $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
68
        $context->method('getAuthorization')->willReturn($authorization);
69
70
        $this->configExport = $this->getMockBuilder(Export::class)->disableOriginalConstructor()->getMock();
71
72
        $raw = $this->getMockBuilder(Raw::class)->disableOriginalConstructor()->getMock();
73
74
        $resultRawFactory = $this->getMockBuilder(RawFactory::class)
75
            ->disableOriginalConstructor()
76
            ->setMethods(['create'])
77
            ->getMock();
78
        $resultRawFactory->method('create')->willReturn($raw);
79
80
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
81
            'context' => $context,
82
            'configExport' => $this->configExport,
83
            'resultRawFactory' => $resultRawFactory
84
        ]);
85
    }
86
87
    public function testExecute()
88
    {
89
        $this->configExport->method('generateConfigExportXml')->willReturn('export xml');
90
91
        $result = $this->classToTest->execute();
92
        $this->assertInstanceOf(Raw::class, $result);
93
    }
94
95
    public function testExecuteException()
96
    {
97
        $exception = new \Exception();
98
        $this->configExport->method('generateConfigExportXml')->willThrowException($exception);
99
100
        $result = $this->classToTest->execute();
101
        $this->assertInstanceOf(Raw::class, $result);
102
    }
103
}
104