Skip to content

Commit d118a10

Browse files
committed
Add test for closure di
1 parent 57724d9 commit d118a10

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/Integration/QueryDataTableTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,26 @@ public function it_can_return_formatted_columns()
339339
$this->assertEquals(Carbon::parse($user->created_at)->format('Y-m-d'), $data['created_at_formatted']);
340340
}
341341

342+
/** @test */
343+
public function it_can_return_added_column_with_dependency_injection()
344+
{
345+
$crawler = $this->call('GET', '/closure-di');
346+
347+
$crawler->assertJson([
348+
'draw' => 0,
349+
'recordsTotal' => 20,
350+
'recordsFiltered' => 20,
351+
]);
352+
353+
$user = DB::table('users')->find(1);
354+
$data = $crawler->json('data')[0];
355+
356+
$this->assertTrue(isset($data['name']));
357+
$this->assertTrue(isset($data['name_di']));
358+
359+
$this->assertEquals($user->name.'_di', $data['name_di']);
360+
}
361+
342362
protected function setUp(): void
343363
{
344364
parent::setUp();
@@ -451,5 +471,13 @@ protected function setUp(): void
451471
->setFilteredRecords(10)
452472
->toJson();
453473
});
474+
475+
$router->get('/closure-di', function (DataTables $dataTable) {
476+
return $dataTable->query(DB::table('users'))
477+
->addColumn('name_di', function ($user, User $u) {
478+
return $u->newQuery()->find($user->id)->name.'_di';
479+
})
480+
->toJson();
481+
});
454482
}
455483
}

0 commit comments

Comments
 (0)