IndexTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 62
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 43 1
A testExecute() 0 5 1
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\Information;
28
29
use Payone\Core\Controller\Adminhtml\Information\Index as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Backend\App\Action\Context;
32
use Magento\Framework\App\ViewInterface;
33
use Magento\Framework\View\LayoutInterface;
34
use Magento\Framework\View\Element\AbstractBlock;
35
use Magento\Backend\Model\Menu;
36
use Magento\Backend\Model\Menu\Item;
37
use Magento\Framework\View\Result\Page;
38
use Magento\Framework\View\Page\Config;
39
use Magento\Framework\View\Page\Title;
40
use Magento\Framework\AuthorizationInterface;
41
use Payone\Core\Test\Unit\BaseTestCase;
42
use Payone\Core\Model\Test\PayoneObjectManager;
43
44
class IndexTest extends BaseTestCase
45
{
46
    /**
47
     * @var ClassToTest
48
     */
49
    private $classToTest;
50
51
    /**
52
     * @var ObjectManager|PayoneObjectManager
53
     */
54
    private $objectManager;
55
56
    protected function setUp()
57
    {
58
        $this->objectManager = $this->getObjectManager();
59
60
        $item = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->getMock();
61
        $item->method('getTitle')->willReturn('Dummy title');
62
63
        $parentItems = [$item];
64
65
        $menu = $this->getMockBuilder(Menu::class)->disableOriginalConstructor()->getMock();
66
        $menu->method('getParentItems')->willReturn($parentItems);
67
68
        $block = $this->getMockBuilder(AbstractBlock::class)
69
            ->disableOriginalConstructor()
70
            ->setMethods(['getMenuModel', 'setActive', 'toHtml'])
71
            ->getMock();
72
        $block->method('getMenuModel')->willReturn($menu);
73
74
        $layout = $this->getMockBuilder(LayoutInterface::class)->disableOriginalConstructor()->getMock();
75
        $layout->method('getBlock')->willReturn($block);
76
        $layout->method('createBlock')->willReturn($block);
77
78
        $title = $this->getMockBuilder(Title::class)->disableOriginalConstructor()->getMock();
79
80
        $config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
81
        $config->method('getTitle')->willReturn($title);
82
83
        $page = $this->getMockBuilder(Page::class)->disableOriginalConstructor()->getMock();
84
        $page->method('getConfig')->willReturn($config);
85
86
        $view = $this->getMockBuilder(ViewInterface::class)->disableOriginalConstructor()->getMock();
87
        $view->method('getLayout')->willReturn($layout);
88
        $view->method('getPage')->willReturn($page);
89
90
        $authorization = $this->getMockBuilder(AuthorizationInterface::class)->disableOriginalConstructor()->getMock();
91
        $authorization->method('isAllowed')->willReturn(true);
92
93
        $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
94
        $context->method('getView')->willReturn($view);
95
        $context->method('getAuthorization')->willReturn($authorization);
96
97
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, ['context' => $context]);
98
    }
99
100
    public function testExecute()
101
    {
102
        $result = $this->classToTest->execute();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $this->classToTest->execute() (which targets Payone\Core\Controller\A...mation\Index::execute()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
103
        $this->assertNull($result);
104
    }
105
}
106