1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace App\Bundle\Example\Tests\Service; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Import classes |
7
|
|
|
*/ |
8
|
|
|
use App\Exception\EntityNotFoundException; |
9
|
|
|
use App\Tests\ContainerAwareTrait; |
10
|
|
|
use App\Tests\DatabaseSchemaToolTrait; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Sunrise\Http\ServerRequest\ServerRequestFactory; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* EntryDeleteControllerTest |
16
|
|
|
*/ |
17
|
|
|
class EntryDeleteControllerTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
use ContainerAwareTrait; |
20
|
|
|
use DatabaseSchemaToolTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private const ROUTE_NAME = 'api_v1_entry_delete'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return void |
29
|
|
|
* |
30
|
|
|
* @runInSeparateProcess |
31
|
|
|
*/ |
32
|
|
|
public function testDelete() : void |
33
|
|
|
{ |
34
|
|
|
$container = $this->getContainer(); |
35
|
|
|
$doctrine = $container->get('doctrine'); |
36
|
|
|
|
37
|
|
|
$entityManager = $doctrine->getManager('master'); |
38
|
|
|
$this->createDatabaseSchema($entityManager); |
39
|
|
|
|
40
|
|
|
$entryManager = $container->get('entryManager'); |
41
|
|
|
$this->assertSame(0, $entryManager->countAll()); |
42
|
|
|
|
43
|
|
|
$entry = $entryManager->create(['name' => 'foo', 'slug' => 'foo']); |
44
|
|
|
$this->assertSame(1, $entryManager->countAll()); |
45
|
|
|
|
46
|
|
|
$request = (new ServerRequestFactory) |
47
|
|
|
->createServerRequest('DELETE', '/api/v1/entry/' . $entry->getId()->toString()) |
48
|
|
|
->withAttribute('entryId', $entry->getId()->toString()); |
49
|
|
|
|
50
|
|
|
$response = $container->get('router') |
51
|
|
|
->getRoute(self::ROUTE_NAME) |
52
|
|
|
->handle($request); |
53
|
|
|
|
54
|
|
|
$this->assertSame(200, $response->getStatusCode()); |
55
|
|
|
$this->assertSame(0, $entryManager->countAll()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return void |
60
|
|
|
* |
61
|
|
|
* @runInSeparateProcess |
62
|
|
|
*/ |
63
|
|
|
public function testDeleteNonExistentEntry() : void |
64
|
|
|
{ |
65
|
|
|
$container = $this->getContainer(); |
66
|
|
|
$doctrine = $container->get('doctrine'); |
67
|
|
|
|
68
|
|
|
$entityManager = $doctrine->getManager('master'); |
69
|
|
|
$this->createDatabaseSchema($entityManager); |
70
|
|
|
|
71
|
|
|
$entryManager = $container->get('entryManager'); |
72
|
|
|
$this->assertSame(0, $entryManager->countAll()); |
73
|
|
|
|
74
|
|
|
$request = (new ServerRequestFactory) |
75
|
|
|
->createServerRequest('DELETE', '/api/v1/entry/3466e003-6191-48c7-bb3a-64786587b8a1') |
76
|
|
|
->withAttribute('entryId', '3466e003-6191-48c7-bb3a-64786587b8a1'); |
77
|
|
|
|
78
|
|
|
$this->expectException(EntityNotFoundException::class); |
79
|
|
|
|
80
|
|
|
$response = $container->get('router') |
81
|
|
|
->getRoute(self::ROUTE_NAME) |
82
|
|
|
->handle($request); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|