Skip to content

Commit 74b37fa

Browse files
committed
Add tests for nested wheres. (close #2)
1 parent b9e2c45 commit 74b37fa

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

tests/Model/AuthUserProviderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,18 @@ public function it_cannot_retrieve_by_credentials_with_multiple_conditions()
340340
$this->assertNull($result);
341341
}
342342

343+
/** @test */
344+
public function it_cannot_retrieve_by_credentials_if_key_is_not_supported()
345+
{
346+
$provider = new AuthUserProvider($this->hasher, UserA::class);
347+
348+
$result = $provider->retrieveByCredentials([
349+
'foo' => 'bar'
350+
]);
351+
352+
$this->assertNull($result);
353+
}
354+
343355
/** @test */
344356
public function it_can_validate_credentials()
345357
{

tests/Query/BuilderTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,53 @@ public function it_can_process_filter_between()
387387
$this->assertEquals($params, $query['params']);
388388
}
389389

390+
/** @test */
391+
public function it_can_process_nested_filters()
392+
{
393+
$params = [
394+
'TableName' => 'ProductCatalog',
395+
'FilterExpression' => '(((#1 = :1 and #2 = :2) or (#1 = :3 and #3 < :4)) or #3 >= :5)',
396+
'ExpressionAttributeNames' => [
397+
'#1' => 'ProductCategory',
398+
'#2' => 'Brand',
399+
'#3' => 'Price'
400+
],
401+
'ExpressionAttributeValues' => [
402+
':1' => [
403+
'S' => 'Bicycle'
404+
],
405+
':2' => [
406+
'S' => 'Mountain A'
407+
],
408+
':3' => [
409+
'S' => 'Book'
410+
],
411+
':4' => [
412+
'N' => 10
413+
],
414+
':5' => [
415+
'N' => 500
416+
]
417+
]
418+
];
419+
420+
$query = $this->newQuery('ProductCatalog')->filter(function ($query) {
421+
$query->where(function ($query) {
422+
$query->where(function ($query) {
423+
$query->where('ProductCategory', 'Bicycle');
424+
$query->where('Brand', 'Mountain A');
425+
});
426+
$query->orWhere(function ($query) {
427+
$query->where('ProductCategory', 'Book');
428+
$query->where('Price', '<', 10);
429+
});
430+
});
431+
$query->orWhere('Price', '>=', 500);
432+
})->scan();
433+
434+
$this->assertEquals($params, $query['params']);
435+
}
436+
390437
/** @test */
391438
public function it_can_process_attribute_exists_function()
392439
{

0 commit comments

Comments
 (0)