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
|
|
|
* @author Maxime Beaudoin <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
trait AddTestingSupportForInclude |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Call the given URI and return the Response. |
17
|
|
|
* |
18
|
|
|
* @param string $method |
19
|
|
|
* @param string $uri |
20
|
|
|
* @param array $parameters |
21
|
|
|
* @param array $cookies |
22
|
|
|
* @param array $files |
23
|
|
|
* @param array $server |
24
|
|
|
* @param string $content |
25
|
|
|
* @return \Illuminate\Http\Response |
26
|
|
|
*/ |
27
|
|
|
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null) |
28
|
|
|
{ |
29
|
|
|
$kernel = $this->app->make('Illuminate\Contracts\Http\Kernel'); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->currentUri = $this->prepareUrlForRequest($uri); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$this->resetPageContext(); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$symfonyRequest = SymfonyRequest::create( |
36
|
|
|
$this->currentUri, $method, $parameters, |
37
|
|
|
$cookies, $this->filterFiles($files), array_replace($this->serverVariables, $server), $content |
|
|
|
|
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$request = Request::createFromBase($symfonyRequest); |
41
|
|
|
|
42
|
|
|
$response = app(\EllipseSynergie\ApiResponse\Contracts\Response::class); |
43
|
|
|
|
44
|
|
|
$response |
45
|
|
|
->getManager() |
46
|
|
|
->parseIncludes(explode(',', $request->get('include'))); |
47
|
|
|
|
48
|
|
|
$response = $kernel->handle($request); |
49
|
|
|
|
50
|
|
|
$kernel->terminate($request, $response); |
51
|
|
|
|
52
|
|
|
return $this->response = $response; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
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: