Completed
Push — master ( fe4d16...77dac1 )
by Florian
26:03
created

StatusMappingTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 86
Duplicated Lines 16.28 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 2
dl 14
loc 86
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 38 1
A testRenderCellTemplate() 0 13 1
A testGetArrayRows() 7 7 1
A testGetArrayRowsSerialized() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Adminhtml\Config\Form\Field;
28
29
use Payone\Core\Block\Adminhtml\Config\Form\Field\StatusMapping as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Framework\Data\Form\Element\Factory;
32
use Magento\Sales\Model\ResourceModel\Order\Status\Collection;
33
use Payone\Core\Model\Source\TransactionStatus;
34
use Magento\Framework\Data\Form\Element\AbstractElement;
35
use Magento\Framework\Data\Form\Element\Multiselect;
36
use Magento\Framework\Data\Form\AbstractForm;
37
38
class StatusMappingTest extends \PHPUnit_Framework_TestCase
39
{
40
    /**
41
     * @var ClassToTest
42
     */
43
    private $classToTest;
44
45
    /**
46
     * @var ObjectManager
47
     */
48
    private $objectManager;
49
50
    /**
51
     * @var Multiselect|\PHPUnit_Framework_MockObject_MockObject
52
     */
53
    private $element;
54
55
    protected function setUp()
56
    {
57
        $this->objectManager = new ObjectManager($this);
58
59
        $form = $this->getMockBuilder(AbstractForm::class)->disableOriginalConstructor()->getMock();
60
61
        $element = $this->getMockBuilder(AbstractElement::class)
62
            ->disableOriginalConstructor()
63
            ->setMethods(['setForm', 'getForm', 'setName', 'setHtmlId', 'setValues'])
64
            ->getMock();
65
        $element->method('getForm')->willReturn($form);
66
67
        $elementFactory = $this->getMockBuilder(Factory::class)->disableOriginalConstructor()->getMock();
68
        $elementFactory->method('create')->willReturn($element);
69
70
        $orderStatus = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
71
        $orderStatus->method('toOptionArray')->willReturn([
72
            ['value' => 'complete', 'label' => 'Complete']
73
        ]);
74
75
        $transactionStatus = $this->getMockBuilder(TransactionStatus::class)->disableOriginalConstructor()->getMock();
76
        $transactionStatus->method('toOptionArray')->willReturn([
77
            ['value' => 'paid', 'label' => 'PAID']
78
        ]);
79
80
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
81
            'elementFactory' => $elementFactory,
82
            'orderStatus' => $orderStatus,
83
            'transactionStatus' => $transactionStatus
84
        ]);
85
86
        $form = $this->objectManager->getObject(AbstractForm::class);
87
        $this->element = $this->objectManager->getObject(Multiselect::class);
88
        $this->element->setForm($form);
89
        $this->classToTest->setElement($this->element);
90
        $this->classToTest->setForm($form);
91
        $this->classToTest->addColumn('dummy', ['label' => __('Dummy')]);
92
    }
93
94
    public function testRenderCellTemplate()
95
    {
96
        $this->element->setValue([['te<s>t' => 't<e>st', 'data&1' => 'da&ta1']]);
97
98
        $result = $this->classToTest->renderCellTemplate('txaction');
99
        $this->assertNotEmpty($result);
100
101
        $result = $this->classToTest->renderCellTemplate('state_status');
102
        $this->assertNotEmpty($result);
103
104
        $result = $this->classToTest->renderCellTemplate('dummy');
105
        $this->assertNotEmpty($result);
106
    }
107
108 View Code Duplication
    public function testGetArrayRows()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
    {
110
        $this->element->setValue([['te<s>t' => 't<e>st', 'data&1' => 'da&ta1']]);
111
112
        $result = $this->classToTest->getArrayRows();
113
        $this->assertNotEmpty($result);
114
    }
115
116 View Code Duplication
    public function testGetArrayRowsSerialized()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        $this->element->setValue(serialize([['te<s>t' => 't<e>st', 'data&1' => 'da&ta1']]));
119
120
        $result = $this->classToTest->getArrayRows();
121
        $this->assertNotEmpty($result);
122
    }
123
}
124