Completed
Push — master ( dd1955...c3a87b )
by Michael
10s
created

testWhenCharacterIsNotAControl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace PhpSchool\TerminalTest;
4
5
use PhpSchool\Terminal\InputCharacter;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * @author Aydin Hassan <[email protected]>
10
 */
11
class InputCharacterTest extends TestCase
12
{
13
    public function testWhenCharacterIsAControl() : void
14
    {
15
        $char = new InputCharacter("\n");
16
17
        self::assertTrue($char->isControl());
18
        self::assertFalse($char->isNotControl());
19
        self::assertEquals('ENTER', $char->getControl());
20
        self::assertEquals("\n", $char->get());
21
        self::assertEquals("\n", $char->__toString());
22
    }
23
24
    public function testWhenCharacterIsNotAControl() : void
25
    {
26
        $char = new InputCharacter('p');
27
28
        self::assertFalse($char->isControl());
29
        self::assertTrue($char->isNotControl());
30
        self::assertEquals('p', $char->get());
31
        self::assertEquals('p', $char->__toString());
32
    }
33
34
    public function testExceptionIsThrownIfGetControlCalledWhenNotAControl() : void
35
    {
36
        self::expectException(\RuntimeException::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        self::/** @scrutinizer ignore-call */ 
37
              expectException(\RuntimeException::class);
Loading history...
37
        self::expectExceptionMessage('Character "p" is not a control');
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        self::/** @scrutinizer ignore-call */ 
38
              expectExceptionMessage('Character "p" is not a control');
Loading history...
38
39
        $char = new InputCharacter('p');
40
        $char->getControl();
41
    }
42
43
    public function testGetControls() : void
44
    {
45
        self::assertEquals(
46
            [
47
                'UP',
48
                'DOWN',
49
                'RIGHT',
50
                'LEFT',
51
                'CTRLA',
52
                'CTRLB',
53
                'CTRLE',
54
                'CTRLF',
55
                'BACKSPACE',
56
                'CTRLW',
57
                'ENTER',
58
                'TAB',
59
            ],
60
            InputCharacter::getControls()
61
        );
62
    }
63
64
    public function testFromControlNameThrowsExceptionIfControlDoesNotExist() : void
65
    {
66
        self::expectException(\InvalidArgumentException::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        self::/** @scrutinizer ignore-call */ 
67
              expectException(\InvalidArgumentException::class);
Loading history...
67
        self::expectExceptionMessage('Control "w" does not exist');
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        self::/** @scrutinizer ignore-call */ 
68
              expectExceptionMessage('Control "w" does not exist');
Loading history...
68
69
        InputCharacter::fromControlName('w');
70
    }
71
72
    public function testFromControlName() : void
73
    {
74
        $char = InputCharacter::fromControlName(InputCharacter::UP);
75
76
        self::assertTrue($char->isControl());
77
        self::assertEquals('UP', $char->getControl());
78
        self::assertEquals("\033[A", $char->get());
79
    }
80
81
    public function testControlExists() : void
82
    {
83
        self::assertTrue(InputCharacter::controlExists(InputCharacter::UP));
84
        self::assertFalse(InputCharacter::controlExists('w'));
85
    }
86
}
87