|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JDesrosiers\Resourceful\IndexControllerProvider\Test; |
|
4
|
|
|
|
|
5
|
|
|
use JDesrosiers\Resourceful\IndexControllerProvider\IndexControllerProvider; |
|
6
|
|
|
use JDesrosiers\Resourceful\Resourceful; |
|
7
|
|
|
use JDesrosiers\Resourceful\ResourcefulServiceProvider\ResourcefulServiceProvider; |
|
8
|
|
|
use JDesrosiers\Resourceful\SchemaControllerProvider\SchemaControllerProvider; |
|
9
|
|
|
use PHPUnit_Framework_TestCase; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Symfony\Component\HttpKernel\Client; |
|
12
|
|
|
|
|
13
|
|
|
class IndexControllerProviderTest extends PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private $app; |
|
16
|
|
|
private $client; |
|
17
|
|
|
private $service; |
|
18
|
|
|
|
|
19
|
|
|
public function setUp() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->app = new Resourceful(); |
|
22
|
|
|
$this->app["debug"] = true; |
|
23
|
|
|
|
|
24
|
|
|
$this->app->register(new ResourcefulServiceProvider(), [ |
|
25
|
|
|
"resourceful.schemas" => $this->getMockBuilder("Doctrine\Common\Cache\Cache")->getMock(), |
|
26
|
|
|
]); |
|
27
|
|
|
|
|
28
|
|
|
$this->app->mount("/schema", new SchemaControllerProvider()); |
|
|
|
|
|
|
29
|
|
|
$this->app->flush(); |
|
30
|
|
|
|
|
31
|
|
|
$this->service = $this->getMockBuilder("Doctrine\Common\Cache\Cache")->getMock(); |
|
32
|
|
|
$this->app->mount("/", new IndexControllerProvider($this->service)); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
$this->client = new Client($this->app); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGet() |
|
38
|
|
|
{ |
|
39
|
|
|
$index = '{"title":"My API", "description":"This is my fantastic API"}'; |
|
40
|
|
|
|
|
41
|
|
|
$this->service->method("contains") |
|
42
|
|
|
->with("/") |
|
43
|
|
|
->willReturn(true); |
|
44
|
|
|
|
|
45
|
|
|
$this->service->method("fetch") |
|
46
|
|
|
->with("/") |
|
47
|
|
|
->willReturn(json_decode($index)); |
|
48
|
|
|
|
|
49
|
|
|
$headers = [ |
|
50
|
|
|
"HTTP_ACCEPT" => "application/json", |
|
51
|
|
|
]; |
|
52
|
|
|
$this->client->request("GET", "/", [], [], $headers); |
|
53
|
|
|
$response = $this->client->getResponse(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); |
|
56
|
|
|
$this->assertEquals("application/json", $response->headers->get("Content-Type")); |
|
57
|
|
|
$this->assertEquals("</schema/index>; rel=\"describedby\"", $response->headers->get("Link")); |
|
58
|
|
|
$this->assertJsonStringEqualsJsonString($index, $response->getContent()); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: