|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JDesrosiers\Resourceful\Controller\Test; |
|
4
|
|
|
|
|
5
|
|
|
use JDesrosiers\Resourceful\Controller\DeleteResourceController; |
|
6
|
|
|
use PHPUnit_Framework_TestCase; |
|
7
|
|
|
use Silex\Application; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
9
|
|
|
use Symfony\Component\HttpKernel\Client; |
|
10
|
|
|
|
|
11
|
|
|
class DeleteResourceControllerTest extends PHPUnit_Framework_TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
private $app; |
|
14
|
|
|
private $service; |
|
15
|
|
|
private $client; |
|
16
|
|
|
|
|
17
|
|
|
public function setUp() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->app = new Application(); |
|
20
|
|
|
$this->app["debug"] = true; |
|
21
|
|
|
|
|
22
|
|
|
$this->service = $this->getMockBuilder("Doctrine\Common\Cache\Cache")->getMock(); |
|
23
|
|
|
$this->app->delete("/foo/{id}", new DeleteResourceController($this->service)); |
|
24
|
|
|
|
|
25
|
|
|
$this->client = new Client($this->app); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testDelete() |
|
29
|
|
|
{ |
|
30
|
|
|
$headers = [ |
|
31
|
|
|
"HTTP_ACCEPT" => "application/json", |
|
32
|
|
|
]; |
|
33
|
|
|
$this->client->request("DELETE", "/foo/4ee8e29d45851", [], [], $headers); |
|
34
|
|
|
$response = $this->client->getResponse(); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertEquals(Response::HTTP_NO_CONTENT, $response->getStatusCode()); |
|
37
|
|
|
$this->assertEquals("", $response->getContent()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testDeleteError() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->service->method("delete") |
|
43
|
|
|
->willReturn(false); |
|
44
|
|
|
|
|
45
|
|
|
$this->app->error(function (\Exception $e, $code) { |
|
|
|
|
|
|
46
|
|
|
$this->assertEquals("Failed to delete resource", $e->getMessage()); |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
$headers = [ |
|
50
|
|
|
"HTTP_ACCEPT" => "application/json", |
|
51
|
|
|
]; |
|
52
|
|
|
$this->client->request("DELETE", "/foo/4ee8e29d45851", [], [], $headers); |
|
53
|
|
|
$response = $this->client->getResponse(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertEquals(Response::HTTP_SERVICE_UNAVAILABLE, $response->getStatusCode()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.