Issues (142)

Spec/ResponseTrait.php (3 issues)

Labels
Severity
1
<?php
2
3
/*
4
 * This file is part of the doyo/code-coverage project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Spec\Doyo\Bridge\CodeCoverage;
15
16
use Symfony\Component\HttpFoundation\JsonResponse;
0 ignored issues
show
The type Symfony\Component\HttpFoundation\JsonResponse 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...
17
use Symfony\Component\HttpFoundation\Response;
0 ignored issues
show
The type Symfony\Component\HttpFoundation\Response 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...
18
use Webmozart\Assert\Assert;
0 ignored issues
show
The type Webmozart\Assert\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...
19
20
/**
21
 * Trait ResponseTrait.
22
 */
23
trait ResponseTrait
24
{
25
    public function getMatchers(): array
26
    {
27
        return [
28
            'beInJson' => function ($subject) {
29
                Assert::isInstanceOf($subject, JsonResponse::class);
30
31
                return true;
32
            },
33
            'containJsonKey' => function ($subject, $key) {
34
                /** @var \Symfony\Component\HttpFoundation\JsonResponse $subject */
35
                $json = $subject->getContent();
36
                $json = json_decode($json, true);
37
                Assert::isArray($json);
38
                Assert::keyExists($json, $key);
39
40
                return true;
41
            },
42
            'containJsonKeyWithValue' => function ($subject, $key, $expected) {
43
                /** @var \Symfony\Component\HttpFoundation\JsonResponse $subject */
44
                $json = $subject->getContent();
45
                $json = json_decode($json, true);
46
                Assert::keyExists($json, $key);
47
                Assert::contains($json[$key], $expected);
48
49
                return true;
50
            },
51
            'haveStatusCode' => function ($subject, $expected) {
52
                Assert::eq($subject->getStatusCode(), $expected);
53
54
                return true;
55
            },
56
            'haveContent' => function ($subject, $expected) {
57
                Assert::isInstanceOf($subject, Response::class);
58
                Assert::contains($subject->getContent(), $expected);
59
60
                return true;
61
            },
62
            'beAHttpResponse' => function ($subject) {
63
                Assert::isInstanceOf($subject, Response::class);
64
65
                return true;
66
            },
67
            'beASerializedObject' => function ($subject, $expected) {
68
                /** @var \Symfony\Component\HttpFoundation\Response $subject */
69
                $serialized = unserialize($subject->getContent());
70
                $class = $expected;
71
                if (!\is_string($class)) {
72
                    $class = \get_class($class);
73
                }
74
                Assert::isInstanceOf($serialized, $class);
75
76
                return true;
77
            },
78
        ];
79
    }
80
}
81