0 and comments >= 1 and comments and not comments = 0', 'EXISTS(comments, EMPTY)'], ['comments and not (comments = 0 or not comments)', 'EXISTS(comments, EMPTY)'], // Flatten relationship inexistance. ['not comments and not comments', 'NOT_EXISTS(comments, EMPTY)'], ['not comments and not (comments or comments)', 'NOT_EXISTS(comments, EMPTY)'], ['comments = 0 and comments < 1 and comments <= 0 and not comments and not comments > 0', 'NOT_EXISTS(comments, EMPTY)'], // Flatten relationship count. ['comments > 1 and comments > 1', 'EXISTS(comments, EMPTY) > 1'], ['comments > 1 and comments >= 2', 'EXISTS(comments, EMPTY) > 1'], ['comments >= 2 and comments > 1', 'EXISTS(comments, EMPTY) >= 2'], ['comments = 2 and comments = 2', 'EXISTS(comments, EMPTY) = 2'], // Flatten relationships complex examples. ['comments.title = A comments.title = B', 'EXISTS(comments, AND(title = A, title = B))'], ['comments.title = A or comments.title = B', 'EXISTS(comments, OR(title = A, title = B))'], ['comments.title = A comments.title = B and foobar', 'AND(EXISTS(comments, AND(title = A, title = B)), foobar)'], ['comments.author.name = John and comments.title = "My Comment"', 'EXISTS(comments, AND(EXISTS(author, name = John), title = My Comment))'], ['comments.author.name = John and comments.author.name = Jane', 'EXISTS(comments, EXISTS(author, AND(name = John, name = Jane)))'], ['comments.author.name = John or comments.author.name = Jane', 'EXISTS(comments, EXISTS(author, OR(name = John, name = Jane)))'], ['(comments.title = A and comments.title = B) and (comments.title = C and comments.title = D)', 'EXISTS(comments, AND(title = A, title = B, title = C, title = D))'], ['(comments.title = A or comments.title = B) or (comments.title = C or comments.title = D)', 'EXISTS(comments, OR(title = A, title = B, title = C, title = D))'], // Keep relationships separate if merging them changes the behavious of the query. ['comments and not comments', 'AND(EXISTS(comments, EMPTY), NOT_EXISTS(comments, EMPTY))'], ['comments and comments > 10', 'AND(EXISTS(comments, EMPTY), EXISTS(comments, EMPTY) > 10)'], ['comments = 3 or not comments = 3', 'OR(EXISTS(comments, EMPTY) = 3, EXISTS(comments, EMPTY) != 3)'], ['comments.title = A or comments > 10', 'OR(EXISTS(comments, title = A), EXISTS(comments, EMPTY) > 10)'], ['comments.title = A foobar comments > 10', 'AND(EXISTS(comments, title = A), foobar, EXISTS(comments, EMPTY) > 10)'], ['comments.title = A or comments.title = B price > 10', 'OR(EXISTS(comments, title = A), AND(EXISTS(comments, title = B), price > 10))'], ]; } /** * @test * @dataProvider success * @param $input * @param $expected */ public function visitor_optimize_ast_success($input, $expected) { $this->assertAstEquals($input, $expected); } }