From b5494d68be4c5722f446bb8cddce8d34fecc0445 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 6 Oct 2025 20:43:13 +0100 Subject: [PATCH 1/8] cache parser --- src/TestComponentMacros.php | 6 ++++-- src/TestResponseMacros.php | 6 ++++-- src/TestViewMacros.php | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/TestComponentMacros.php b/src/TestComponentMacros.php index 2ff04ab..f7c1491 100644 --- a/src/TestComponentMacros.php +++ b/src/TestComponentMacros.php @@ -96,12 +96,14 @@ public function assertContainsElement(): Closure ); try { - $parser = DomParser::new((string) $this); + if (! isset($this->parser)) { + $this->parser = DomParser::new((string) $this); + } } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } - $element = $parser->query($selector); + $element = $this->parser->query($selector); Assert::assertNotNull( $element, diff --git a/src/TestResponseMacros.php b/src/TestResponseMacros.php index 7ab39b9..d630e74 100644 --- a/src/TestResponseMacros.php +++ b/src/TestResponseMacros.php @@ -96,12 +96,14 @@ public function assertContainsElement(): Closure ); try { - $parser = DomParser::new($this->getContent()); + if (! isset($this->parser)) { + $this->parser = DomParser::new($this->getContent()); + } } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } - $element = $parser->query($selector); + $element = $this->parser->query($selector); Assert::assertNotNull( $element, diff --git a/src/TestViewMacros.php b/src/TestViewMacros.php index ae55f8a..bb8f7b2 100644 --- a/src/TestViewMacros.php +++ b/src/TestViewMacros.php @@ -96,12 +96,14 @@ public function assertContainsElement(): Closure ); try { - $parser = DomParser::new((string) $this); + if (! isset($this->parser)) { + $this->parser = DomParser::new((string) $this); + } } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } - $element = $parser->query($selector); + $element = $this->parser->query($selector); Assert::assertNotNull( $element, From cbfedb7ed44a597e46dab6bf569921a816cb5a14 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 6 Oct 2025 20:53:57 +0100 Subject: [PATCH 2/8] Update phpstan-baseline.neon --- phpstan-baseline.neon | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 46767c1..0eda7f7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4,4 +4,6 @@ parameters: - src tmpDir: build/phpstan checkOctaneCompatibility: true - checkModelProperties: true \ No newline at end of file + checkModelProperties: true + ignoreErrors: + - '#Access to an undefined property .*::\$parser#' \ No newline at end of file From 0915c9e4e78074b5ddf70ff795136e9049bdcffd Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 6 Oct 2025 20:58:13 +0100 Subject: [PATCH 3/8] dom parser --- phpstan-baseline.neon | 2 +- src/Asserts/AssertForm.php | 6 +++--- src/Asserts/BaseAssert.php | 4 ++-- src/Asserts/Traits/InteractsWithParser.php | 2 +- src/TestComponentMacros.php | 6 +++--- src/TestResponseMacros.php | 6 +++--- src/TestViewMacros.php | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0eda7f7..aba4ffe 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,4 +6,4 @@ parameters: checkOctaneCompatibility: true checkModelProperties: true ignoreErrors: - - '#Access to an undefined property .*::\$parser#' \ No newline at end of file + - '#Access to an undefined property .*::\domParser#' \ No newline at end of file diff --git a/src/Asserts/AssertForm.php b/src/Asserts/AssertForm.php index 36212f9..bcd68ae 100644 --- a/src/Asserts/AssertForm.php +++ b/src/Asserts/AssertForm.php @@ -42,7 +42,7 @@ public function hasMethod(string $method): self public function hasSpoofMethod(string $type): self { - $element = $this->parser->query('input[type="hidden"][name="_method"]'); + $element = $this->domParser->query('input[type="hidden"][name="_method"]'); Assert::assertNotNull( $element, sprintf('No spoof methods was found in form!') @@ -60,7 +60,7 @@ public function hasSpoofMethod(string $type): self public function hasCSRF(): self { Assert::assertNotNull( - $this->parser->query('input[type="hidden"][name="_token"]'), + $this->domParser->query('input[type="hidden"][name="_token"]'), 'No CSRF was found in form!'); return $this; @@ -68,7 +68,7 @@ public function hasCSRF(): self protected function getAttributeFromForm(string $attribute) { - return $this->parser->getAttributeForRoot($attribute); + return $this->domParser->getAttributeForRoot($attribute); } public function findSelect($selector = 'select', $callback = null): static diff --git a/src/Asserts/BaseAssert.php b/src/Asserts/BaseAssert.php index 3f41ce6..64d8bd7 100644 --- a/src/Asserts/BaseAssert.php +++ b/src/Asserts/BaseAssert.php @@ -30,10 +30,10 @@ abstract class BaseAssert public function __construct($html, $element = null) { - $this->parser = DomParser::new($html); + $this->domParser = DomParser::new($html); if (! is_null($element)) { - $this->parser->setRoot($element); + $this->domParser->setRoot($element); } } diff --git a/src/Asserts/Traits/InteractsWithParser.php b/src/Asserts/Traits/InteractsWithParser.php index 40436ec..1728251 100644 --- a/src/Asserts/Traits/InteractsWithParser.php +++ b/src/Asserts/Traits/InteractsWithParser.php @@ -13,7 +13,7 @@ trait InteractsWithParser public function getParser(): DomParser { - return $this->parser; + return $this->domParser; } protected function getContent(): string diff --git a/src/TestComponentMacros.php b/src/TestComponentMacros.php index f7c1491..f282afd 100644 --- a/src/TestComponentMacros.php +++ b/src/TestComponentMacros.php @@ -96,14 +96,14 @@ public function assertContainsElement(): Closure ); try { - if (! isset($this->parser)) { - $this->parser = DomParser::new((string) $this); + if (! isset($this->domParser)) { + $this->domParser = DomParser::new((string) $this); } } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } - $element = $this->parser->query($selector); + $element = $this->domParser->query($selector); Assert::assertNotNull( $element, diff --git a/src/TestResponseMacros.php b/src/TestResponseMacros.php index d630e74..db011a6 100644 --- a/src/TestResponseMacros.php +++ b/src/TestResponseMacros.php @@ -96,14 +96,14 @@ public function assertContainsElement(): Closure ); try { - if (! isset($this->parser)) { - $this->parser = DomParser::new($this->getContent()); + if (! isset($this->domParser)) { + $this->domParser = DomParser::new($this->getContent()); } } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } - $element = $this->parser->query($selector); + $element = $this->domParser->query($selector); Assert::assertNotNull( $element, diff --git a/src/TestViewMacros.php b/src/TestViewMacros.php index bb8f7b2..0cb8d54 100644 --- a/src/TestViewMacros.php +++ b/src/TestViewMacros.php @@ -96,14 +96,14 @@ public function assertContainsElement(): Closure ); try { - if (! isset($this->parser)) { - $this->parser = DomParser::new((string) $this); + if (! isset($this->domParser)) { + $this->domParser = DomParser::new((string) $this); } } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } - $element = $this->parser->query($selector); + $element = $this->domParser->query($selector); Assert::assertNotNull( $element, From de2b9970c96cbec95e4180201b00270edf325853 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 6 Oct 2025 21:00:33 +0100 Subject: [PATCH 4/8] Update phpstan-baseline.neon --- phpstan-baseline.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index aba4ffe..436fb3f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,4 +6,4 @@ parameters: checkOctaneCompatibility: true checkModelProperties: true ignoreErrors: - - '#Access to an undefined property .*::\domParser#' \ No newline at end of file + - '#Access to an undefined property .*::\$domParser#' \ No newline at end of file From d80c1ac47b10ef019c44e0166d841e2bf66bea17 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 6 Oct 2025 21:07:34 +0100 Subject: [PATCH 5/8] diff --- src/Asserts/AssertForm.php | 7 +++---- src/Asserts/BaseAssert.php | 4 ++-- src/Asserts/Traits/InteractsWithParser.php | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Asserts/AssertForm.php b/src/Asserts/AssertForm.php index bcd68ae..73a932f 100644 --- a/src/Asserts/AssertForm.php +++ b/src/Asserts/AssertForm.php @@ -42,7 +42,7 @@ public function hasMethod(string $method): self public function hasSpoofMethod(string $type): self { - $element = $this->domParser->query('input[type="hidden"][name="_method"]'); + $element = this->parser->query('input[type="hidden"][name="_method"]'); Assert::assertNotNull( $element, sprintf('No spoof methods was found in form!') @@ -59,8 +59,7 @@ public function hasSpoofMethod(string $type): self public function hasCSRF(): self { - Assert::assertNotNull( - $this->domParser->query('input[type="hidden"][name="_token"]'), + Assert::assertNotNull($this->parser->query('input[type="hidden"][name="_token"]'), 'No CSRF was found in form!'); return $this; @@ -68,7 +67,7 @@ public function hasCSRF(): self protected function getAttributeFromForm(string $attribute) { - return $this->domParser->getAttributeForRoot($attribute); + return $this->parser->getAttributeForRoot($attribute); } public function findSelect($selector = 'select', $callback = null): static diff --git a/src/Asserts/BaseAssert.php b/src/Asserts/BaseAssert.php index 64d8bd7..3f41ce6 100644 --- a/src/Asserts/BaseAssert.php +++ b/src/Asserts/BaseAssert.php @@ -30,10 +30,10 @@ abstract class BaseAssert public function __construct($html, $element = null) { - $this->domParser = DomParser::new($html); + $this->parser = DomParser::new($html); if (! is_null($element)) { - $this->domParser->setRoot($element); + $this->parser->setRoot($element); } } diff --git a/src/Asserts/Traits/InteractsWithParser.php b/src/Asserts/Traits/InteractsWithParser.php index 1728251..40436ec 100644 --- a/src/Asserts/Traits/InteractsWithParser.php +++ b/src/Asserts/Traits/InteractsWithParser.php @@ -13,7 +13,7 @@ trait InteractsWithParser public function getParser(): DomParser { - return $this->domParser; + return $this->parser; } protected function getContent(): string From 02586f3a95f3bfee1ac97ee5ee542db1c12ce210 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 6 Oct 2025 21:08:26 +0100 Subject: [PATCH 6/8] Update AssertForm.php --- src/Asserts/AssertForm.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Asserts/AssertForm.php b/src/Asserts/AssertForm.php index 73a932f..36212f9 100644 --- a/src/Asserts/AssertForm.php +++ b/src/Asserts/AssertForm.php @@ -42,7 +42,7 @@ public function hasMethod(string $method): self public function hasSpoofMethod(string $type): self { - $element = this->parser->query('input[type="hidden"][name="_method"]'); + $element = $this->parser->query('input[type="hidden"][name="_method"]'); Assert::assertNotNull( $element, sprintf('No spoof methods was found in form!') @@ -59,7 +59,8 @@ public function hasSpoofMethod(string $type): self public function hasCSRF(): self { - Assert::assertNotNull($this->parser->query('input[type="hidden"][name="_token"]'), + Assert::assertNotNull( + $this->parser->query('input[type="hidden"][name="_token"]'), 'No CSRF was found in form!'); return $this; From 050a72ed4085bc772d287bc719f94ae4b64a0554 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 9 Oct 2025 12:42:48 +0100 Subject: [PATCH 7/8] use container --- src/TestComponentMacros.php | 6 +++--- src/TestResponseMacros.php | 6 +++--- src/TestViewMacros.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/TestComponentMacros.php b/src/TestComponentMacros.php index f282afd..608875c 100644 --- a/src/TestComponentMacros.php +++ b/src/TestComponentMacros.php @@ -96,14 +96,14 @@ public function assertContainsElement(): Closure ); try { - if (! isset($this->domParser)) { - $this->domParser = DomParser::new((string) $this); + if (! app()->has('dom-assertions.parser')) { + app()->instance('dom-assertions.parser', DomParser::new((string) $this)); } } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } - $element = $this->domParser->query($selector); + $element = app()->make('dom-assertions.parser')->query($selector); Assert::assertNotNull( $element, diff --git a/src/TestResponseMacros.php b/src/TestResponseMacros.php index db011a6..3a4bb0e 100644 --- a/src/TestResponseMacros.php +++ b/src/TestResponseMacros.php @@ -96,14 +96,14 @@ public function assertContainsElement(): Closure ); try { - if (! isset($this->domParser)) { - $this->domParser = DomParser::new($this->getContent()); + if (! app()->has('dom-assertions.parser')) { + app()->instance('dom-assertions.parser', DomParser::new($this->getContent())); } } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } - $element = $this->domParser->query($selector); + $element = app()->make('dom-assertions.parser')->query($selector); Assert::assertNotNull( $element, diff --git a/src/TestViewMacros.php b/src/TestViewMacros.php index 0cb8d54..e811404 100644 --- a/src/TestViewMacros.php +++ b/src/TestViewMacros.php @@ -96,14 +96,14 @@ public function assertContainsElement(): Closure ); try { - if (! isset($this->domParser)) { - $this->domParser = DomParser::new((string) $this); + if (! app()->has('dom-assertions.parser')) { + app()->instance('dom-assertions.parser', DomParser::new((string) $this)); } } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } - $element = $this->domParser->query($selector); + $element = app()->make('dom-assertions.parser')->query($selector); Assert::assertNotNull( $element, From 06789be864e6f66cf4fed7a5c0cf05bc864001b8 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 9 Oct 2025 12:44:14 +0100 Subject: [PATCH 8/8] Update phpstan-baseline.neon --- phpstan-baseline.neon | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 436fb3f..46767c1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4,6 +4,4 @@ parameters: - src tmpDir: build/phpstan checkOctaneCompatibility: true - checkModelProperties: true - ignoreErrors: - - '#Access to an undefined property .*::\$domParser#' \ No newline at end of file + checkModelProperties: true \ No newline at end of file