diff --git a/src/DomAssertionsServiceProvider.php b/src/DomAssertionsServiceProvider.php index 78305c4..4ba02b0 100644 --- a/src/DomAssertionsServiceProvider.php +++ b/src/DomAssertionsServiceProvider.php @@ -3,7 +3,6 @@ namespace Sinnbeck\DomAssertions; use Illuminate\Support\ServiceProvider; -use Illuminate\Support\Traits\Macroable; use Illuminate\Testing\TestComponent; use Illuminate\Testing\TestResponse; use Illuminate\Testing\TestView; @@ -15,9 +14,8 @@ public function boot() if ($this->app->runningUnitTests()) { TestResponse::mixin(new TestResponseMacros); TestView::mixin(new TestViewMacros); - - // https://github.com/laravel/framework/pull/54359 - if (in_array(Macroable::class, class_uses(TestComponent::class) ?? [])) { + if (version_compare($this->app->version(), '11.41.0', '>=')) { + // @phpstan-ignore-next-line TestComponent::mixin(new TestComponentMacros); } } diff --git a/src/TestComponentMacros.php b/src/TestComponentMacros.php index 3156cd4..8900707 100644 --- a/src/TestComponentMacros.php +++ b/src/TestComponentMacros.php @@ -24,12 +24,12 @@ public function assertHtml5(): Closure return function () { /** @var TestComponent $this */ Assert::assertNotEmpty( - (string) $this->rendered, + (string) $this, 'The component is empty!' ); try { - $parser = DomParser::new((string) $this->rendered); + $parser = DomParser::new((string) $this); } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } @@ -49,12 +49,12 @@ public function assertElementExists(): Closure return function ($selector = 'body', $callback = null): TestComponent { /** @var TestComponent $this */ Assert::assertNotEmpty( - (string) $this->rendered, + (string) $this, 'The component is empty!' ); try { - $parser = DomParser::new((string) $this->rendered); + $parser = DomParser::new((string) $this); } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } @@ -73,7 +73,7 @@ public function assertElementExists(): Closure Assert::assertNotNull($element, sprintf('No element found with selector: %s', $selector)); if ($callback) { - $callback(new AssertElement((string) $this->rendered, $element)); + $callback(new AssertElement((string) $this, $element)); } return $this; @@ -85,12 +85,12 @@ public function assertFormExists(): Closure return function ($selector = 'form', $callback = null): TestComponent { /** @var TestComponent $this */ Assert::assertNotEmpty( - (string) $this->rendered, + (string) $this, 'The component is empty!' ); try { - $parser = DomParser::new((string) $this->rendered); + $parser = DomParser::new((string) $this); } catch (DOMException $exception) { Assert::fail($exception->getMessage()); } @@ -116,7 +116,7 @@ public function assertFormExists(): Closure 'Element is not of type form!'); if ($callback) { - $callback(new AssertForm((string) $this->rendered, $form)); + $callback(new AssertForm((string) $this, $form)); } return $this; diff --git a/tests/ComponentTest.php b/tests/ComponentTest.php index bfd02e0..7c6a798 100644 --- a/tests/ComponentTest.php +++ b/tests/ComponentTest.php @@ -1,7 +1,5 @@ version(), '11.41.0', '>=')) { TestCase::markTestSkipped('Testing Blade components is unavailable in this version of Laravel'); } });