1
|
|
|
<?php |
|
|
|
|
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/* |
4
|
|
|
* This file is part of the KleijnWeb\SwaggerBundle package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace KleijnWeb\SwaggerBundle\Test; |
11
|
|
|
|
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Client; |
13
|
|
|
use Symfony\Component\BrowserKit\Request; |
14
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author John Kleijn <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class ApiTestClient extends Client |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Client |
23
|
|
|
*/ |
24
|
|
|
private $target; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function __construct(Client $client) |
30
|
|
|
{ |
31
|
|
|
$this->target = $client; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Makes a request from a Request object directly. |
36
|
|
|
* |
37
|
|
|
* @param Request $request A Request instance |
38
|
|
|
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), |
39
|
|
|
* and reload()) |
40
|
|
|
* |
41
|
|
|
* @return Crawler |
42
|
|
|
*/ |
43
|
|
|
public function requestFromRequest(Request $request, $changeHistory = true) |
44
|
|
|
{ |
45
|
|
|
return $this->target->requestFromRequest($request, $changeHistory); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return null|\Symfony\Component\HttpFoundation\Request |
50
|
|
|
*/ |
51
|
|
|
public function getRequest() |
52
|
|
|
{ |
53
|
|
|
return $this->target->getRequest(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return null|\Symfony\Component\HttpFoundation\Response |
58
|
|
|
*/ |
59
|
|
|
public function getResponse() |
60
|
|
|
{ |
61
|
|
|
return $this->target->getResponse(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return \Symfony\Component\DependencyInjection\ContainerInterface |
66
|
|
|
*/ |
67
|
|
|
public function getContainer() |
68
|
|
|
{ |
69
|
|
|
return $this->target->getContainer(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return \Symfony\Component\HttpKernel\KernelInterface |
74
|
|
|
*/ |
75
|
|
|
public function getKernel() |
76
|
|
|
{ |
77
|
|
|
return $this->target->getKernel(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return \Symfony\Component\HttpKernel\Profiler\Profile |
82
|
|
|
*/ |
83
|
|
|
public function getProfile() |
84
|
|
|
{ |
85
|
|
|
return $this->target->getProfile(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return \Symfony\Component\HttpKernel\Profiler\Profile |
90
|
|
|
*/ |
91
|
|
|
public function enableProfiler() |
92
|
|
|
{ |
93
|
|
|
return $this->target->getProfile(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return void |
98
|
|
|
*/ |
99
|
|
|
public function disableReboot() |
100
|
|
|
{ |
101
|
|
|
$this->target->disableReboot(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return void |
106
|
|
|
*/ |
107
|
|
|
public function enableReboot() |
108
|
|
|
{ |
109
|
|
|
$this->target->enableReboot(); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.