-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathKeysBodyMatcher.php
More file actions
32 lines (27 loc) · 965 Bytes
/
KeysBodyMatcher.php
File metadata and controls
32 lines (27 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
declare(strict_types=1);
namespace Core\TestCase\BodyMatchers;
use Core\Utils\CoreHelper;
class KeysBodyMatcher extends BodyMatcher
{
/**
* Initializes a new KeysBodyMatcher object with the parameters provided.
*/
public static function init($expectedBody, bool $matchArrayOrder = false, bool $matchArrayCount = false): self
{
$matcher = new self(new BodyComparator(!$matchArrayCount, $matchArrayOrder, false), $expectedBody);
$matcher->defaultMessage = 'Response body does not match in keys';
return $matcher;
}
/**
* Compares rawBody with expectedBody and asserts if expectedBody is a subset of rawBody or not.
*/
public function assert(string $rawBody)
{
parent::assert($rawBody);
$this->testCase->assertTrue(
$this->bodyComparator->compare($this->expectedBody, CoreHelper::deserialize($rawBody)),
$this->defaultMessage
);
}
}