1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Behatch\HttpCall; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\EventDispatcher\Event\StepTested; |
6
|
|
|
use Behat\Behat\EventDispatcher\Event\AfterStepTested; |
7
|
|
|
use Behat\Behat\Tester\Result\ExecutedStepResult; |
8
|
|
|
use Behat\Mink\Mink; |
9
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
10
|
|
|
|
11
|
|
|
class HttpCallListener implements EventSubscriberInterface |
12
|
|
|
{ |
13
|
|
|
private $contextSupportedVoter; |
14
|
|
|
|
15
|
|
|
private $httpCallResultPool; |
16
|
|
|
|
17
|
|
|
private $mink; |
18
|
|
|
|
19
|
|
|
public function __construct(ContextSupportedVoter $contextSupportedVoter, HttpCallResultPool $httpCallResultPool, Mink $mink) |
20
|
|
|
{ |
21
|
|
|
$this->contextSupportedVoter = $contextSupportedVoter; |
22
|
|
|
$this->httpCallResultPool = $httpCallResultPool; |
23
|
|
|
$this->mink = $mink; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public static function getSubscribedEvents() |
27
|
|
|
{ |
28
|
|
|
return [ |
29
|
|
|
StepTested::AFTER => 'afterStep' |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function afterStep(AfterStepTested $event) |
34
|
|
|
{ |
35
|
|
|
$testResult = $event->getTestResult(); |
36
|
|
|
|
37
|
|
|
if (!$testResult instanceof ExecutedStepResult) { |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$httpCallResult = new HttpCallResult( |
42
|
|
|
$testResult->getCallResult()->getReturn() |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
if ($this->contextSupportedVoter->vote($httpCallResult)) { |
46
|
|
|
$this->httpCallResultPool->store($httpCallResult); |
47
|
|
|
|
48
|
|
|
return true; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// For now to avoid modification on MinkContext |
52
|
|
|
// We add fallback on Mink |
53
|
|
|
try { |
54
|
|
|
$this->httpCallResultPool->store( |
55
|
|
|
new HttpCallResult($this->mink->getSession()->getPage()->getContent()) |
56
|
|
|
); |
57
|
|
|
} catch (\LogicException $e) { |
58
|
|
|
// Mink has no response |
59
|
|
|
} catch (\Behat\Mink\Exception\DriverException $e) { |
60
|
|
|
// No Mink |
61
|
|
|
} catch (\Throwable $t) { |
|
|
|
|
62
|
|
|
printf('What do we want to do with "%s"', $t->getMessage()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.