Skip to content

Commit 5593882

Browse files
committed
Add eloquent test for cursor pagination with union and multiple aliases
1 parent 678b6f6 commit 5593882

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/Integration/Database/EloquentCursorPaginateTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ protected function afterRefreshingDatabase()
2121

2222
Schema::create('test_users', function ($table) {
2323
$table->increments('id');
24+
$table->string('name')->nullable();
2425
$table->timestamps();
2526
});
2627
}
@@ -167,6 +168,32 @@ public function testPaginationWithMultipleWhereClauses()
167168
);
168169
}
169170

171+
public function testPaginationWithMultipleAliases()
172+
{
173+
TestUser::create(['name' => 'A (user)']);
174+
TestUser::create(['name' => 'C (user)']);
175+
176+
TestPost::create(['title' => 'B (post)']);
177+
TestPost::create(['title' => 'D (post)']);
178+
179+
$table1 = TestPost::select(['title as alias']);
180+
$table2 = TestUser::select(['name as alias']);
181+
182+
$columns = ['alias'];
183+
$cursorName = 'cursor-name';
184+
$cursor = new Cursor(['alias' => 'A (user)']);
185+
186+
$result = $table1->toBase()
187+
->union($table2->toBase())
188+
->orderBy('alias', 'asc')
189+
->cursorPaginate(1, $columns, $cursorName, $cursor);
190+
191+
$this->assertSame(['alias'], $result->getOptions()['parameters']);
192+
193+
$this->assertCount(1, $result->items(), 'Expect cursor paginated query should have 1 result');
194+
$this->assertEquals('B (post)', current($result->items())->alias, 'Expect the paginated query would return `B (post)`');
195+
}
196+
170197
public function testPaginationWithAliasedOrderBy()
171198
{
172199
for ($i = 1; $i <= 6; $i++) {

0 commit comments

Comments
 (0)