-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestResponseMixins.php
More file actions
66 lines (53 loc) · 2.3 KB
/
TestResponseMixins.php
File metadata and controls
66 lines (53 loc) · 2.3 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace Ziadoz\AssertableHtml\Mixins;
use Closure;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Ziadoz\AssertableHtml\Dom\AssertableDocument;
class TestResponseMixins
{
/** Get the response HTML content. */
public function getHtmlContent(): Closure
{
return fn (): string => $this->baseResponse instanceof StreamedResponse ? $this->streamedContent() : $this->getContent();
}
/** Return an assertable HTML document. */
public function assertableHtml(): Closure
{
return function (int $options = 0, ?string $overrideEncoding = null): AssertableDocument {
return AssertableDocument::createFromString($this->getHtmlContent(), $options, $overrideEncoding);
};
}
/** Return an assertable HTML document. */
public function assertHtml(): Closure
{
return function (callable $callback, int $options = 0, ?string $overrideEncoding = null): static {
AssertableDocument::createFromString($this->getHtmlContent(), $options, $overrideEncoding)->with($callback);
return $this;
};
}
/** Return an assertable HTML document scoped to <head>. */
public function assertHead(): Closure
{
return function (callable $callback, int $options = 0, ?string $overrideEncoding = null): static {
AssertableDocument::createFromString($this->getHtmlContent(), $options, $overrideEncoding)->one('head', $callback);
return $this;
};
}
/** Return an assertable HTML document scoped to <body>. */
public function assertBody(): Closure
{
return function (callable $callback, int $options = 0, ?string $overrideEncoding = null): static {
AssertableDocument::createFromString($this->getHtmlContent(), $options, $overrideEncoding)->one('body', $callback);
return $this;
};
}
/** Return an assertable HTML document scoped to the given selector. */
public function assertElement(): Closure
{
return function (string $selector, callable $callback, int $options = 0, ?string $overrideEncoding = null): static {
AssertableDocument::createFromString($this->getHtmlContent(), $options, $overrideEncoding)->one($selector, $callback);
return $this;
};
}
}