Passed
Push — 1.x ( e3781f...255b78 )
by Kevin
02:10
created

Json   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 6
c 2
b 0
f 1
dl 0
loc 24
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assertJson() 0 4 1
A assertJsonMatches() 0 9 1
1
<?php
2
3
namespace Zenstruck\Browser\Extension;
4
5
use PHPUnit\Framework\Assert as PHPUnit;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Assert was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use function JmesPath\search;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
trait Json
12
{
13
    final public function assertJson(): self
14
    {
15
        return $this->wrapMinkExpectation(
0 ignored issues
show
Bug introduced by
It seems like wrapMinkExpectation() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
        return $this->/** @scrutinizer ignore-call */ wrapMinkExpectation(
Loading history...
16
            fn() => $this->webAssert()->responseHeaderContains('Content-Type', 'application/json')
0 ignored issues
show
Bug introduced by
It seems like webAssert() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
            fn() => $this->/** @scrutinizer ignore-call */ webAssert()->responseHeaderContains('Content-Type', 'application/json')
Loading history...
17
        );
18
    }
19
20
    /**
21
     * @param string $expression JMESPath expression
22
     * @param mixed  $expected
23
     *
24
     * @return static
25
     */
26
    final public function assertJsonMatches(string $expression, $expected): self
27
    {
28
        $this->assertJson();
29
30
        $data = \json_decode($this->documentElement()->getContent(), true, 512, JSON_THROW_ON_ERROR);
0 ignored issues
show
Bug introduced by
It seems like documentElement() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        $data = \json_decode($this->/** @scrutinizer ignore-call */ documentElement()->getContent(), true, 512, JSON_THROW_ON_ERROR);
Loading history...
31
32
        PHPUnit::assertSame($expected, search($expression, $data));
33
34
        return $this;
35
    }
36
}
37