runParserTest($test); } /** * @return string[][] */ public static function parseWith(): array { return [ ['parser/parseWithStatement'], ['parser/parseWithStatement1'], ['parser/parseWithStatement2'], ['parser/parseWithStatement3'], ['parser/parseWithStatement4'], ['parser/parseWithStatement5'], ['parser/parseWithStatement6'], ['parser/parseWithStatement7'], ['parser/parseWithStatementErr'], ['parser/parseWithStatementErr1'], ['parser/parseWithStatementErr2'], ['parser/parseWithStatementErr3'], ['parser/parseWithStatementErr4'], ['parser/parseWithStatementErr5'], ['parser/parseWithStatementErr6'], ['parser/parseWithStatementErr7'], ['parser/parseWithStatementErr8'], ]; } public function testWith(): void { $sql = <<getErrorsAsArray($lexer); $this->assertCount(0, $lexerErrors); $parser = new Parser($lexer->list); $parserErrors = $this->getErrorsAsArray($parser); $this->assertCount(0, $parserErrors); $this->assertCount(1, $parser->statements); // phpcs:disable Generic.Files.LineLength.TooLong $expected = <<assertEquals($expected, $parser->statements[0]->build()); } public function testWithHasErrors(): void { $sql = <<getErrorsAsArray($lexer); $this->assertCount(0, $lexerErrors); $parser = new Parser($lexer->list); $parserErrors = $this->getErrorsAsArray($parser); $this->assertCount(4, $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')); } }