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

FieldUnitTest::testNoNameException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Mezon\Gui\Tests;
3
4
class FieldUnitTest extends \PHPUnit\Framework\TestCase
5
{
6
7
    /**
8
     * Testing constructor
9
     */
10
    public function testNoNameException()
11
    {
12
        $this->expectException(\Exception::class);
13
        new \Mezon\Gui\Field([], '');
14
    }
15
16
    /**
17
     * Testing setters
18
     */
19
    public function testNameSetter()
20
    {
21
        // test body
22
        $field = new \Mezon\Gui\Field(json_decode(file_get_contents(__DIR__ . '/conf/name-setter.json'), true), '');
23
24
        // assertions
25
        $this->assertStringContainsString('prefixfield-name000', $field->html(), 'Invalid field "name" value');
26
    }
27
28
    /**
29
     * Testing setters
30
     */
31
    public function testRequiredSetter()
32
    {
33
        // test body
34
        $field = new \Mezon\Gui\Field(json_decode(file_get_contents(__DIR__ . '/conf/required-setter.json'), true), '');
35
36
        // assertions
37
        $this->assertStringContainsString('prefixfield-name1111select2', $field->html(), 'Invalid field "name" value');
38
    }
39
40
    /**
41
     * Testing exception if type not set
42
     */
43
    public function testTypeException(): void
44
    {
45
        // setup and assertions
46
        $this->expectExceptionCode(- 2);
47
48
        // test body
49
        new \Mezon\Gui\Field([], '');
50
    }
51
52
    /**
53
     * Testing setters
54
     */
55
    public function testHasLabelSetter()
56
    {
57
        // test body
58
        $field = new \Mezon\Gui\Field(json_decode(file_get_contents(__DIR__ . '/conf/has-label-setter.json'), true), '');
59
60
        // assertions
61
        $this->assertTrue($field->hasLabel());
62
    }
63
}
64