3 declare(strict_types = 1);
20 use Psr\Http\Message\ResponseInterface;
90 if ($this->buildFlags & self::FLAG_BUILD_HTML) {
91 $content .=
'<div>HTML content</div>';
93 if ($this->buildFlags & self::FLAG_BUILD_PHP) {
95 $content .=
'<div><?php echo base64_decode(\'UEhQIGNvbnRlbnQ=\');?></div>';
97 if ($this->buildFlags & self::FLAG_BUILD_SVG) {
98 $content .=
'<text id="test" x="0" y="0">SVG content</text>';
100 if ($this->buildFlags & self::FLAG_BUILD_SVG_DOCUMENT) {
102 '<svg xmlns="http://www.w3.org/2000/svg">%s</svg>',
107 '<!DOCTYPE html><html lang="en"><body>%s</body></html>',
112 public function matches(ResponseInterface $response): bool
121 public function getMismatches(ResponseInterface $response): array
124 if ($this->handler instanceof \Closure) {
125 $result = $this->handler->call($this, $response);
126 if ($result !==
null) {
127 $mismatches[] = $result;
132 $body = (string)$response->getBody();
133 $contentType = $response->getHeaderLine(
'content-type');
134 if ($this->expectedContent !==
null && strpos($body, $this->expectedContent) ===
false) {
135 $mismatches[] =
new StatusMessage(
136 'content mismatch %s',
137 $this->expectedContent,
141 if ($this->unexpectedContent !==
null && strpos($body, $this->unexpectedContent) !==
false) {
142 $mismatches[] =
new StatusMessage(
143 'unexpected content %s',
144 $this->unexpectedContent,
148 if ($this->expectedContentType !==
null
149 && strpos($contentType .
';', $this->expectedContentType .
';') !== 0) {
150 $mismatches[] =
new StatusMessage(
151 'content-type mismatch %s, got %s',
152 $this->expectedContentType,
156 if ($this->unexpectedContentType !==
null
157 && strpos($contentType .
';', $this->unexpectedContentType .
';') === 0) {
159 'unexpected content-type %s',
160 $this->unexpectedContentType,
169 $target = clone $this;
170 $target->expectedContentType = $contentType;
176 $target = clone $this;
177 $target->unexpectedContentType = $contentType;
183 $target = clone $this;
184 $target->expectedContent = $content;
190 $target = clone $this;
191 $target->unexpectedContent = $content;
197 $target = clone $this;
204 $target = clone $this;
228 public function getUrl(): string