1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace whm\Smoke\Extensions\SmokeReporter\Reporter; |
4
|
|
|
|
5
|
|
|
use phm\HttpWebdriverClient\Http\Request\DeviceAwareRequest; |
6
|
|
|
use phm\HttpWebdriverClient\Http\Request\ViewportAwareRequest; |
7
|
|
|
use phm\HttpWebdriverClient\Http\Response\RequestAwareResponse; |
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use whm\Smoke\Extensions\SmokeResponseRetriever\Retriever\Retriever; |
11
|
|
|
use whm\Smoke\Rules\CheckResult; |
12
|
|
|
|
13
|
|
|
abstract class CliReporter implements Reporter |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var OutputInterface |
17
|
|
|
*/ |
18
|
|
|
protected $output; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Retriever |
22
|
|
|
*/ |
23
|
|
|
protected $retriever; |
24
|
|
|
|
25
|
|
|
public function setResponseRetriever(Retriever $retriever) |
26
|
|
|
{ |
27
|
|
|
$this->retriever = $retriever; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function setOutputInterface(OutputInterface $output) |
31
|
|
|
{ |
32
|
|
|
$this->output = $output; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
private function getRequestString(ResponseInterface $response) |
36
|
|
|
{ |
37
|
|
|
if ($response instanceof RequestAwareResponse) { |
|
|
|
|
38
|
|
|
$request = $response->getRequest(); |
39
|
|
|
if ($request instanceof DeviceAwareRequest) { |
|
|
|
|
40
|
|
|
return ' (Device: ' . $request->getDevice()->getName() . ')'; |
41
|
|
|
} else if ($request instanceof ViewportAwareRequest) { |
|
|
|
|
42
|
|
|
$viewport = $request->getViewport(); |
43
|
|
|
return ' (Viewport: width: ' . $viewport->getWidth() . ', height: ' . $viewport->getHeight() . ')'; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return ''; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function renderFailure(CheckResult $result) |
51
|
|
|
{ |
52
|
|
|
$this->output->writeln(' <error> ' . (string)$result->getResponse()->getUri() . $this->getRequestString($result->getResponse()) . ' </error> coming from ' . (string)$this->retriever->getComingFrom($result->getResponse()->getUri())); |
53
|
|
|
$this->output->writeln(' - ' . $result->getMessage() . ' [rule: ' . $result->getRuleName() . ']'); |
54
|
|
|
$this->output->writeln(''); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function renderSuccess(CheckResult $result) |
58
|
|
|
{ |
59
|
|
|
$this->output->writeln(' <info> ' . (string)$result->getResponse()->getUri() . $this->getRequestString($result->getResponse()) . ' </info> all tests passed'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function renderSkipped(CheckResult $result) |
63
|
|
|
{ |
64
|
|
|
$this->output->writeln(' <comment> ' . (string)$result->getResponse()->getUri() . $this->getRequestString($result->getResponse()) . ' </comment>test skipped'); |
65
|
|
|
$this->output->writeln(' - ' . $result->getMessage() . ' [rule: ' . $result->getRuleName() . ']'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.