MinkJsonProvider::provideJsonResponse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace JsonSpec\Behat\JsonProvider;
4
5
use Behat\Behat\EventDispatcher\Event\AfterStepTested;
6
use Behat\Behat\EventDispatcher\Event\StepTested;
7
use Behat\Behat\Tester\Result\ExecutedStepResult;
8
use Behat\Mink\Mink;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11
class MinkJsonProvider implements EventSubscriberInterface
12
{
13
14
    /**
15
     * @var JsonHolder
16
     */
17
    private $jsonHolder;
18
19
    /**
20
     * @var Mink
21
     */
22
    private $mink;
23
24
    /**
25
     * @param JsonHolder $jsonHolder
26
     * @param Mink $mink
27
     */
28
    public function __construct(JsonHolder $jsonHolder, Mink $mink)
29
    {
30
        $this->jsonHolder = $jsonHolder;
31
        $this->mink = $mink;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public static function getSubscribedEvents()
38
    {
39
        return array(
40
            StepTested::AFTER => 'provideJsonResponse'
41
        );
42
    }
43
44
45
    public function provideJsonResponse(AfterStepTested $event)
46
    {
47
        $testResult = $event->getTestResult();
48
49
        if (!$testResult instanceof ExecutedStepResult) {
50
            return;
51
        }
52
53
        $callResult = $testResult->getCallResult()->getReturn();
54
        if (!$callResult instanceof \Behat\Mink\Element\DocumentElement) {
0 ignored issues
show
Bug introduced by
The class Behat\Mink\Element\DocumentElement does not exist. Did you forget a USE statement, or did you not list all dependencies?

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 the composer.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 or require-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 ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
55
            return;
56
        }
57
58
        $response = $callResult->getContent();
59
        $this->jsonHolder->setJson($response);
60
    }
61
62
}
63