getErrorsAsArray($lexer); $this->assertCount(0, $lexerErrors); $parser = new Parser($lexer->list); $parserErrors = $this->getErrorsAsArray($parser); $this->assertCount(0, $parserErrors); $this->assertCount(2, $parser->statements); // phpcs:disable Generic.Files.LineLength.TooLong $expected = <<assertEquals($expected, $parser->statements[0]->build()); $this->assertEquals('SELECT * FROM categories', $parser->statements[1]->build()); } public function testWithHasErrors(): void { $sql = <<getErrorsAsArray($lexer); $this->assertCount(0, $lexerErrors); $parser = new Parser($lexer->list); $parserErrors = $this->getErrorsAsArray($parser); $this->assertCount(2, $parserErrors); } public function testWithEmbedParenthesis(): void { $sql = <<getErrorsAsArray($lexer); $this->assertCount(0, $lexerErrors); $parser = new Parser($lexer->list); $parserErrors = $this->getErrorsAsArray($parser); $this->assertCount(0, $parserErrors); // phpcs:disable Generic.Files.LineLength.TooLong $expected = <<assertEquals($expected, $parser->statements[0]->build()); } public function testWithHasUnclosedParenthesis(): void { $sql = <<getErrorsAsArray($lexer); $this->assertCount(0, $lexerErrors); $parser = new Parser($lexer->list); $parserErrors = $this->getErrorsAsArray($parser); $this->assertEquals($parserErrors[0][0], 'A closing bracket was expected.'); } public function testBuildWrongWithKeyword(): void { $this->expectExceptionMessage('Can not build a component that is not a WithKeyword'); WithKeyword::build(new stdClass()); } public function testBuildBadWithKeyword(): void { $this->expectExceptionMessage('No statement inside WITH'); WithKeyword::build(new WithKeyword('test')); } }