public function testCustomOrder()
{
$data = [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']];
$queryConfiguration = QueryConfigurationBuilder::create()->start(0)->length(2)->drawCall(1)->columnOrder('id', 'desc')->build();
$columnConfiguration = ColumnConfigurationBuilder::create()->name('id')->build();
$provider = new CollectionProvider(new Collection($data));
$provider->order(function ($first, $second, array $order) {
if (!$order[0]->isAscending()) {
return $first['id'] < $second['id'] ? 1 : ($first['id'] > $second['id'] ? -1 : 0);
}
return $first['id'] < $second['id'] ? -1 : ($first['id'] > $second['id'] ? 1 : 0);
});
$provider->prepareForProcessing($queryConfiguration, [$columnConfiguration]);
$data = $provider->process();
$this->assertSame(2, $data->data()->count());
$first = $data->data()->first();
$this->assertSame(2, $first['id']);
}