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

RuntimeTest::providerNonPositiveMemory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
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\Command\OutputCommand;
9
use Remorhaz\UniLex\Example\Brainfuck\Exception as BrainfuckException;
10
use Remorhaz\UniLex\Example\Brainfuck\Runtime;
11
12
/**
13
 * @covers \Remorhaz\UniLex\Example\Brainfuck\Runtime
14
 * @covers \Remorhaz\UniLex\Example\Brainfuck\Command\OutputCommand
15
 */
16
class RuntimeTest extends TestCase
17
{
18
    /**
19
     * @param int $memory
20
     * @dataProvider providerNonPositiveMemory
21
     * @throws BrainfuckException
22
     */
23
    public function testConstruct_NonPositiveMemory_ThrowsException(int $memory): void
24
    {
25
        $this->expectException(BrainfuckException::class);
26
        $this->expectExceptionMessage('Memory amount must be positive');
27
        new Runtime($memory);
28
    }
29
30
    public function providerNonPositiveMemory(): array
31
    {
32
        return [
33
            'Zero memory' => [0],
34
            'Negative memory' => [-1],
35
        ];
36
    }
37
38
    /**
39
     * @throws BrainfuckException
40
     */
41
    public function testGetOutput_NoOutputCommandsExecuted_ReturnsEmptyString(): void
42
    {
43
        $actualValue = (new Runtime())->getOutput();
44
        self::assertSame('', $actualValue);
45
    }
46
47
    /**
48
     * @throws BrainfuckException
49
     */
50
    public function testGetOutput_OutputCommandExecuted_ReturnsMatchingString(): void
51
    {
52
        $runtime = new Runtime();
53
        $command = new OutputCommand($runtime);
54
        $runtime->addCommand($command);
55
        $command->exec();
56
        $actualValue = $runtime->getOutput();
57
        self::assertSame("\0", $actualValue);
58
    }
59
}
60