These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace ByJG\Swagger; |
||
4 | |||
5 | use GuzzleHttp\Client; |
||
6 | use GuzzleHttp\Exception\BadResponseException; |
||
7 | use GuzzleHttp\Psr7\Request; |
||
8 | use PHPUnit\Framework\TestCase; |
||
9 | |||
10 | // backward compatibility |
||
11 | if (!class_exists('\PHPUnit\Framework\TestCase')) { |
||
12 | class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase'); |
||
13 | } |
||
14 | |||
15 | abstract class SwaggerTestCase extends TestCase |
||
16 | { |
||
17 | /** |
||
18 | * @var \ByJG\Swagger\SwaggerSchema |
||
19 | */ |
||
20 | protected $swaggerSchema; |
||
21 | |||
22 | protected $filePath; |
||
23 | |||
24 | /** |
||
25 | * @throws \Exception |
||
26 | */ |
||
27 | protected function setUp() |
||
28 | { |
||
29 | if (empty($this->filePath)) { |
||
30 | throw new \Exception('You have to define the property $filePath'); |
||
31 | } |
||
32 | |||
33 | $this->swaggerSchema = new SwaggerSchema(file_get_contents($this->filePath)); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param string $method The HTTP Method: GET, PUT, DELETE, POST, etc |
||
38 | * @param string $path The REST path call |
||
39 | * @param int $statusExpected |
||
40 | * @param array|null $query |
||
41 | * @param array|null $requestBody |
||
42 | * @param array $requestHeader |
||
43 | * @return mixed |
||
44 | * @deprecated Use assertRequest instead |
||
45 | * @throws \ByJG\Swagger\Exception\HttpMethodNotFoundException |
||
46 | * @throws \ByJG\Swagger\Exception\InvalidDefinitionException |
||
47 | * @throws \ByJG\Swagger\Exception\NotMatchedException |
||
48 | * @throws \ByJG\Swagger\Exception\PathNotFoundException |
||
49 | * @throws \ByJG\Swagger\Exception\RequiredArgumentNotFound |
||
50 | * @throws \Exception |
||
51 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
52 | */ |
||
53 | protected function makeRequest( |
||
54 | $method, |
||
55 | $path, |
||
56 | $statusExpected = 200, |
||
57 | $query = null, |
||
58 | $requestBody = null, |
||
59 | $requestHeader = [] |
||
60 | ) { |
||
61 | $requester = new SwaggerRequester(); |
||
62 | $body = $requester |
||
63 | ->withSwaggerSchema($this->swaggerSchema) |
||
64 | ->withMethod($method) |
||
65 | ->withPath($path) |
||
66 | ->withQuery($query) |
||
0 ignored issues
–
show
|
|||
67 | ->withRequestBody($requestBody) |
||
0 ignored issues
–
show
It seems like
$requestBody defined by parameter $requestBody on line 58 can also be of type array ; however, ByJG\Swagger\SwaggerRequester::withRequestBody() does only seem to accept null , maybe add an additional type check?
This check looks at variables that have been passed in as parameters and are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble.
Loading history...
|
|||
68 | ->withRequestHeader($requestHeader) |
||
69 | ->assertResponseCode($statusExpected) |
||
70 | ->send(); |
||
71 | |||
72 | // Note: |
||
73 | // This code is only reached if the send is successful and |
||
74 | // all matches are satisfied. Otherwise an error is throwed before |
||
75 | // reach this; |
||
76 | $this->assertTrue(true); |
||
77 | |||
78 | return $body; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param \ByJG\Swagger\SwaggerRequester $request |
||
83 | * @return mixed |
||
84 | * @throws \ByJG\Swagger\Exception\HttpMethodNotFoundException |
||
85 | * @throws \ByJG\Swagger\Exception\InvalidDefinitionException |
||
86 | * @throws \ByJG\Swagger\Exception\NotMatchedException |
||
87 | * @throws \ByJG\Swagger\Exception\PathNotFoundException |
||
88 | * @throws \ByJG\Swagger\Exception\RequiredArgumentNotFound |
||
89 | * @throws \Exception |
||
90 | */ |
||
91 | public function assertRequest(SwaggerRequester $request) |
||
92 | { |
||
93 | // Request based on the Swagger Request definitios |
||
94 | $body = $request |
||
95 | ->withSwaggerSchema($this->swaggerSchema) |
||
96 | ->send(); |
||
97 | |||
98 | // Note: |
||
99 | // This code is only reached if the send is successful and |
||
100 | // all matches are satisfied. Otherwise an error is throwed before |
||
101 | // reach this; |
||
102 | $this->assertTrue(true); |
||
103 | |||
104 | return $body; |
||
105 | } |
||
106 | } |
||
107 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.