Test Failed
Push — master ( 4be781...b621d9 )
by Edward
12:55
created

testGetOutput_NoExecCalled_ThrowsException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UniLex\Example\Brainfuck\Test;
6
7
use PHPUnit\Framework\TestCase;
8
use Remorhaz\UniLex\Example\Brainfuck\Exception as BrainfuckException;
9
use Remorhaz\UniLex\Example\Brainfuck\Interpreter;
10
use Remorhaz\UniLex\Exception as UniLexException;
11
12
/**
13
 * @covers \Remorhaz\UniLex\Example\Brainfuck\Interpreter
14
 */
15
class InterpreterTest extends TestCase
16
{
17
    /**
18
     * @throws BrainfuckException
19
     * @throws UniLexException
20
     */
21
    public function testExec_ValidInput_GetOutputReturnsMatchingValue(): void
22
    {
23
        $code =
24
            "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++" .
25
            ".>+.+++++++..+++.>++.<<+++++++++++++++.>.+++." .
26
            "------.--------.>+.>.";
27
        $interpreter = new Interpreter();
28
        $interpreter->exec($code);
29
        $actualValue = $interpreter->getOutput();
30
        self::assertSame("Hello World!\n", $actualValue);
31
    }
32
33
    /**
34
     * @throws BrainfuckException
35
     */
36
    public function testGetOutput_NoExecCalled_ThrowsException(): void
37
    {
38
        $interpreter = new Interpreter();
39
40
        $this->expectException(BrainfuckException::class);
41
        $this->expectExceptionMessage('Output is not defined');
42
        $interpreter->getOutput();
43
    }
44
}
45