Completed
Push — master ( 2b7ec8...e65692 )
by Alex
09:34
created

RecordFieldUnitTest::getFieldMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 29
nc 1
nop 0
dl 0
loc 47
rs 9.456
c 0
b 0
f 0
1
<?php
2
namespace Mezon\Gui\Field\Tests;
3
4
use Mezon\Gui\Field\RecordField;
5
use PHPUnit\Framework\TestCase;
6
7
class RecordFieldUnitTest extends TestCase
8
{
9
10
    /**
11
     * Method returns mock object of the custom field
12
     *
13
     * @return object mock object of the custom field
14
     */
15
    protected function getFieldMock(): object
16
    {
17
        $mock = $this->getMockBuilder(RecordField::class)
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

17
        $mock = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(RecordField::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
18
            ->setConstructorArgs(
19
            [
20
                [
21
                    'name' => 'name',
22
                    'required' => 1,
23
                    'disabled' => 1,
24
                    'custom' => 1,
25
                    'name-prefix' => 'prefix',
26
                    'batch' => 1,
27
                    'toggler' => 'toggler-name',
28
                    'toggle-value' => 3,
29
                    'bind-field' => 'id',
30
                    'session-id' => 'sid',
31
                    'remote-source' => 'http://ya.ru',
32
                    'type' => 'remote',
33
                    'layout' => [
34
                        'rows' => [
35
                            [
36
                                "remote" => [
37
                                    "width" => 10
38
                                ]
39
                            ]
40
                        ]
41
                    ]
42
                ],
43
                ''
44
            ])
45
            ->setMethods([
46
            'getFields'
47
        ])
48
            ->getMock();
49
50
        $mock->method('getFields')->willReturn(
51
            [
52
                'id' => [
53
                    'type' => 'integer'
54
                ],
55
                'remote' => [
56
                    'type' => 'string',
57
                    'title' => 'remote-title'
58
                ]
59
            ]);
60
61
        return $mock;
62
    }
63
64
    /**
65
     * Testing constructor
66
     */
67
    public function testConstructor()
68
    {
69
        // setup
70
        $field = $this->getFieldMock();
71
72
        // test body
73
        $content = $field->html();
74
75
        // assertions
76
        $this->assertStringContainsString('name="prefix-remote"', $content, 'Name of the remote record was not found');
77
    }
78
}
79