-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRawBodyMatcher.php
More file actions
33 lines (28 loc) · 952 Bytes
/
RawBodyMatcher.php
File metadata and controls
33 lines (28 loc) · 952 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
33
<?php
declare(strict_types=1);
namespace Core\TestCase\BodyMatchers;
use Core\Types\Sdk\CoreFileWrapper;
class RawBodyMatcher extends BodyMatcher
{
/**
* Initializes a RawBodyMatcher object with the expectedBody provided.
*/
public static function init($expectedBody): self
{
$matcher = new self(new BodyComparator(), $expectedBody);
$matcher->defaultMessage = 'Response body does not match exactly';
return $matcher;
}
/**
* Asserts if rawBody matches expectedBody.
*/
public function assert(string $rawBody)
{
parent::assert($rawBody);
if ($this->expectedBody instanceof CoreFileWrapper) {
$this->expectedBody = $this->expectedBody->getFileContent();
$this->defaultMessage = 'Binary result does not match the given file';
}
$this->testCase->assertEquals($this->expectedBody, $rawBody, $this->defaultMessage);
}
}