|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2020. |
|
4
|
|
|
* @author Paweł Antosiak <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace Gorynych\Testing; |
|
10
|
|
|
|
|
11
|
|
|
use Gorynych\Testing\Constraint\ContainsSubset; |
|
12
|
|
|
use Gorynych\Testing\Constraint\MatchesJsonSchema; |
|
13
|
|
|
use Gorynych\Util\SchemaFactory; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
trait ApiAssertionsTrait |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Asserts that response status code matches given one |
|
19
|
|
|
*/ |
|
20
|
|
|
protected static function assertStatusCodeSame(int $statusCode, string $message = ''): void |
|
21
|
|
|
{ |
|
22
|
|
|
static::assertSame($statusCode, static::$client->getResponse()->getStatusCode(), $message); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Asserts that response contains given subset |
|
27
|
|
|
* |
|
28
|
|
|
* @param mixed $subset |
|
29
|
|
|
*/ |
|
30
|
|
|
protected static function assertContainsSubset($subset, bool $checkForObjectIdentity = false, string $message = ''): void |
|
31
|
|
|
{ |
|
32
|
|
|
$constraint = new ContainsSubset($subset, $checkForObjectIdentity); |
|
33
|
|
|
|
|
34
|
|
|
static::assertThat(static::normalizeResponse(), $constraint, $message); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Asserts that response matches given item resource JSON schema |
|
39
|
|
|
*/ |
|
40
|
|
|
protected static function assertMatchesItemJsonSchema(string $schemaClassName, ?int $checkMode = null, string $message = ''): void |
|
41
|
|
|
{ |
|
42
|
|
|
self::matchesJsonSchema(static::normalizeResponse(), $schemaClassName, $checkMode, $message); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Asserts that response matches given collection resource JSON schema |
|
47
|
|
|
*/ |
|
48
|
|
|
protected static function assertMatchesCollectionJsonSchema(string $schemaClassName, ?int $checkMode = null, string $message = ''): void |
|
49
|
|
|
{ |
|
50
|
|
|
$data = static::normalizeResponse(); |
|
51
|
|
|
|
|
52
|
|
|
self::matchesJsonSchema($data[0] ?? $data, $schemaClassName, $checkMode, $message); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param mixed[] $data |
|
57
|
|
|
*/ |
|
58
|
|
|
private static function matchesJsonSchema($data, string $schemaClassName, ?int $checkMode, string $message = ''): void |
|
59
|
|
|
{ |
|
60
|
|
|
$schema = json_decode(static::$container->get(SchemaFactory::class)->create($schemaClassName)); |
|
61
|
|
|
$constraint = new MatchesJsonSchema($schema, $checkMode); |
|
62
|
|
|
|
|
63
|
|
|
static::assertThat($data, $constraint, $message); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths