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

CheckboxesFieldUnitTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorWithTitle() 0 15 1
A getFieldMock() 0 34 1
A testConstructor() 0 11 1
1
<?php
2
namespace Mezon\Gui\Field\Tests;
3
4
class CheckboxesFieldUnitTest extends \PHPUnit\Framework\TestCase
5
{
6
7
    /**
8
     * Method returns mock object of the custom field
9
     *
10
     * @return object mock object of the custom field
11
     */
12
    protected function getFieldMock(array $items = [
13
        [
14
            'id' => 1
15
        ]
16
    ]): object
17
    {
18
        $mock = $this->getMockBuilder(\Mezon\Gui\Field\CheckboxesField::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

18
        $mock = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(\Mezon\Gui\Field\CheckboxesField::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...
19
            ->setConstructorArgs(
20
            [
21
                [
22
                    'name' => 'name',
23
                    'required' => 1,
24
                    'disabled' => 1,
25
                    'custom' => 1,
26
                    'name-prefix' => 'prefix',
27
                    'batch' => 1,
28
                    'toggler' => 'toggler-name',
29
                    'toggle-value' => 3,
30
                    'bind-field' => 'id',
31
                    'session-id' => 'sid',
32
                    'remote-source' => 'http://ya.ru',
33
                    'type' => 'int',
34
                    'class' => 'cls'
35
                ],
36
                ''
37
            ])
38
            ->setMethods([
39
            'getExternalRecords'
40
        ])
41
            ->getMock();
42
43
        $mock->method('getExternalRecords')->willReturn($items);
44
45
        return $mock;
46
    }
47
48
    /**
49
     * Testing constructor
50
     */
51
    public function testConstructor()
52
    {
53
        // setup
54
        $field = $this->getFieldMock();
55
56
        // test body
57
        $content = $field->html();
58
59
        // assertions
60
        $this->assertStringContainsString('type="checkbox"', $content);
61
        $this->assertStringContainsString('class="cls"', $content);
62
    }
63
64
    /**
65
     * Testing constructor
66
     */
67
    public function testConstructorWithTitle()
68
    {
69
        // setup
70
        $field = $this->getFieldMock([
71
            [
72
                'id' => 1,
73
                'title' => 'item-title'
74
            ]
75
        ]);
76
77
        // test body
78
        $content = $field->html();
79
80
        // assertions
81
        $this->assertStringContainsString('item-title', $content);
82
    }
83
}
84