CustomFieldUnitTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 32
c 1
b 1
f 0
dl 0
loc 60
rs 10
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
use Mezon\Gui\Field\CustomField;
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 *
9
 * @psalm-suppress PropertyNotSetInConstructor
10
 */
11
class CustomFieldUnitTest extends TestCase
12
{
13
14
    /**
15
     * Method returns mock object of the custom field
16
     *
17
     * @return object mock object of the custom field
18
     */
19
    protected function getFieldMock(): object
20
    {
21
        $mock = $this->getMockBuilder(CustomField::class)
22
            ->setConstructorArgs(
23
            [
24
                [
25
                    'name' => 'name',
26
                    'required' => 1,
27
                    'disabled' => 1,
28
                    'custom' => 1,
29
                    'name-prefix' => 'prefix',
30
                    'batch' => 1,
31
                    'toggler' => 'toggler-name',
32
                    'toggle-value' => 3,
33
                    'type' => 'integer',
34
                    'fields' => [],
35
                    'class' => 'cls'
36
                ],
37
                ''
38
            ])
39
            ->onlyMethods([
40
            'getFieldTemplate'
41
        ])
42
            ->getMock();
43
44
        $mock->method('getFieldTemplate')->willReturn(
45
            'class:{class} name:{name} required:{required} disabled:{disabled} custom:{custom} name-prefix:{name-prefix} batch:{batch} toggler:{toggler} toggler:{toggle-value}');
46
47
        return $mock;
48
    }
49
50
    /**
51
     * Testing constructor
52
     */
53
    public function testConstructor():void
54
    {
55
        // setup
56
        $field = $this->getFieldMock();
57
58
        // test body
59
        $content = $field->html();
60
61
        // assertions
62
        $this->assertStringContainsString('name:name', $content);
63
        $this->assertStringContainsString('required:1', $content);
64
        $this->assertStringContainsString('disabled:1', $content);
65
        $this->assertStringContainsString('custom:1', $content);
66
        $this->assertStringContainsString('name-prefix:prefix', $content);
67
        $this->assertStringContainsString('batch:1', $content);
68
        $this->assertStringContainsString('toggler:toggler-name', $content);
69
        $this->assertStringContainsString('toggler:3', $content);
70
        $this->assertStringContainsString('class:cls', $content);
71
    }
72
}
73