Skip to content

Commit

Permalink
phpunit update on deprecated function "assertContains"
Browse files Browse the repository at this point in the history
  • Loading branch information
n1crack committed Nov 1, 2019
1 parent 5ff814b commit 0c1696f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/nbproject
composer.lock
.DS_Store
*.cache
67 changes: 52 additions & 15 deletions tests/unit/DatatablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ private function customfunction($data)
return substr($data, 0, 3).'...';
}

public function setUp()
public function setUp(): void
{
$sqlconfig = __DIR__.'/../fixtures/test.db';
$this->request = Request::create(array() ,['draw' => 1] );
$this->request = Request::create(array(), ['draw' => 1]);

$this->db = new Datatables(new SQLite($sqlconfig), $this->request);
}

public function tearDown()
public function tearDown(): void
{
unset($this->db);
}
Expand All @@ -53,7 +53,7 @@ public function testReturnsDataFromABasicSql()

$this->assertSame("1", $data[0]);
$this->assertSame("John", $data[1]);
$this->assertContains('Doe', $data[2]);
$this->assertStringContainsString('Doe', $data[2]);
}

public function testSetsColumnNamesFromAliases()
Expand Down Expand Up @@ -186,7 +186,13 @@ public function testSortsExcludingHiddenColumnsObjectData()
$this->request->query->set('order', [['column' => '1', 'dir' => 'asc']]);

$this->request->query->set('columns', [
['data' => 'name', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => ['value' => '']],
[
'data' => 'name',
'name' => '',
'searchable' => 'true',
'orderable' => 'true',
'search' => ['value' => ''],
],
['data' => 'age', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => ['value' => '']],
]);

Expand All @@ -206,8 +212,20 @@ public function testReorderingColumnsDoesNotAffectOrdering()

$this->request->query->set('columns', [
['data' => 'age', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => ['value' => '']],
['data' => 'surname', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => ['value' => '']],
['data' => 'name', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => ['value' => '']],
[
'data' => 'surname',
'name' => '',
'searchable' => 'true',
'orderable' => 'true',
'search' => ['value' => ''],
],
[
'data' => 'name',
'name' => '',
'searchable' => 'true',
'orderable' => 'true',
'search' => ['value' => ''],
],
]);

$this->db->query('Select id as fid, name, surname, age from mytable');
Expand All @@ -232,17 +250,36 @@ public function testReorderingColumnsDoesNotAffectGlobalSearching()
$this->db->hide('fid');
$datatables = $this->db->generate()->toArray();

$this->assertSame([ 'Stephanie', 'Skinner', '45'], $datatables['data'][0]);
$this->assertSame(['Stephanie', 'Skinner', '45'], $datatables['data'][0]);
}

public function testReorderingColumnsDoesNotAffectIndividualSearching()
{
$this->request->query->set('search', ['value' => '']);
$this->request->query->set('order', [['column' => '0', 'dir' => 'asc']]);

$this->request->query->set('columns', [
['data' => 'surname', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => ['value' => 'McCoy']],
['data' => 'age', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => ['value' => '19']],
['data' => 'name', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => ['value' => 'Colin']],
[
'data' => 'surname',
'name' => '',
'searchable' => 'true',
'orderable' => 'true',
'search' => ['value' => 'McCoy'],
],
[
'data' => 'age',
'name' => '',
'searchable' => 'true',
'orderable' => 'true',
'search' => ['value' => '19'],
],
[
'data' => 'name',
'name' => '',
'searchable' => 'true',
'orderable' => 'true',
'search' => ['value' => 'Colin'],
],
]);

$this->db->query('Select id as fid, name, surname, age from mytable');
Expand All @@ -264,8 +301,8 @@ public function testCustomFilteringBetween()
]);

$this->db->query('Select id as fid, name, surname, age from mytable');
$this->db->filter('fid', function(){
return $this->between(4,6);
$this->db->filter('fid', function () {
return $this->between(4, 6);
});

$datatables = $this->db->generate()->toArray();
Expand All @@ -286,7 +323,7 @@ public function testCustomFilteringWhereIn()
]);

$this->db->query('Select id as fid, name, surname, age from mytable');
$this->db->filter('fid', function(){
$this->db->filter('fid', function () {
return $this->whereIn([5]);
});

Expand All @@ -309,7 +346,7 @@ public function testReturnDefaultSearchWhenNull()
]);

$this->db->query('Select id as fid, name, surname, age from mytable');
$this->db->filter('fid', function(){
$this->db->filter('fid', function () {
//return $this->defaultFilter(); // when it is not defined, returns defaultFilter
});

Expand Down

0 comments on commit 0c1696f

Please sign in to comment.