* @mixin Parser */ class ParserSpec extends ObjectBehavior { function it_is_initializable() { $this->shouldHaveType('Madkom\NginxConfigurator\Parser'); } /** * @throws ParseFailureException */ function it_can_parse_directive() { /** @var RootNode $root */ $root = $this->parse(<<shouldReturnAnInstanceOf(RootNode::class); $directives = $root->search(function (Node $node) { return $node; })->getWrappedObject(); /** @var Directive $directive */ foreach ($directives as $directive) { break; } Assert::assertEquals($directive->getName(), 'internal'); Assert::assertInstanceOf(Traversable::class, $directive->getParams()); } function it_can_parse_multiple_directives_with_params() { $root = $this->parse(<<shouldReturnAnInstanceOf(RootNode::class); $directives = $root->search(function (Node $node) { return $node; })->getWrappedObject(); /** @var Directive $directive */ foreach ($directives as $index => $directive) { switch ($index) { case 0: Assert::assertEquals($directive->getName(), 'internal'); Assert::assertInstanceOf(Traversable::class, $directive->getParams()); break; case 1: Assert::assertEquals($directive->getName(), 'sendfile'); Assert::assertInstanceOf(Traversable::class, $directive->getParams()); break; case 2: Assert::assertEquals($directive->getName(), 'set'); Assert::assertInstanceOf(Traversable::class, $directive->getParams()); break; } } } function it_can_parse_multiple_directives_with_params_in_context() { $root = $this->parse(<<shouldReturnAnInstanceOf(RootNode::class); $contexts = $root->search(function (Node $node) { return $node; })->getWrappedObject(); /** @var Context $context */ foreach ($contexts as $index => $context) { switch ($index) { case 0: Assert::assertInstanceOf(Server::class, $context); /** @var Directive $directive */ foreach ($context as $index => $directive) { switch ($index) { case 0: Assert::assertEquals('internal', $directive->getName()); break; case 1: Assert::assertEquals('sendfile', $directive->getName()); break; case 2: Assert::assertEquals('set', $directive->getName()); } } break; } } } function it_can_parse_multiple_directives_with_params_in_multiple_contexts() { $root = $this->parse(<<shouldReturnAnInstanceOf(RootNode::class); $contexts = $root->search(function (Node $node) { return $node; })->getWrappedObject(); /** @var Context $context */ foreach ($contexts as $index => $context) { switch ($index) { case 0: Assert::assertInstanceOf(Server::class, $context); /** @var Directive $directive */ foreach ($context as $index => $directive) { switch ($index) { case 0: Assert::assertEquals('internal', $directive->getName()); break; case 1: Assert::assertEquals('sendfile', $directive->getName()); break; case 2: Assert::assertEquals('set', $directive->getName()); break; case 3: Assert::assertInstanceOf(Location::class, $directive); break; } } break; case 1: Assert::assertInstanceOf(Directive::class, $context); Assert::assertEquals('sendfile', $context->getName()); break; } } } }