-
Notifications
You must be signed in to change notification settings - Fork 4
/
SortExtensionTest.php
63 lines (53 loc) · 2.37 KB
/
SortExtensionTest.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\SQLServerPlatform;
final class SortExtensionTest extends AbstractTest
{
public function testGetCollectionSortByName(): void
{
$response = static::createClient()->request('GET', '/cars?sort=name.asc');
$this->assertResponseIsSuccessful();
$this->assertEquals('a', $response->toArray()['hydra:member'][0]['name'][0]);
$response = static::createClient()->request('GET', '/cars?sort=name.desc');
$this->assertResponseIsSuccessful();
$this->assertEquals('z', $response->toArray()['hydra:member'][0]['name'][0]);
}
public function testGetCollectionSortByNameAndColor(): void
{
$response = static::createClient()->request('GET', '/cars?sort=name.asc,color.desc');
$this->assertResponseIsSuccessful();
$this->assertEquals('a', $response->toArray()['hydra:member'][0]['name'][0]);
}
public function testGetCollectionSortByNameAndColorNulls(): void
{
$kernel = self::bootKernel();
$container = $kernel->getContainer();
$registry = $container->get('doctrine');
if ($registry->getConnection()->getDriver()->getDatabasePlatform() instanceof SQLServerPlatform) {
$this->markTestSkipped();
}
$response = static::createClient()->request('GET', '/cars?sort=color.asc.nullsfirst');
$this->assertResponseIsSuccessful();
$this->assertNull($response->toArray()['hydra:member'][0]['color']);
$response = static::createClient()->request('GET', '/cars?sort=color.asc.nullslast');
$this->assertResponseIsSuccessful();
$this->assertIsString($response->toArray()['hydra:member'][0]['color']);
$response = static::createClient()->request('GET', '/cars?sort=name.asc,color.nullsfirst');
$this->assertResponseIsSuccessful();
$this->assertEquals('a', $response->toArray()['hydra:member'][0]['name'][0]);
}
public function testGetCollectionSortByPrice(): void
{
$response = static::createClient()->request('GET', '/cars?sort=price.desc');
$this->assertResponseIsSuccessful();
}
}