Completed
Pull Request — master (#144)
by
unknown
05:00
created

SerializedOrJsonTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testBeforeSave() 0 6 1
A testAfterLoad() 0 6 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\Model\Config\Backend;
28
29
use Payone\Core\Model\Config\Backend\SerializedOrJson as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Payone\Core\Test\Unit\BaseTestCase;
32
use Payone\Core\Test\Unit\PayoneObjectManager;
33
34
35
class SerializedOrJsonTest extends BaseTestCase
36
{
37
    /**
38
     * @var ClassToTest
39
     */
40
    private $classToTest;
41
42
    /**
43
     * @var ObjectManager|PayoneObjectManager
44
     */
45
    private $objectManager;
46
47
    protected function setUp()
48
    {
49
        $this->objectManager = $this->getObjectManager();
50
51
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
52
53
        ]);
54
    }
55
56
    public function testBeforeSave()
57
    {
58
        $this->classToTest->setValue(['test' => '123']);
0 ignored issues
show
Documentation introduced by
array('test' => '123') is of type array<string,string,{"test":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
        $result = $this->classToTest->beforeSave();
60
        $this->assertInstanceOf(ClassToTest::class, $result);
61
    }
62
63
    public function testAfterLoad()
64
    {
65
        $this->classToTest->setValue(json_encode(['test' => '123']));
66
        $result = $this->classToTest->afterLoad();
67
        $this->assertInstanceOf(ClassToTest::class, $result);
68
    }
69
}
70