1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nicofuma\SwaggerBundle\Tests\Behat\Context; |
4
|
|
|
|
5
|
|
|
use Behat\Mink\Driver\BrowserKitDriver; |
6
|
|
|
use Behat\Mink\Exception\UnsupportedDriverActionException; |
7
|
|
|
use FR3D\SwaggerAssertions\PhpUnit\SymfonyAssertsTrait; |
8
|
|
|
use Nicofuma\SwaggerBundle\Validator\ValidatorMap; |
9
|
|
|
use Sanpi\Behatch\Context\BaseContext; |
10
|
|
|
|
11
|
|
|
class SwaggerContext extends BaseContext |
12
|
|
|
{ |
13
|
|
|
use SymfonyAssertsTrait; |
14
|
|
|
|
15
|
|
|
/** @var ValidatorMap */ |
16
|
|
|
private $map; |
17
|
|
|
|
18
|
|
|
public function __construct(ValidatorMap $map) |
19
|
|
|
{ |
20
|
|
|
$this->map = $map; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* This method match the response against its Swagger definition. |
25
|
|
|
* |
26
|
|
|
* @throws \Behat\Mink\Exception\ExpectationException |
27
|
|
|
* @throws \Exception |
28
|
|
|
* |
29
|
|
|
* @Then the response should match the Swagger definition |
30
|
|
|
*/ |
31
|
|
|
public function theResponseMatchSwagger() |
32
|
|
|
{ |
33
|
|
|
$response = $this->getResponse(); |
34
|
|
|
$request = $this->getRequest(); |
35
|
|
|
$schemaManager = $this->map->getValidator($request)->getSchemaManager(); |
36
|
|
|
|
37
|
|
|
$this->assertResponseMatch($response, $schemaManager, $request->getPathInfo(), $request->getMethod()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return \Symfony\Component\BrowserKit\Client |
42
|
|
|
* |
43
|
|
|
* @throws UnsupportedDriverActionException |
44
|
|
|
*/ |
45
|
|
|
protected function getClient() |
46
|
|
|
{ |
47
|
|
|
$driver = $this->getSession()->getDriver(); |
48
|
|
|
|
49
|
|
|
if (!$driver instanceof BrowserKitDriver) { |
|
|
|
|
50
|
|
|
throw new UnsupportedDriverActionException('This step is only supported by the BrowserKitDriver, not the %s one', $driver); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $driver->getClient(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the last response. |
58
|
|
|
* |
59
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
60
|
|
|
*/ |
61
|
|
|
protected function getResponse() |
62
|
|
|
{ |
63
|
|
|
return $this->getClient()->getResponse(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return \Symfony\Component\HttpFoundation\Request |
68
|
|
|
*/ |
69
|
|
|
public function getRequest() |
70
|
|
|
{ |
71
|
|
|
return $this->getClient()->getRequest(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.