Passed
Push — master ( dab6df...ec728c )
by Alex
02:15
created

CustomFieldsModelMock   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
eloc 5
c 1
b 0
f 1
dl 0
loc 11
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConnection() 0 6 1
1
<?php
2
3
class PdoCrudMock extends \Mezon\PdoCrud\PdoCrud
4
{
5
6
    public $selectResult = [];
7
8
    public function select(
9
        string $fields,
10
        string $tableNames,
11
        string $where = '1 = 1',
12
        int $from = 0,
13
        int $limit = 1000000): array
14
    {
15
        return $this->selectResult;
16
    }
17
}
18
19
class CustomFieldsModelMock extends \Mezon\Service\CustomFieldsModel
20
{
21
22
    public $selectResult = [];
23
24
    public function getConnection(string $connectionName = 'default-db-connection')
0 ignored issues
show
Unused Code introduced by
The parameter $connectionName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
    public function getConnection(/** @scrutinizer ignore-unused */ string $connectionName = 'default-db-connection')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        $mock = new \PdoCrudMock();
27
        $mock->selectResult = $this->selectResult;
28
29
        return $mock;
30
    }
31
}
32
33
class CustomFieldsModelUnitTest extends \PHPUnit\Framework\TestCase
34
{
35
36
    /**
37
     * Data provider
38
     *
39
     * @return array testing data
40
     */
41
    public function getFieldForObjectDataProvider(): array
42
    {
43
        return [
44
            [
45
                [],
46
                'default'
47
            ],
48
            [
49
                [
50
                    [
51
                        'field_value' => '111'
52
                    ]
53
                ],
54
                '111'
55
            ]
56
        ];
57
    }
58
59
    /**
60
     * Testing getFieldForObject
61
     *
62
     * @param array $data custom fields of the object
63
     * @param string $expectedResult expected result of the call getFieldForObject
64
     * @dataProvider getFieldForObjectDataProvider
65
     */
66
    public function testGetExistingCustomField(array $data, string $expectedResult): void
67
    {
68
        // setup
69
        $model = new \CustomFieldsModelMock('entity');
70
        $model->selectResult = $data;
71
72
        // test body
73
        $actualResult = $model->getFieldForObject(1, 'id', 'default');
74
75
        // assertions
76
        $this->assertEquals($expectedResult, $actualResult);
77
    }
78
}
79