-
Notifications
You must be signed in to change notification settings - Fork 4
/
FilterExtensionTest.php
63 lines (54 loc) · 2.06 KB
/
FilterExtensionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*
* This file is part of the ESQL project.
*
* (c) Antoine Bluchet <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Api;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
final class FilterExtensionTest extends AbstractTest
{
public function testSimpleFilter(): void
{
$response = static::createClient()->request('GET', '/cars?sold=eq.true');
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@context' => '/contexts/Car',
'@id' => '/cars',
'@type' => 'hydra:Collection',
'hydra:member' => [
['name' => 'golf', 'sold' => true],
['name' => 'caddy', 'sold' => true],
],
]);
$this->assertGreaterThanOrEqual(2, $response->toArray()['hydra:totalItems']);
}
public function testComplexFilter(): void
{
$kernel = self::bootKernel();
$container = $kernel->getContainer();
$registry = $container->get('doctrine');
$platform = $registry->getConnection()->getDriver()->getDatabasePlatform();
if ($platform instanceof SqlitePlatform || $platform instanceof SQLServerPlatform) {
$this->markTestSkipped();
}
$response = static::createClient()->request('GET', '/cars?and=(price.gt.1000000,sold.is.false,or(sold.is.true))&sort=price.asc');
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@context' => '/contexts/Car',
'@id' => '/cars',
'@type' => 'hydra:Collection',
// 'hydra:member' => [
// ['name' => 'golf', 'sold' => true, 'price' => 10000],
// ['name' => 'caddy', 'sold' => true, 'price' => 1000000],
// ['name' => 'passat', 'sold' => false, 'price' => 2599999],
// ],
'hydra:totalItems' => 1003,
]);
}
}