Completed
Push — master ( a29d2d...4681dd )
by Hannes
10:53 queued 08:08
created

ParserSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace spec\byrokrat\autogiro;
6
7
use byrokrat\autogiro\Parser;
8
use byrokrat\autogiro\Grammar;
9
use byrokrat\autogiro\Processor\Processor;
10
use byrokrat\autogiro\Tree\Node;
11
use byrokrat\autogiro\Exception\ParserException;
12
use PhpSpec\ObjectBehavior;
13
use Prophecy\Argument;
14
15
class ParserSpec extends ObjectBehavior
16
{
17
    function let(Grammar $grammar, Processor $processor)
18
    {
19
        $this->beConstructedWith($grammar, $processor);
20
    }
21
22
    function it_is_initializable()
23
    {
24
        $this->shouldHaveType(Parser::CLASS);
25
    }
26
27
    function it_throws_exception_if_parser_fails($grammar)
28
    {
29
        $grammar->parse('')->willThrow(new \Exception);
30
        $this->shouldThrow(ParserException::CLASS)->duringParse('');
31
    }
32
33
    function it_throws_exception_if_processor_fails($grammar, $processor, Node $node)
34
    {
35
        $grammar->parse('')->willReturn($node);
36
        $node->accept($processor)->shouldBeCalled();
37
        $processor->hasErrors()->willReturn(true)->shouldBeCalled();
38
        $processor->getErrors()->willReturn(['error'])->shouldBeCalled();
39
        $this->shouldThrow(ParserException::CLASS)->duringParse('');
40
    }
41
}
42