1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\Tests\Controller; |
4
|
|
|
|
5
|
|
|
use ScayTrase\Api\Cruds\Tests\Fixtures\Common\Entity\MyEntity; |
6
|
|
|
use ScayTrase\Api\Cruds\Tests\WebTestCase; |
7
|
|
|
|
8
|
|
|
final class SearchControllerTest extends WebTestCase |
9
|
|
|
{ |
10
|
|
|
public function testSearchAction() |
11
|
|
|
{ |
12
|
|
|
$em = $this->getEntityManager(); |
13
|
|
|
$entity = new MyEntity('my-test-secret'); |
14
|
|
|
$em->persist($entity); |
15
|
|
|
$parent = new MyEntity('non-recursing-entity'); |
16
|
|
|
$em->persist($parent); |
17
|
|
|
$entity->setParent($parent); |
18
|
|
|
$em->flush(); |
19
|
|
|
$em->clear(); |
20
|
|
|
|
21
|
|
|
$client = self::createClient(); |
22
|
|
|
$client->request( |
23
|
|
|
'GET', |
24
|
|
|
'/api/entity/my-entity/search', |
25
|
|
|
[ |
26
|
|
|
'criteria' => ['id' => $entity->getId()], |
27
|
|
|
], |
28
|
|
|
[], |
29
|
|
|
['HTTP_CONTENT_TYPE' => 'application/json'] |
30
|
|
|
); |
31
|
|
|
$response = $client->getResponse(); |
32
|
|
|
|
33
|
|
|
self::assertTrue($response->isSuccessful()); |
34
|
|
|
$data = json_decode($response->getContent()); |
35
|
|
|
|
36
|
|
|
self::assertEquals(JSON_ERROR_NONE, json_last_error()); |
37
|
|
|
|
38
|
|
|
self::assertInternalType('array', $data); |
39
|
|
|
self::assertCount(1, $data); |
40
|
|
|
|
41
|
|
|
$data = array_shift($data); |
42
|
|
|
|
43
|
|
|
self::assertInstanceOf(\stdClass::class, $data); |
44
|
|
|
self::assertSame($entity->getId(), $data->id); |
45
|
|
|
self::assertObjectHasAttribute('public_api_field', $data); |
46
|
|
|
self::assertSame('defaults', $data->public_api_field); |
47
|
|
|
self::assertObjectNotHasAttribute('private_field', $data); |
48
|
|
|
self::assertSame($parent->getId(), $data->parent); |
49
|
|
|
self::assertSame([], $data->children); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|