diff --git a/src/Api/Concerns/MakesElementAssertions.php b/src/Api/Concerns/MakesElementAssertions.php index 0270add7..a89d4393 100644 --- a/src/Api/Concerns/MakesElementAssertions.php +++ b/src/Api/Concerns/MakesElementAssertions.php @@ -4,7 +4,6 @@ namespace Pest\Browser\Api\Concerns; -use Illuminate\Support\Str; use Pest\Browser\Api\Webpage; use PHPUnit\Framework\ExpectationFailedException; @@ -155,7 +154,7 @@ public function assertCount(string $selector, int $expected): Webpage */ public function assertScript(string $expression, mixed $expected = true): Webpage { - if (! Str::contains($expression, ['===', '!==', '==', '!=', '>', '<', '>=', '<=', '&&', '||']) && ! Str::startsWith($expression, 'return ') && ! Str::startsWith($expression, 'function')) { + if (! self::strContainsAny($expression, ['===', '!==', '==', '!=', '>', '<', '>=', '<=', '&&', '||']) && ! str_starts_with($expression, 'return ') && ! str_starts_with($expression, 'function')) { $expression = "function() { return {$expression}; }"; } @@ -567,4 +566,21 @@ public function waitForText(string|int|float $text): Webpage return $this->assertSee($text); } + + /** + * Return true if haystack contains any of the given needles + * + * @param string $haystack String to look in + * @param array $needles List of needles to look for in haystack + */ + private static function strContainsAny(string $haystack, array $needles): bool + { + foreach ($needles as $needle) { + if (str_contains($haystack, $needle)) { + return true; + } + } + + return false; + } } diff --git a/tests/ArchTest.php b/tests/ArchTest.php index d37896ef..2f5fe285 100644 --- a/tests/ArchTest.php +++ b/tests/ArchTest.php @@ -2,4 +2,12 @@ declare(strict_types=1); -return; +arch() + ->expect(['Illuminate', 'Laravel', 'Livewire']) + ->toOnlyBeUsedIn([ + Pest\Browser\Api\Livewire::class, + Pest\Browser\Api\TestableLivewire::class, + Pest\Browser\Cleanables\Livewire::class, + Pest\Browser\Drivers\LaravelHttpServer::class, + 'Workbench', + ]);