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

CustomFieldUnitTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructor() 0 18 1
A getFieldMock() 0 29 1
1
<?php
2
namespace Mezon\Gui\Tests;
3
4
class CustomFieldUnitTest 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(): object
13
    {
14
        $mock = $this->getMockBuilder(\Mezon\Gui\Field\CustomField::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

14
        $mock = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(\Mezon\Gui\Field\CustomField::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...
15
            ->setConstructorArgs(
16
            [
17
                [
18
                    'name' => 'name',
19
                    'required' => 1,
20
                    'disabled' => 1,
21
                    'custom' => 1,
22
                    'name-prefix' => 'prefix',
23
                    'batch' => 1,
24
                    'toggler' => 'toggler-name',
25
                    'toggle-value' => 3,
26
                    'type' => 'integer',
27
                    'fields' => [],
28
                    'class' => 'cls'
29
                ],
30
                ''
31
            ])
32
            ->setMethods([
33
            'get_field_template'
34
        ])
35
            ->getMock();
36
37
        $mock->method('get_field_template')->willReturn(
38
            'class:{class} name:{name} required:{required} disabled:{disabled} custom:{custom} name-prefix:{name-prefix} batch:{batch} toggler:{toggler} toggler:{toggle-value}');
39
40
        return $mock;
41
    }
42
43
    /**
44
     * Testing constructor
45
     */
46
    public function testConstructor()
47
    {
48
        // setup
49
        $field = $this->getFieldMock();
50
51
        // test body
52
        $content = $field->html();
53
54
        // assertions
55
        $this->assertStringContainsString('name:name', $content);
56
        $this->assertStringContainsString('required:1', $content);
57
        $this->assertStringContainsString('disabled:1', $content);
58
        $this->assertStringContainsString('custom:1', $content);
59
        $this->assertStringContainsString('name-prefix:prefix', $content);
60
        $this->assertStringContainsString('batch:1', $content);
61
        $this->assertStringContainsString('toggler:toggler-name', $content);
62
        $this->assertStringContainsString('toggler:3', $content);
63
        $this->assertStringContainsString('class:cls', $content);
64
    }
65
}
66