Skip to content

Commit

Permalink
Minor improve AbstractCachedTableTest
Browse files Browse the repository at this point in the history
  • Loading branch information
compositephp committed Oct 28, 2023
1 parent 93cc75b commit ccc8ca5
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions tests/Table/AbstractCachedTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,85 +58,100 @@ public static function getCountCacheKey_dataProvider(): array
{
return [
[
'',
[],
'sqlite.TestAutoincrement.v1.c.all',
],
[
'name = :name',
['name' => 'John'],
new Where('name = :name', ['name' => 'John']),
'sqlite.TestAutoincrement.v1.c.name_eq_john',
],
[
' name = :name ',
['name' => 'John'],
'sqlite.TestAutoincrement.v1.c.name_john',
],
[
new Where(' name = :name ', ['name' => 'John']),
'sqlite.TestAutoincrement.v1.c.name_eq_john',
],
[
'name=:name',
['name' => 'John'],
new Where('name=:name', ['name' => 'John']),
'sqlite.TestAutoincrement.v1.c.name_eq_john',
],
[
'name = :name AND id > :id',
['name' => 'John', 'id' => 10],
new Where('name = :name AND id > :id', ['name' => 'John', 'id' => 10]),
'sqlite.TestAutoincrement.v1.c.name_eq_john_and_id_gt_10',
],
[
['name' => 'John', 'id' => ['>', 10]],
'sqlite.TestAutoincrement.v1.c.name_john_id_gt_10',
],
];
}

/**
* @dataProvider getCountCacheKey_dataProvider
*/
public function test_getCountCacheKey(string $whereString, array $whereParams, string $expected): void
public function test_getCountCacheKey(array|Where $where, string $expected): void
{
$table = new Tables\TestAutoincrementCachedTable(Helpers\CacheHelper::getCache());
$reflectionMethod = new \ReflectionMethod($table, 'getCountCacheKey');
$actual = $reflectionMethod->invoke($table, new Where($whereString, $whereParams));
$actual = $reflectionMethod->invoke($table, $where);
$this->assertEquals($expected, $actual);
}

public static function getListCacheKey_dataProvider(): array
{
return [
[
'',
[],
[],
null,
'sqlite.TestAutoincrement.v1.l.all',
],
[
'',
[],
[],
10,
'sqlite.TestAutoincrement.v1.l.all.limit_10',
],
[
'',
[],
['id' => 'DESC'],
10,
'sqlite.TestAutoincrement.v1.l.all.ob_id_desc.limit_10',
],
[
'name = :name',
new Where('name = :name', ['name' => 'John']),
[],
null,
'sqlite.TestAutoincrement.v1.l.name_eq_john',
],
[
['name' => 'John'],
[],
null,
'sqlite.TestAutoincrement.v1.l.name_john',
],
[
new Where('name = :name', ['name' => 'John']),
[],
null,
'sqlite.TestAutoincrement.v1.l.name_eq_john',
],
[
'name = :name AND id > :id',
['name' => 'John', 'id' => 10],
new Where('name = :name AND id > :id', ['name' => 'John', 'id' => 10]),
[],
null,
'sqlite.TestAutoincrement.v1.l.name_eq_john_and_id_gt_10',
],
[
'name = :name AND id > :id',
['name' => 'John', 'id' => 10],
['name' => 'John', 'id' => ['>', 10]],
[],
null,
'sqlite.TestAutoincrement.v1.l.name_john_id_gt_10',
],
[
new Where('name = :name AND id > :id', ['name' => 'John', 'id' => 10]),
['id' => 'ASC'],
20,
'bbcf331b765b682da02c4d21dbaa3342bf2c3f18', //sha1('sqlite.TestAutoincrement.v1.l.name_eq_john_and_id_gt_10.ob_id_asc.limit_20')
Expand All @@ -147,11 +162,11 @@ public static function getListCacheKey_dataProvider(): array
/**
* @dataProvider getListCacheKey_dataProvider
*/
public function test_getListCacheKey(string $whereString, array $whereArray, array $orderBy, ?int $limit, string $expected): void
public function test_getListCacheKey(array|Where $where, array $orderBy, ?int $limit, string $expected): void
{
$table = new Tables\TestAutoincrementCachedTable(Helpers\CacheHelper::getCache());
$reflectionMethod = new \ReflectionMethod($table, 'getListCacheKey');
$actual = $reflectionMethod->invoke($table, new Where($whereString, $whereArray), $orderBy, $limit);
$actual = $reflectionMethod->invoke($table, $where, $orderBy, $limit);
$this->assertEquals($expected, $actual);
}

Expand Down

0 comments on commit ccc8ca5

Please sign in to comment.