|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Mamazu\DocumentationParser\Parser\Parser; |
| 4 | + |
| 5 | +use Gregwar\RST\Document; |
| 6 | +use Gregwar\RST\Environment; |
| 7 | +use Gregwar\RST\ErrorManager; |
| 8 | +use Gregwar\RST\HTML\Nodes\CodeNode; |
| 9 | +use Gregwar\RST\Parser; |
| 10 | +use Mamazu\DocumentationParser\Parser\Parser\ParserInterface; |
| 11 | +use PhpSpec\ObjectBehavior; |
| 12 | +use Prophecy\Argument; |
| 13 | + |
| 14 | +class RstParserSpec extends ObjectBehavior |
| 15 | +{ |
| 16 | + public function let(Parser $parser): void |
| 17 | + { |
| 18 | + $this->beConstructedWith($parser); |
| 19 | + } |
| 20 | + |
| 21 | + public function it_is_a_parser(): void |
| 22 | + { |
| 23 | + $this->shouldImplement(ParserInterface::class); |
| 24 | + } |
| 25 | + |
| 26 | + public function it_only_allows_rst_files(): void |
| 27 | + { |
| 28 | + $this->canParse('docs.rst')->shouldReturn(true); |
| 29 | + $this->canParse('hello.py')->shouldReturn(false); |
| 30 | + $this->canParse('hello.RsT')->shouldReturn(true); |
| 31 | + } |
| 32 | + |
| 33 | + public function it_parses_code_blocks( |
| 34 | + Parser $parser, |
| 35 | + Document $document, |
| 36 | + Environment $environment, |
| 37 | + ErrorManager $errorManager, |
| 38 | + CodeNode $codeNode |
| 39 | + ): void |
| 40 | + { |
| 41 | + $parser->getEnvironment()->willReturn($environment); |
| 42 | + $environment->getErrorManager()->willReturn($errorManager); |
| 43 | + |
| 44 | + $errorManager->abortOnError(false)->shouldBeCalled(); |
| 45 | + |
| 46 | + $parser->parseFile('documentation.rst')->shouldBeCalled()->willReturn($document); |
| 47 | + $document->getNodes(Argument::type(\Closure::class))->willReturn([ $codeNode ]); |
| 48 | + $codeNode->getValue()->willReturn('echo "PHP";'); |
| 49 | + $codeNode->getStartingLineNumber()->willReturn(12); |
| 50 | + $codeNode->getLanguage()->willReturn('php'); |
| 51 | + |
| 52 | + $result = $this->parse('documentation.rst'); |
| 53 | + $result->shouldHaveCount(1); |
| 54 | + $result[0]->getFileName()->shouldBe('documentation.rst'); |
| 55 | + $result[0]->getContent()->shouldBe('echo "PHP";'); |
| 56 | + $result[0]->getRelativeLineNumber()->shouldBe(12); |
| 57 | + $result[0]->getType()->shouldBe('php'); |
| 58 | + } |
| 59 | +} |
0 commit comments