Skip to content

Commit cbb143f

Browse files
authored
Cache parser for assertContainsElement (#37)
* cached in the container
1 parent d69683b commit cbb143f

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/TestComponentMacros.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ public function assertContainsElement(): Closure
9696
);
9797

9898
try {
99-
$parser = DomParser::new((string) $this);
99+
if (! app()->has('dom-assertions.parser')) {
100+
app()->instance('dom-assertions.parser', DomParser::new((string) $this));
101+
}
100102
} catch (DOMException $exception) {
101103
Assert::fail($exception->getMessage());
102104
}
103105

104-
$element = $parser->query($selector);
106+
$element = app()->make('dom-assertions.parser')->query($selector);
105107

106108
Assert::assertNotNull(
107109
$element,

src/TestResponseMacros.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ public function assertContainsElement(): Closure
9696
);
9797

9898
try {
99-
$parser = DomParser::new($this->getContent());
99+
if (! app()->has('dom-assertions.parser')) {
100+
app()->instance('dom-assertions.parser', DomParser::new($this->getContent()));
101+
}
100102
} catch (DOMException $exception) {
101103
Assert::fail($exception->getMessage());
102104
}
103105

104-
$element = $parser->query($selector);
106+
$element = app()->make('dom-assertions.parser')->query($selector);
105107

106108
Assert::assertNotNull(
107109
$element,

src/TestViewMacros.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ public function assertContainsElement(): Closure
9696
);
9797

9898
try {
99-
$parser = DomParser::new((string) $this);
99+
if (! app()->has('dom-assertions.parser')) {
100+
app()->instance('dom-assertions.parser', DomParser::new((string) $this));
101+
}
100102
} catch (DOMException $exception) {
101103
Assert::fail($exception->getMessage());
102104
}
103105

104-
$element = $parser->query($selector);
106+
$element = app()->make('dom-assertions.parser')->query($selector);
105107

106108
Assert::assertNotNull(
107109
$element,

0 commit comments

Comments
 (0)