Skip to content

Commit

Permalink
Add test for multi union, multi where binding order problem
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsvdanker committed Apr 11, 2024
1 parent b512794 commit 3e87617
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/Integration/Database/EloquentCursorPaginateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,37 @@ public function testPaginationWithMultipleWhereClauses()
);
}

public function testPaginationWithMultipleUnionAndMultipleWhereClauses()
{
TestPost::create(['title' => 'Post A', 'user_id' => 100]);
TestPost::create(['title' => 'Post B', 'user_id' => 101]);

$table1 = TestPost::select(['id', 'title', 'user_id'])->where('user_id', 100);
$table2 = TestPost::select(['id', 'title', 'user_id'])->where('user_id', 101);
$table3 = TestPost::select(['id', 'title', 'user_id'])->where('user_id', 101);

$columns = ['id'];
$cursorName = 'cursor-name';
$cursor = new Cursor(['id' => 1]);

$result = $table1->toBase()
->union($table2->toBase())
->union($table3->toBase())
->orderBy('id', 'asc')
->cursorPaginate(1, $columns, $cursorName, $cursor);

$this->assertSame(['id'], $result->getOptions()['parameters']);

// Post B is the result of the second query.
$postB = $table2->where('id', '>', 1)->first();
$this->assertEquals('Post B', $postB->title);

// So the cursor paginated query should at least have 1 result
$this->assertCount(1, $result->items());
// And it should be Post B
$this->assertEquals('Post B', current($result->items())->title);
}

public function testPaginationWithAliasedOrderBy()
{
for ($i = 1; $i <= 6; $i++) {
Expand Down

0 comments on commit 3e87617

Please sign in to comment.