FieldUnitTest::testNoNameException()   A
last analyzed

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
use PHPUnit\Framework\TestCase;
5
6
/**
7
 *
8
 * @psalm-suppress PropertyNotSetInConstructor
9
 */
10
class FieldUnitTest extends TestCase
11
{
12
13
    /**
14
     * Testing constructor
15
     */
16
    public function testNoNameException(): void
17
    {
18
        $this->expectException(\Exception::class);
19
        new \Mezon\Gui\Field([], '');
20
    }
21
22
    /**
23
     * Testing setters
24
     */
25
    public function testNameSetter(): void
26
    {
27
        // test body
28
        $field = new \Mezon\Gui\Field(json_decode(file_get_contents(__DIR__ . '/conf/name-setter.json'), true), '');
29
30
        // assertions
31
        $this->assertStringContainsString('prefixfield-name000', $field->html(), 'Invalid field "name" value');
32
    }
33
34
    /**
35
     * Testing setters
36
     */
37
    public function testRequiredSetter(): void
38
    {
39
        // test body
40
        $field = new \Mezon\Gui\Field(json_decode(file_get_contents(__DIR__ . '/conf/required-setter.json'), true), '');
41
42
        // assertions
43
        $this->assertStringContainsString('prefixfield-name1111select2', $field->html(), 'Invalid field "name" value');
44
    }
45
46
    /**
47
     * Testing exception if type not set
48
     */
49
    public function testTypeException(): void
50
    {
51
        // setup and assertions
52
        $this->expectExceptionCode(- 2);
53
54
        // test body
55
        new \Mezon\Gui\Field([], '');
56
    }
57
58
    /**
59
     * Testing setters
60
     */
61
    public function testHasLabelSetter(): void
62
    {
63
        // test body
64
        $field = new \Mezon\Gui\Field(json_decode(file_get_contents(__DIR__ . '/conf/has-label-setter.json'), true), '');
65
66
        // assertions
67
        $this->assertTrue($field->hasLabel());
68
    }
69
}
70