These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use Behat\Behat\Hook\Scope\AfterStepScope; |
||
4 | use Behat\Mink\Driver\Selenium2Driver; |
||
5 | use Behat\MinkExtension\Context\RawMinkContext; |
||
6 | use Behat\Testwork\Tester\Result\TestResult; |
||
7 | |||
8 | class ScreenShotAfterFailContext extends RawMinkContext |
||
0 ignored issues
–
show
|
|||
9 | { |
||
10 | /** |
||
11 | * @AfterStep |
||
12 | * @param AfterStepScope $scope |
||
13 | */ |
||
14 | public function takeScreenShotAfterFailedStep(AfterStepScope $scope) |
||
15 | { |
||
16 | if ($scope->getTestResult()->getResultCode() !== TestResult::FAILED) { |
||
17 | return; |
||
18 | } |
||
19 | |||
20 | $driver = $this->getSession()->getDriver(); |
||
21 | |||
22 | if (!($driver instanceof Selenium2Driver)) { |
||
23 | return; |
||
24 | } |
||
25 | |||
26 | $fileName = basename($scope->getFeature()->getFile()) . '_' . $scope->getStep()->getLine(); |
||
27 | file_put_contents($this->getScreenShotDir() . $fileName . '.png', $this->getSession()->getDriver()->getScreenshot()); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return string |
||
32 | */ |
||
33 | private function getScreenShotDir() |
||
34 | { |
||
35 | return '/app/tests/app/var/screens/'; |
||
36 | } |
||
37 | } |
||
38 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.