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

InterpreterTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testExec_ValidInput_GetOutputReturnsMatchingValue() 0 10 1
A testGetOutput_NoExecCalled_ThrowsException() 0 7 1
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