Skip to content

Commit

Permalink
DataSources\ArraySource: Added missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
o5 committed Jan 17, 2016
1 parent 70bdc84 commit 62c5db1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/DataSources/ArraySource.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function compare($actual, $condition, $expected)
return (int) $actual >= $expected;

} else {
throw new Exception("Condition '$condition' not implemented yet.");
throw new Exception("Condition '$condition' is not implemented yet.");
}
}

Expand Down
34 changes: 32 additions & 2 deletions tests/DataSources/ArraySource.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Grido\Tests;

use Tester\Assert,
Grido\Grid,
Grido\DataSources\ArraySource,
Grido\Components\Filters\Condition;

require_once __DIR__ . '/TestCase.php';
Expand Down Expand Up @@ -65,7 +66,7 @@ class ArraySourceTest extends DataSourceTestCase

function testCompare()
{
$source = new \Grido\DataSources\ArraySource([]);
$source = new ArraySource([]);

Assert::true($source->compare('Lucie', 'LIKE ?', '%Lu%'));
Assert::true($source->compare('Lucie', 'LIKE ?', '%ie'));
Expand Down Expand Up @@ -99,7 +100,36 @@ class ArraySourceTest extends DataSourceTestCase

Assert::error(function() use ($source) {
Assert::true($source->compare(2, 'SOMETHING ?', 3));
}, 'Grido\Exception', "Condition 'SOMETHING ?' not implemented yet.");
}, 'Grido\Exception', "Condition 'SOMETHING ?' is not implemented yet.");
}

function testMakeWhere()
{
$data = [
['name' => 'AA', 'surname' => 'BB', 'city' => 'CC'],
['name' => 'CC', 'surname' => 'DD', 'city' => 'AA'],
['name' => 'EE', 'surname' => 'AA', 'city' => 'FF'],
['name' => 'AA', 'surname' => 'AA', 'city' => 'BB'],
['name' => 'AA', 'surname' => 'AA', 'city' => 'AA'],
];

$source = new ArraySource($data);
$source->filter([Condition::setup(['name'], '= ?', 'CC')]);
Assert::same([1 => $data[1]], $source->data);

$source = new ArraySource($data);
$source->filter([Condition::setup(['name', 'OR', 'surname'], '= ?', 'AA')]);
$expected = $data;
unset($expected[1]);
Assert::same($expected, $source->data);

$source = new ArraySource($data);
$source->filter([Condition::setup(['name', 'AND', 'surname'], '= ?', 'AA')]);
Assert::same([3 => $data[3], 4 => $data[4]], $source->data);

$source = new ArraySource($data);
$source->filter([Condition::setup(['name', 'AND', 'surname', 'AND', 'city'], '= ?', 'AA')]);
Assert::same([4 => $data[4]], $source->data);
}
}

Expand Down

0 comments on commit 62c5db1

Please sign in to comment.