1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EllipseSynergie\ApiResponse\Testing\Laravel; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request as SymfonyRequest; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class AddTestingSupportForInclude |
10
|
|
|
* @package EllipseSynergie\ApiResponse\Testing\Laravel |
11
|
|
|
*/ |
12
|
|
|
trait AddTestingSupportForInclude |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Call the given URI and return the Response. |
16
|
|
|
* |
17
|
|
|
* @param string $method |
18
|
|
|
* @param string $uri |
19
|
|
|
* @param array $parameters |
20
|
|
|
* @param array $cookies |
21
|
|
|
* @param array $files |
22
|
|
|
* @param array $server |
23
|
|
|
* @param string $content |
24
|
|
|
* @return \Illuminate\Http\Response |
25
|
|
|
*/ |
26
|
|
|
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null) |
27
|
|
|
{ |
28
|
|
|
$kernel = $this->app->make('Illuminate\Contracts\Http\Kernel'); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$this->currentUri = $this->prepareUrlForRequest($uri); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$this->resetPageContext(); |
|
|
|
|
33
|
|
|
|
34
|
|
|
$symfonyRequest = SymfonyRequest::create( |
35
|
|
|
$this->currentUri, $method, $parameters, |
36
|
|
|
$cookies, $this->filterFiles($files), array_replace($this->serverVariables, $server), $content |
|
|
|
|
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$request = Request::createFromBase($symfonyRequest); |
40
|
|
|
|
41
|
|
|
$response = app(\EllipseSynergie\ApiResponse\Contracts\Response::class); |
42
|
|
|
|
43
|
|
|
$response |
44
|
|
|
->getManager() |
45
|
|
|
->parseIncludes(explode(',', $request->get('include'))); |
46
|
|
|
|
47
|
|
|
$response = $kernel->handle($request); |
48
|
|
|
|
49
|
|
|
$kernel->terminate($request, $response); |
50
|
|
|
|
51
|
|
|
return $this->response = $response; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: