Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/DomAssertionsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/TestComponentMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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;
Expand All @@ -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());
}
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions tests/ComponentTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use Illuminate\Support\Traits\Macroable;
use Illuminate\Testing\TestComponent;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
use Sinnbeck\DomAssertions\Asserts\AssertElement;
Expand All @@ -13,7 +11,7 @@
use Tests\Views\Components\NestedComponent;

beforeEach(function () {
if (! in_array(Macroable::class, class_uses(TestComponent::class) ?? [])) {
if (! version_compare(app()->version(), '11.41.0', '>=')) {
TestCase::markTestSkipped('Testing Blade components is unavailable in this version of Laravel');
}
});
Expand Down
Loading