From 8f77c504969bc2695465f0a844c8c46d498894a2 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 15:11:09 -0300 Subject: [PATCH 1/7] Support Laravel 12 --- .github/workflows/run-tests.yml | 5 ++++- composer.json | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0109349..7c098e2 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, macos-latest] - php: [8.2] + php: [8.2, 8.3, 8.4] laravel: [10.*, 11.*] stability: [prefer-lowest, prefer-stable] include: @@ -19,6 +19,9 @@ jobs: - laravel: 11.* testbench: 9.* workbench: 9.* + - laravel: 12.* + testbench: 10.* + workbench: 10.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index 0b03c23..eec04f5 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ ], "require": { "php": "^8.2", - "illuminate/support": "^10.0|^11.0" + "illuminate/support": "^10.0|^11.0|^12.0" }, "require-dev": { "laravel/pint": "^1.10", - "orchestra/testbench": "^8.14|^9.0", - "orchestra/workbench": "^8.0|^9.0", + "orchestra/testbench": "^8.14|^9.0|^10.0", + "orchestra/workbench": "^8.0|^9.0|^10.0", "phpunit/phpunit": "^10.5" }, "autoload": { From 86de589c919f90e8717d55b1e8f250983f8cb256 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 15:14:13 -0300 Subject: [PATCH 2/7] Fix missing Laravel 12.* --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 7c098e2..51a3326 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -10,7 +10,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] php: [8.2, 8.3, 8.4] - laravel: [10.*, 11.*] + laravel: [10.*, 11.*, 12.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* From ff8554aa00fae3c1dfffad562958dadc70d6e2d3 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 15:18:09 -0300 Subject: [PATCH 3/7] Skip Laravel 12 on PHP 8.2 --- .github/workflows/run-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 51a3326..7345c92 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -22,6 +22,9 @@ jobs: - laravel: 12.* testbench: 10.* workbench: 10.* + exclude: + - php: 8.2 + laravel: 12.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} From 23f714c3032ed4723766d193ab4cd43ba107e6c0 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 15:23:12 -0300 Subject: [PATCH 4/7] Support PHPUnit 11 --- .github/workflows/run-tests.yml | 3 --- composer.json | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 7345c92..51a3326 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -22,9 +22,6 @@ jobs: - laravel: 12.* testbench: 10.* workbench: 10.* - exclude: - - php: 8.2 - laravel: 12.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index eec04f5..1254ee9 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "laravel/pint": "^1.10", "orchestra/testbench": "^8.14|^9.0|^10.0", "orchestra/workbench": "^8.0|^9.0|^10.0", - "phpunit/phpunit": "^10.5" + "phpunit/phpunit": "^10.5|^11.5" }, "autoload": { "psr-4": { From afd24a240c93de3ea2a0bc5cfe379550f5ee5f4b Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 15:34:35 -0300 Subject: [PATCH 5/7] Rector --- rector.php | 22 ++ src/Broadcasting/Factory.php | 18 +- src/Broadcasting/PendingBroadcast.php | 31 +- src/Broadcasting/Rendering.php | 18 +- src/Commands/TurboInstallCommand.php | 20 +- src/Events/TurboStreamBroadcast.php | 45 +-- src/Exceptions/TurboStreamTargetException.php | 4 +- src/Facades/Turbo.php | 4 +- src/Facades/TurboStream.php | 2 +- src/Features.php | 2 +- src/Http/HotwireNativeRedirectResponse.php | 2 +- src/Http/Middleware/TurboMiddleware.php | 13 +- .../MultiplePendingTurboStreamResponse.php | 8 +- src/Http/PendingTurboStreamResponse.php | 20 +- src/Jobs/BroadcastAction.php | 38 +- src/Models/Broadcasts.php | 6 +- src/Models/ModelObserver.php | 10 +- src/Models/Naming/Name.php | 2 +- src/NamesResolver.php | 2 +- src/Testing/AssertableTurboStream.php | 2 +- src/Testing/TurboStreamMatcher.php | 17 +- src/Turbo.php | 6 +- src/TurboServiceProvider.php | 74 ++-- src/Views/RecordIdentifier.php | 2 +- src/Views/UnidentifiableRecordException.php | 2 +- tests/Broadcasting/LimiterTest.php | 4 +- tests/Events/TurboStreamBroadcastTest.php | 8 +- tests/FunctionsTest.php | 40 +- .../HotwireNativeNavigationControllerTest.php | 33 +- tests/Http/MacroablePendingStreamTest.php | 10 +- tests/Http/Middleware/TurboMiddlewareTest.php | 48 +-- tests/Http/RequestMacrosTest.php | 16 +- tests/Http/ResponseMacrosTest.php | 374 +++++++++--------- tests/Http/TestResponseMacrosTest.php | 10 +- tests/Http/TurboStreamResponseTest.php | 24 +- tests/Models/BroadcastsModelTest.php | 198 +++++----- tests/Models/BroadcastsToOthersTest.php | 10 +- tests/Models/NamesResolverTest.php | 14 +- tests/Models/NamingTest.php | 23 +- tests/Testing/InteractsWithTurboTest.php | 4 +- tests/Testing/TurboStreamMatcherTest.php | 30 +- tests/TurboStreamsBroadcastingTest.php | 188 +++++---- tests/Views/ComponentsTest.php | 40 +- .../Views/RecordIdentifierStreamableTest.php | 16 +- tests/Views/RecordIdentifierTest.php | 32 +- tests/Views/ViewHelpersTest.php | 43 +- 46 files changed, 697 insertions(+), 838 deletions(-) create mode 100644 rector.php diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..0283c1f --- /dev/null +++ b/rector.php @@ -0,0 +1,22 @@ +withPaths([ + __DIR__.'/src', + __DIR__.'/tests', + ]) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + typeDeclarations: true, + privatization: true, + earlyReturn: true, + ) + ->withAttributesSets() + ->withPhpSets() + ->withPhpVersion(PhpVersion::PHP_82); diff --git a/src/Broadcasting/Factory.php b/src/Broadcasting/Factory.php index f04e6a5..58632a3 100644 --- a/src/Broadcasting/Factory.php +++ b/src/Broadcasting/Factory.php @@ -45,7 +45,7 @@ public function withoutBroadcasts(callable $callback) } } - public function fake() + public function fake(): static { $this->recording = true; @@ -93,7 +93,7 @@ public function broadcastRefresh(Channel|Model|Collection|array|string|null $cha action: 'refresh', channel: $channel, attributes: array_filter(['request-id' => $requestId = Turbo::currentRequestId()]), - )->lazyCancelIf(fn (PendingBroadcast $broadcast) => ( + )->lazyCancelIf(fn (PendingBroadcast $broadcast): bool => ( $this->shouldLimitPageRefreshesOn($broadcast->channels, $requestId) )); } @@ -116,7 +116,7 @@ public function broadcastAction(string $action, $content = null, Model|string|nu return $broadcast->cancelIf(! $this->isBroadcasting); } - public function record(PendingBroadcast $broadcast) + public function record(PendingBroadcast $broadcast): static { $this->recordedStreams[] = $broadcast; @@ -151,9 +151,7 @@ protected function resolveRendering($content) protected function resolveChannels(Channel|Model|Collection|array|string $channel) { if (is_array($channel) || $channel instanceof Collection) { - return collect($channel)->flatMap(function ($channel) { - return $this->resolveChannels($channel); - })->values()->filter()->all(); + return collect($channel)->flatMap(fn ($channel) => $this->resolveChannels($channel))->values()->filter()->all(); } if (is_string($channel)) { @@ -184,7 +182,7 @@ public function clearRecordedBroadcasts(): self return $this; } - public function assertBroadcasted($callback) + public function assertBroadcasted(?callable $callback): static { $result = collect($this->recordedStreams)->filter($callback); @@ -193,7 +191,7 @@ public function assertBroadcasted($callback) return $this; } - public function assertBroadcastedTimes($callback, $times = 1, $message = null) + public function assertBroadcastedTimes(?callable $callback, $times = 1, $message = null): static { $result = collect($this->recordedStreams)->filter($callback); @@ -210,8 +208,6 @@ public function assertBroadcastedTimes($callback, $times = 1, $message = null) public function assertNothingWasBroadcasted() { - return $this->assertBroadcastedTimes(function () { - return true; - }, 0, sprintf('Expected to not have broadcasted any Turbo Stream, but broadcasted %d instead.', count($this->recordedStreams))); + return $this->assertBroadcastedTimes(fn (): true => true, 0, sprintf('Expected to not have broadcasted any Turbo Stream, but broadcasted %d instead.', count($this->recordedStreams))); } } diff --git a/src/Broadcasting/PendingBroadcast.php b/src/Broadcasting/PendingBroadcast.php index 48e9f03..2e31518 100644 --- a/src/Broadcasting/PendingBroadcast.php +++ b/src/Broadcasting/PendingBroadcast.php @@ -18,12 +18,6 @@ class PendingBroadcast /** @var Channel[] */ public array $channels; - public string $action; - - public ?string $target = null; - - public ?string $targets = null; - public ?string $partialView = null; public ?array $partialData = []; @@ -32,8 +26,6 @@ class PendingBroadcast public bool $escapeInlineContent = true; - public array $attributes = []; - /** * Whether we should broadcast only to other users and * ignore the current user's broadcasting socket. @@ -61,7 +53,7 @@ class PendingBroadcast * * @var ?\HotwiredLaravel\TurboLaravel\Broadcasting\Factory = null */ - protected $recorder = null; + protected $recorder; /** * These cancel callbacks will run right before the broadcasting is fired on __destruct. @@ -70,13 +62,8 @@ class PendingBroadcast */ protected array $deferredCancelCallbacks = []; - public function __construct(array $channels, string $action, Rendering $rendering, ?string $target = null, ?string $targets = null, array $attributes = []) + public function __construct(array $channels, public string $action, Rendering $rendering, public ?string $target = null, public ?string $targets = null, public array $attributes = []) { - $this->action = $action; - $this->target = $target; - $this->targets = $targets; - $this->attributes = $attributes; - $this->to($channels); $this->rendering($rendering); } @@ -142,12 +129,12 @@ public function view(?string $view, array $data = []): self return $this->rendering(new Rendering($view, $data)); } - public function content($content) + public function content(\Illuminate\Contracts\View\View|\Illuminate\Support\HtmlString|string $content) { return $this->rendering(Rendering::forContent($content)); } - public function attributes(array $attributes) + public function attributes(array $attributes): static { $this->attributes = $attributes; @@ -170,7 +157,7 @@ public function method(?string $method = null): self return $this->attributes(Arr::except($this->attributes, 'method')); } - public function rendering(Rendering $rendering) + public function rendering(Rendering $rendering): static { $this->partialView = $rendering->partial; $this->partialData = $rendering->data; @@ -187,28 +174,28 @@ public function later(bool $later = true): self return $this; } - public function cancel() + public function cancel(): static { $this->wasCancelled = true; return $this; } - public function cancelIf($condition) + public function cancelIf($condition): static { $this->wasCancelled = $this->wasCancelled || boolval(value($condition, $this)); return $this; } - public function lazyCancelIf(callable $condition) + public function lazyCancelIf(callable $condition): static { $this->deferredCancelCallbacks[] = $condition; return $this; } - public function fake($recorder = null) + public function fake($recorder = null): static { $this->isRecording = true; $this->recorder = $recorder; diff --git a/src/Broadcasting/Rendering.php b/src/Broadcasting/Rendering.php index c8d948c..444c5c6 100644 --- a/src/Broadcasting/Rendering.php +++ b/src/Broadcasting/Rendering.php @@ -9,23 +9,9 @@ class Rendering { - public ?string $partial = null; + public function __construct(public ?string $partial = null, public ?array $data = [], public ?string $inlineContent = null, public bool $escapeInlineContent = true) {} - public ?array $data = []; - - public ?string $inlineContent = null; - - public bool $escapeInlineContent = true; - - public function __construct(?string $partial = null, ?array $data = [], ?string $inlineContent = null, ?bool $escapeInlineContent = true) - { - $this->partial = $partial; - $this->data = $data; - $this->inlineContent = $inlineContent; - $this->escapeInlineContent = $escapeInlineContent; - } - - public static function forContent(View|HtmlString|string $content) + public static function forContent(View|HtmlString|string $content): static { if ($content instanceof View) { return new static(partial: $content->name(), data: $content->getData()); diff --git a/src/Commands/TurboInstallCommand.php b/src/Commands/TurboInstallCommand.php index 123450e..56c0c5b 100644 --- a/src/Commands/TurboInstallCommand.php +++ b/src/Commands/TurboInstallCommand.php @@ -16,7 +16,7 @@ class TurboInstallCommand extends Command public $description = 'Installs Turbo.'; - public function handle() + public function handle(): void { $this->updateLayouts(); $this->publishJsFiles(); @@ -26,7 +26,7 @@ public function handle() $this->components->info('Turbo Laravel was installed successfully.'); } - private function publishJsFiles() + private function publishJsFiles(): void { File::ensureDirectoryExists(resource_path('js/elements')); File::ensureDirectoryExists(resource_path('js/libs')); @@ -38,7 +38,7 @@ private function publishJsFiles() File::put(resource_path('js/libs/index.js'), $this->libsIndexJsImportLines()); } - private function appJsImportLines() + private function appJsImportLines(): string { $prefix = $this->usingImportmaps() ? '' : './'; @@ -51,7 +51,7 @@ private function appJsImportLines() return implode("\n", $imports); } - private function libsIndexJsImportLines() + private function libsIndexJsImportLines(): string { $imports = []; @@ -62,7 +62,7 @@ private function libsIndexJsImportLines() return implode("\n", $imports); } - private function installJsDependencies() + private function installJsDependencies(): void { if ($this->usingImportmaps()) { $this->updateImportmapsDependencies(); @@ -74,9 +74,7 @@ private function installJsDependencies() private function updateNpmDependencies(): void { - $this->updateNodePackages(function ($packages) { - return $this->jsDependencies() + $packages; - }); + static::updateNodePackages(fn ($packages): array => $this->jsDependencies() + $packages); } private function runInstallAndBuildCommand(): void @@ -92,7 +90,7 @@ private function runInstallAndBuildCommand(): void } } - private function runCommands($commands): void + private function runCommands(array $commands): void { $process = Process::fromShellCommandline(implode(' && ', $commands), null, null, null, null); @@ -104,7 +102,7 @@ private function runCommands($commands): void } } - $process->run(function ($type, $line) { + $process->run(function ($type, string $line): void { $this->output->write(' '.$line); }); } @@ -174,7 +172,7 @@ private function existingLayoutFiles() ->filter(fn ($file) => File::exists($file)); } - private function phpBinary() + private function phpBinary(): string { return (new PhpExecutableFinder)->find(false) ?: 'php'; } diff --git a/src/Events/TurboStreamBroadcast.php b/src/Events/TurboStreamBroadcast.php index 75011a7..a9c014a 100644 --- a/src/Events/TurboStreamBroadcast.php +++ b/src/Events/TurboStreamBroadcast.php @@ -12,44 +12,25 @@ class TurboStreamBroadcast implements ShouldBroadcastNow { use InteractsWithSockets; - /** @var Channel[] */ - public array $channels; - - public string $action; - - public ?string $target = null; - - public ?string $targets = null; - - public ?string $partial = null; - - public ?array $partialData = []; - - public ?string $inlineContent = null; - - public array $attrs = []; - - public bool $escapeInlineContent = true; - - public function __construct(array $channels, string $action, ?string $target = null, ?string $targets = null, ?string $partial = null, ?array $partialData = [], ?string $inlineContent = null, bool $escapeInlineContent = true, array $attributes = []) - { - $this->channels = $channels; - $this->action = $action; - $this->target = $target; - $this->targets = $targets; - $this->partial = $partial; - $this->partialData = $partialData; - $this->inlineContent = $inlineContent; - $this->escapeInlineContent = $escapeInlineContent; - $this->attrs = $attributes; - } + public function __construct( + /** @var Channel[] */ + public array $channels, + public string $action, + public ?string $target = null, + public ?string $targets = null, + public ?string $partial = null, + public ?array $partialData = [], + public ?string $inlineContent = null, + public bool $escapeInlineContent = true, + public array $attrs = [] + ) {} public function broadcastOn() { return $this->channels; } - public function broadcastWith() + public function broadcastWith(): array { return [ 'message' => $this->render(), diff --git a/src/Exceptions/TurboStreamTargetException.php b/src/Exceptions/TurboStreamTargetException.php index d081e72..8298c6c 100644 --- a/src/Exceptions/TurboStreamTargetException.php +++ b/src/Exceptions/TurboStreamTargetException.php @@ -6,12 +6,12 @@ class TurboStreamTargetException extends InvalidArgumentException { - public static function targetMissing() + public static function targetMissing(): static { return new static('No target was specified'); } - public static function multipleTargets() + public static function multipleTargets(): static { return new static('Must specify either target or targets attributes, but never both.'); } diff --git a/src/Facades/Turbo.php b/src/Facades/Turbo.php index b4015d8..a975500 100644 --- a/src/Facades/Turbo.php +++ b/src/Facades/Turbo.php @@ -25,12 +25,12 @@ */ class Turbo extends Facade { - public static function usePartialsSubfolderPattern() + public static function usePartialsSubfolderPattern(): void { static::resolvePartialsPathUsing('{plural}.partials.{singular}'); } - public static function resolvePartialsPathUsing(string|Closure $pattern) + public static function resolvePartialsPathUsing(string|Closure $pattern): void { NamesResolver::resolvePartialsPathUsing($pattern); } diff --git a/src/Facades/TurboStream.php b/src/Facades/TurboStream.php index a63a6fa..431c5d1 100644 --- a/src/Facades/TurboStream.php +++ b/src/Facades/TurboStream.php @@ -32,7 +32,7 @@ protected static function getFacadeAccessor() public static function fake($callback = null) { - return tap(static::getFacadeRoot(), function ($fake) use ($callback) { + return tap(static::getFacadeRoot(), function ($fake) use ($callback): void { static::swap($fake->fake($callback)); }); } diff --git a/src/Features.php b/src/Features.php index 0873698..9fc879e 100644 --- a/src/Features.php +++ b/src/Features.php @@ -4,7 +4,7 @@ class Features { - public static function enabled(string $feature) + public static function enabled(string $feature): bool { return in_array($feature, config('turbo-laravel.features', [])); } diff --git a/src/Http/HotwireNativeRedirectResponse.php b/src/Http/HotwireNativeRedirectResponse.php index 385adf8..78dddd8 100644 --- a/src/Http/HotwireNativeRedirectResponse.php +++ b/src/Http/HotwireNativeRedirectResponse.php @@ -30,7 +30,7 @@ public function with($key, $value = null) $params = $this->getQueryString(); return $this->withoutQueryStrings() - ->setTargetUrl($this->getTargetUrl().'?'.http_build_query($params + [$key => urlencode($value)])); + ->setTargetUrl($this->getTargetUrl().'?'.http_build_query($params + [$key => urlencode((string) $value)])); } /** diff --git a/src/Http/Middleware/TurboMiddleware.php b/src/Http/Middleware/TurboMiddleware.php index 7044241..0a11c75 100644 --- a/src/Http/Middleware/TurboMiddleware.php +++ b/src/Http/Middleware/TurboMiddleware.php @@ -93,7 +93,7 @@ private function turboResponse($response, Request $request) if ($response->exception instanceof ValidationException && ($formRedirectUrl = $this->guessFormRedirectUrl($request, $response->exception->redirectTo))) { $response->setTargetUrl($formRedirectUrl); - return tap($this->handleRedirectInternally($request, $response), function () use ($request) { + return tap($this->handleRedirectInternally($request, $response), function () use ($request): void { App::instance('request', $request); Facade::clearResolvedInstance('request'); }); @@ -108,11 +108,10 @@ private function kernel(): Kernel } /** - * @param Request $request * @param Response $response * @return Response */ - private function handleRedirectInternally($request, $response) + private function handleRedirectInternally(\Illuminate\Http\Request $request, \Illuminate\Http\RedirectResponse $response) { $kernel = $this->kernel(); @@ -140,18 +139,14 @@ private function createRequestFrom(string $url, Request $baseRequest) } /** - * @param \Illuminate\Http\Request $request * @return bool */ - private function turboVisit($request) + private function turboVisit(\Illuminate\Http\Request $request) { return Str::contains($request->header('Accept', ''), Turbo::TURBO_STREAM_FORMAT); } - /** - * @param \Illuminate\Http\Request $request - */ - private function guessFormRedirectUrl($request, ?string $defaultRedirectUrl = null) + private function guessFormRedirectUrl(\Illuminate\Http\Request $request, ?string $defaultRedirectUrl = null) { if ($this->inExceptArray($request)) { return $defaultRedirectUrl; diff --git a/src/Http/MultiplePendingTurboStreamResponse.php b/src/Http/MultiplePendingTurboStreamResponse.php index cee2959..0788390 100644 --- a/src/Http/MultiplePendingTurboStreamResponse.php +++ b/src/Http/MultiplePendingTurboStreamResponse.php @@ -8,10 +8,10 @@ use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; -class MultiplePendingTurboStreamResponse implements Htmlable, Renderable, Responsable +class MultiplePendingTurboStreamResponse implements \Stringable, Htmlable, Renderable, Responsable { /** @var Collection|PendingTurboStreamResponse[] */ - private Collection $pendingStreams; + private readonly Collection $pendingStreams; /** * @param Collection $pendingStreams @@ -43,9 +43,7 @@ public function toResponse($request) public function render(): string { return $this->pendingStreams - ->map(function (PendingTurboStreamResponse $pendingStream) { - return $pendingStream->render(); - }) + ->map(fn (PendingTurboStreamResponse $pendingStream): string => $pendingStream->render()) ->implode(PHP_EOL); } diff --git a/src/Http/PendingTurboStreamResponse.php b/src/Http/PendingTurboStreamResponse.php index 980d8aa..50cf261 100644 --- a/src/Http/PendingTurboStreamResponse.php +++ b/src/Http/PendingTurboStreamResponse.php @@ -18,7 +18,7 @@ use function HotwiredLaravel\TurboLaravel\dom_id; -class PendingTurboStreamResponse implements Htmlable, Renderable, Responsable +class PendingTurboStreamResponse implements \Stringable, Htmlable, Renderable, Responsable { use Macroable; @@ -34,7 +34,7 @@ class PendingTurboStreamResponse implements Htmlable, Renderable, Responsable private array $partialData = []; - private $inlineContent = null; + private $inlineContent; private array $useCustomAttributes = []; @@ -261,7 +261,7 @@ public function refresh(): self ->attributes(array_filter(['request-id' => Turbo::currentRequestId()])); } - private function buildAction(string $action, Model|string|null $target = null, $content = null, ?Rendering $rendering = null, array $attributes = []) + private function buildAction(string $action, Model|string|null $target = null, $content = null, ?Rendering $rendering = null, array $attributes = []): static { $this->useAction = $action; $this->useTarget = $target instanceof Model ? $this->resolveTargetFor($target) : $target; @@ -273,7 +273,7 @@ private function buildAction(string $action, Model|string|null $target = null, $ return $this; } - private function buildActionAll(string $action, Model|string $targets, $content = null, array $attributes = []) + private function buildActionAll(string $action, Model|string $targets, $content = null, array $attributes = []): static { $this->useAction = $action; $this->useTarget = null; @@ -286,18 +286,18 @@ private function buildActionAll(string $action, Model|string $targets, $content public function broadcastTo($channel, ?callable $callback = null) { - $callback = $callback ?? function () {}; + $callback ??= function (): void {}; - return tap($this, function () use ($channel, $callback) { + return tap($this, function () use ($channel, $callback): void { $callback($this->asPendingBroadcast($channel)); }); } public function broadcastToPrivateChannel($channel, ?callable $callback = null) { - $callback = $callback ?? function () {}; + $callback ??= function (): void {}; - return $this->broadcastTo(null, function (PendingBroadcast $broadcast) use ($channel, $callback) { + return $this->broadcastTo(null, function (PendingBroadcast $broadcast) use ($channel, $callback): void { $broadcast->toPrivateChannel($channel); $callback($broadcast); }); @@ -305,9 +305,9 @@ public function broadcastToPrivateChannel($channel, ?callable $callback = null) public function broadcastToPresenceChannel($channel, ?callable $callback = null) { - $callback = $callback ?? function () {}; + $callback ??= function (): void {}; - return $this->broadcastTo(null, function (PendingBroadcast $broadcast) use ($channel, $callback) { + return $this->broadcastTo(null, function (PendingBroadcast $broadcast) use ($channel, $callback): void { $callback($broadcast->toPresenceChannel($channel)); }); } diff --git a/src/Jobs/BroadcastAction.php b/src/Jobs/BroadcastAction.php index 135f8f5..52e1bce 100644 --- a/src/Jobs/BroadcastAction.php +++ b/src/Jobs/BroadcastAction.php @@ -12,46 +12,14 @@ class BroadcastAction implements ShouldQueue use InteractsWithQueue; use SerializesModels; - public array $channels; + public function __construct(public array $channels, public string $action, public ?string $target = null, public ?string $targets = null, public ?string $partial = null, public ?array $partialData = [], public ?string $inlineContent = null, public bool $escapeInlineContent = true, public array $attributes = [], public ?string $socket = null) {} - public string $action; - - public ?string $target = null; - - public ?string $targets = null; - - public ?string $partial = null; - - public ?array $partialData = null; - - public ?string $inlineContent = null; - - public bool $escapeInlineContent = true; - - public array $attributes = []; - - public ?string $socket = null; - - public function __construct(array $channels, string $action, ?string $target = null, ?string $targets = null, ?string $partial = null, ?array $partialData = [], ?string $inlineContent = null, bool $escapeInlineContent = true, array $attributes = [], $socket = null) - { - $this->channels = $channels; - $this->action = $action; - $this->target = $target; - $this->targets = $targets; - $this->partial = $partial; - $this->partialData = $partialData; - $this->inlineContent = $inlineContent; - $this->escapeInlineContent = $escapeInlineContent; - $this->attributes = $attributes; - $this->socket = $socket; - } - - public function handle() + public function handle(): void { broadcast($this->asEvent()); } - public function asEvent() + public function asEvent(): \HotwiredLaravel\TurboLaravel\Events\TurboStreamBroadcast { $event = new TurboStreamBroadcast( $this->channels, diff --git a/src/Models/Broadcasts.php b/src/Models/Broadcasts.php index e523680..382d56b 100644 --- a/src/Models/Broadcasts.php +++ b/src/Models/Broadcasts.php @@ -19,7 +19,7 @@ trait Broadcasts { protected static $ignoreTurboStreamBroadcastsOn = []; - public static function bootBroadcasts() + public static function bootBroadcasts(): void { static::observe(new ModelObserver); } @@ -40,7 +40,7 @@ public static function withoutTurboStreamBroadcastsOn(array $models, callable $c } } - public static function isIgnoringTurboStreamBroadcasts($class = null) + public static function isIgnoringTurboStreamBroadcasts($class = null): bool { $class = $class ?: static::class; @@ -236,7 +236,7 @@ protected function broadcastDefaultStreamableForCurrentModel(bool $inserting) protected function toChannels(Collection $streamables): array { - return $streamables->filter()->map(function ($streamable) { + return $streamables->filter()->map(function ($streamable): \Illuminate\Broadcasting\Channel|\Illuminate\Broadcasting\PrivateChannel { if ($streamable instanceof Channel) { return $streamable; } diff --git a/src/Models/ModelObserver.php b/src/Models/ModelObserver.php index 4b1cd0d..4855095 100644 --- a/src/Models/ModelObserver.php +++ b/src/Models/ModelObserver.php @@ -21,7 +21,7 @@ public function __construct() /** * @param Model|Broadcasts $model */ - public function saved(Model $model) + public function saved(Model $model): void { if ($this->shouldBroadcastRefresh($model)) { $model->broadcastRefresh()->later(); @@ -39,7 +39,7 @@ public function saved(Model $model) /** * @param Model|Broadcasts $model */ - public function deleted(Model $model) + public function deleted(Model $model): void { if ($this->shouldBroadcastRefresh($model)) { $model->broadcastRefresh()->later(); @@ -56,11 +56,7 @@ private function shouldBroadcastRefresh(Model $model): bool return true; } - if (property_exists($model, 'broadcastsRefreshesTo')) { - return true; - } - - return false; + return property_exists($model, 'broadcastsRefreshesTo'); } private function shouldBroadcast(Model $model): bool diff --git a/src/Models/Naming/Name.php b/src/Models/Naming/Name.php index ced74a7..8a918de 100644 --- a/src/Models/Naming/Name.php +++ b/src/Models/Naming/Name.php @@ -49,7 +49,7 @@ public static function forModel(object $model) return static::$nameInstanceCache[$class] ??= static::build($class); } - public static function build(string $className) + public static function build(string $className): static { $name = new static; diff --git a/src/NamesResolver.php b/src/NamesResolver.php index cfb7dba..d777d47 100644 --- a/src/NamesResolver.php +++ b/src/NamesResolver.php @@ -11,7 +11,7 @@ class NamesResolver { protected static $partialsPathResolver = '{plural}._{singular}'; - public static function resolvePartialsPathUsing(string|Closure $resolver) + public static function resolvePartialsPathUsing(string|Closure $resolver): void { static::$partialsPathResolver = $resolver; } diff --git a/src/Testing/AssertableTurboStream.php b/src/Testing/AssertableTurboStream.php index 7268d03..5ed3e94 100644 --- a/src/Testing/AssertableTurboStream.php +++ b/src/Testing/AssertableTurboStream.php @@ -30,7 +30,7 @@ public function hasTurboStream(?Closure $callback = null): self $matches = $this->turboStreams ->mapInto(TurboStreamMatcher::class) - ->filter(function (TurboStreamMatcher $matcher) use ($callback, $attrs) { + ->filter(function (TurboStreamMatcher $matcher) use ($callback, $attrs): bool { $matcher = $callback($matcher); if (! $matcher->matches()) { diff --git a/src/Testing/TurboStreamMatcher.php b/src/Testing/TurboStreamMatcher.php index f7db265..4e1d49e 100644 --- a/src/Testing/TurboStreamMatcher.php +++ b/src/Testing/TurboStreamMatcher.php @@ -3,23 +3,16 @@ namespace HotwiredLaravel\TurboLaravel\Testing; use Closure; -use DOMElement; use Illuminate\View\ComponentAttributeBag; use PHPUnit\Framework\Assert; class TurboStreamMatcher { - /** @var \DOMElement */ - private $turboStream; - private array $wheres = []; private array $contents = []; - public function __construct(DOMElement $turboStream) - { - $this->turboStream = $turboStream; - } + public function __construct(private \DOMElement $turboStream) {} public function where(string $prop, string $value): self { @@ -53,7 +46,7 @@ public function matches(?Closure $callback = null): bool // `->assertTurboStream(fn)` call. This is where the `->where()` // and `->see()` methods will be called by the developers. - if ($callback) { + if ($callback instanceof \Closure) { return $callback($this)->matches(); } @@ -73,7 +66,7 @@ public function attrs(): string return $this->makeAttributes($this->wheres); } - private function matchesProps() + private function matchesProps(): bool { foreach ($this->wheres as $prop => $value) { $propValue = $this->turboStream->getAttribute($prop); @@ -86,9 +79,9 @@ private function matchesProps() return true; } - private function matchesContents() + private function matchesContents(): bool { - if (empty($this->contents)) { + if ($this->contents === []) { return true; } diff --git a/src/Turbo.php b/src/Turbo.php index b2abbf1..f93fee1 100644 --- a/src/Turbo.php +++ b/src/Turbo.php @@ -74,16 +74,18 @@ public function broadcastToOthers($toOthers = true) if (is_bool($toOthers)) { $this->broadcastToOthersOnly = $toOthers; - return; + return null; } $this->broadcastToOthersOnly = true; if ($toOthers instanceof Closure) { - return tap($toOthers(), function () { + return tap($toOthers(), function (): void { $this->broadcastToOthersOnly = false; }); } + + return null; } public function shouldBroadcastToOthers(): bool diff --git a/src/TurboServiceProvider.php b/src/TurboServiceProvider.php index 276c0be..85790ce 100644 --- a/src/TurboServiceProvider.php +++ b/src/TurboServiceProvider.php @@ -26,7 +26,7 @@ class TurboServiceProvider extends ServiceProvider { - public function boot() + public function boot(): void { $this->configurePublications(); $this->configureRoutes(); @@ -40,7 +40,7 @@ public function boot() $this->configureMiddleware(); } - public function register() + public function register(): void { $this->mergeConfigFrom(__DIR__.'/../config/turbo-laravel.php', 'turbo-laravel'); @@ -49,14 +49,14 @@ public function register() $this->app->scoped(Limiter::class); } - private function configureComponents() + private function configureComponents(): void { - $this->callAfterResolving('blade.compiler', function (BladeCompiler $blade) { + $this->callAfterResolving('blade.compiler', function (BladeCompiler $blade): void { $blade->anonymousComponentPath(__DIR__.'/../resources/views/components', 'turbo'); }); } - private function configurePublications() + private function configurePublications(): void { if (! $this->app->runningInConsole()) { return; @@ -88,60 +88,34 @@ private function configureRoutes(): void private function configureMacros(): void { - Blade::if('turbonative', function () { - return TurboFacade::isHotwireNativeVisit(); - }); + Blade::if('turbonative', fn () => TurboFacade::isHotwireNativeVisit()); - Blade::if('unlessturbonative', function () { - return ! TurboFacade::isHotwireNativeVisit(); - }); + Blade::if('unlessturbonative', fn (): bool => ! TurboFacade::isHotwireNativeVisit()); - Blade::if('hotwirenative', function () { - return TurboFacade::isHotwireNativeVisit(); - }); + Blade::if('hotwirenative', fn () => TurboFacade::isHotwireNativeVisit()); - Blade::if('unlesshotwirenative', function () { - return ! TurboFacade::isHotwireNativeVisit(); - }); + Blade::if('unlesshotwirenative', fn (): bool => ! TurboFacade::isHotwireNativeVisit()); - Blade::directive('domid', function ($expression) { - return ""; - }); + Blade::directive('domid', fn ($expression): string => ""); - Blade::directive('domclass', function ($expression) { - return ""; - }); + Blade::directive('domclass', fn ($expression): string => ""); - Blade::directive('channel', function ($expression) { - return "broadcastChannel(); ?>"; - }); + Blade::directive('channel', fn ($expression): string => "broadcastChannel(); ?>"); } private function configureRequestAndResponseMacros(): void { - ResponseFacade::macro('turboStream', function ($model = null, ?string $action = null): MultiplePendingTurboStreamResponse|PendingTurboStreamResponse { - return turbo_stream($model, $action); - }); + ResponseFacade::macro('turboStream', fn ($model = null, ?string $action = null): MultiplePendingTurboStreamResponse|PendingTurboStreamResponse => turbo_stream($model, $action)); - ResponseFacade::macro('turboStreamView', function ($view, array $data = []): Response|ResponseFactory { - return turbo_stream_view($view, $data); - }); + ResponseFacade::macro('turboStreamView', fn ($view, array $data = []): Response|ResponseFactory => turbo_stream_view($view, $data)); - Request::macro('wantsTurboStream', function (): bool { - return Str::contains($this->header('Accept'), Turbo::TURBO_STREAM_FORMAT); - }); + Request::macro('wantsTurboStream', fn (): bool => Str::contains($this->header('Accept'), Turbo::TURBO_STREAM_FORMAT)); - Request::macro('wantsTurboStreams', function (): bool { - return $this->wantsTurboStream(); - }); + Request::macro('wantsTurboStreams', fn (): bool => $this->wantsTurboStream()); - Request::macro('wasFromTurboNative', function (): bool { - return TurboFacade::isHotwireNativeVisit(); - }); + Request::macro('wasFromTurboNative', fn (): bool => TurboFacade::isHotwireNativeVisit()); - Request::macro('wasFromHotwireNative', function (): bool { - return TurboFacade::isHotwireNativeVisit(); - }); + Request::macro('wasFromHotwireNative', fn (): bool => TurboFacade::isHotwireNativeVisit()); Request::macro('wasFromTurboFrame', function (?string $frame = null): bool { if (! $frame) { @@ -152,13 +126,13 @@ private function configureRequestAndResponseMacros(): void }); } - private function configureTestResponseMacros() + private function configureTestResponseMacros(): void { if (! app()->environment('testing')) { return; } - TestResponse::macro('assertTurboStream', function (?callable $callback = null) { + TestResponse::macro('assertTurboStream', function (?callable $callback = null): void { Assert::assertStringContainsString( Turbo::TURBO_STREAM_FORMAT, $this->headers->get('Content-Type'), @@ -172,22 +146,22 @@ private function configureTestResponseMacros() $callback(new AssertableTurboStream($turboStreams)); }); - TestResponse::macro('assertNotTurboStream', function () { + TestResponse::macro('assertNotTurboStream', function (): void { Assert::assertStringNotContainsString( Turbo::TURBO_STREAM_FORMAT, $this->headers->get('Content-Type'), ); }); - TestResponse::macro('assertRedirectRecede', function (array $with = []) { + TestResponse::macro('assertRedirectRecede', function (array $with = []): void { $this->assertRedirectToRoute('turbo_recede_historical_location', $with); }); - TestResponse::macro('assertRedirectResume', function (array $with = []) { + TestResponse::macro('assertRedirectResume', function (array $with = []): void { $this->assertRedirectToRoute('turbo_resume_historical_location', $with); }); - TestResponse::macro('assertRedirectRefresh', function (array $with = []) { + TestResponse::macro('assertRedirectRefresh', function (array $with = []): void { $this->assertRedirectToRoute('turbo_refresh_historical_location', $with); }); } diff --git a/src/Views/RecordIdentifier.php b/src/Views/RecordIdentifier.php index 6444d14..6266a59 100644 --- a/src/Views/RecordIdentifier.php +++ b/src/Views/RecordIdentifier.php @@ -12,7 +12,7 @@ class RecordIdentifier const DELIMITER = '_'; /** @var Model */ - private $record; + private readonly object $record; public function __construct(object $record) { diff --git a/src/Views/UnidentifiableRecordException.php b/src/Views/UnidentifiableRecordException.php index 6c64748..889506a 100644 --- a/src/Views/UnidentifiableRecordException.php +++ b/src/Views/UnidentifiableRecordException.php @@ -9,7 +9,7 @@ class UnidentifiableRecordException extends RuntimeException public static function missingGetKeyMethod(object $model): self { return new self( - sprintf('[%s] must implement a getKey() method.', get_class($model)) + sprintf('[%s] must implement a getKey() method.', $model::class) ); } } diff --git a/tests/Broadcasting/LimiterTest.php b/tests/Broadcasting/LimiterTest.php index 6a67b47..0ecea6e 100644 --- a/tests/Broadcasting/LimiterTest.php +++ b/tests/Broadcasting/LimiterTest.php @@ -7,8 +7,8 @@ class LimiterTest extends TestCase { - /** @test */ - public function debounces() + #[\PHPUnit\Framework\Attributes\Test] + public function debounces(): void { $this->freezeTime(); diff --git a/tests/Events/TurboStreamBroadcastTest.php b/tests/Events/TurboStreamBroadcastTest.php index 5ef22c5..855f12e 100644 --- a/tests/Events/TurboStreamBroadcastTest.php +++ b/tests/Events/TurboStreamBroadcastTest.php @@ -9,8 +9,8 @@ class TurboStreamBroadcastTest extends TestCase { - /** @test */ - public function renders_turbo_stream() + #[\PHPUnit\Framework\Attributes\Test] + public function renders_turbo_stream(): void { $article = ArticleFactory::new()->create()->fresh(); @@ -35,8 +35,8 @@ public function renders_turbo_stream() $this->assertEquals(trim($expected), trim($event->render())); } - /** @test */ - public function renders_turbo_stream_targets() + #[\PHPUnit\Framework\Attributes\Test] + public function renders_turbo_stream_targets(): void { $article = ArticleFactory::new()->create()->fresh(); diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 5c53ccf..00f571d 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -25,8 +25,8 @@ protected function setUp(): void $this->article = Article::create(['title' => 'Hello World']); } - /** @test */ - public function namespaced_turbo_stream_fn() + #[\PHPUnit\Framework\Attributes\Test] + public function namespaced_turbo_stream_fn(): void { $this->assertEquals( trim(<<<'HTML' @@ -93,8 +93,8 @@ public function namespaced_turbo_stream_fn() ); } - /** @test */ - public function global_turbo_stream_fn() + #[\PHPUnit\Framework\Attributes\Test] + public function global_turbo_stream_fn(): void { $this->assertEquals( trim(<<<'HTML' @@ -161,8 +161,8 @@ public function global_turbo_stream_fn() ); } - /** @test */ - public function namespace_turbo_stream_htmlable() + #[\PHPUnit\Framework\Attributes\Test] + public function namespace_turbo_stream_htmlable(): void { $this->assertEquals( trim(<<<'HTML' @@ -192,8 +192,8 @@ public function namespace_turbo_stream_htmlable() ); } - /** @test */ - public function global_turbo_stream_htmlable() + #[\PHPUnit\Framework\Attributes\Test] + public function global_turbo_stream_htmlable(): void { $this->assertEquals( trim(<<<'HTML' @@ -223,32 +223,32 @@ public function global_turbo_stream_htmlable() ); } - /** @test */ - public function namespaced_dom_id_fn() + #[\PHPUnit\Framework\Attributes\Test] + public function namespaced_dom_id_fn(): void { $this->assertEquals("article_{$this->article->id}", dom_id($this->article)); } - /** @test */ - public function global_dom_id_fn() + #[\PHPUnit\Framework\Attributes\Test] + public function global_dom_id_fn(): void { $this->assertEquals("article_{$this->article->id}", \dom_id($this->article)); } - /** @test */ - public function namespaced_dom_class_fn() + #[\PHPUnit\Framework\Attributes\Test] + public function namespaced_dom_class_fn(): void { $this->assertEquals('article', dom_class($this->article)); } - /** @test */ - public function global_dom_class_fn() + #[\PHPUnit\Framework\Attributes\Test] + public function global_dom_class_fn(): void { $this->assertEquals('article', \dom_class($this->article)); } - /** @test */ - public function namespaced_turbo_stream_view_fn() + #[\PHPUnit\Framework\Attributes\Test] + public function namespaced_turbo_stream_view_fn(): void { $response = turbo_stream_view('functions.turbo_stream_view', [ 'title' => 'Post Using Namespaced Function', @@ -261,8 +261,8 @@ public function namespaced_turbo_stream_view_fn() ); } - /** @test */ - public function global_turbo_stream_view_fn() + #[\PHPUnit\Framework\Attributes\Test] + public function global_turbo_stream_view_fn(): void { $response = \turbo_stream_view('functions.turbo_stream_view', [ 'title' => 'Post Global', diff --git a/tests/Http/HotwireNativeNavigationControllerTest.php b/tests/Http/HotwireNativeNavigationControllerTest.php index c829d68..b018738 100644 --- a/tests/Http/HotwireNativeNavigationControllerTest.php +++ b/tests/Http/HotwireNativeNavigationControllerTest.php @@ -9,7 +9,7 @@ class HotwireNativeNavigationControllerTest extends TestCase { use InteractsWithTurbo; - public static function actionsDataProvider() + public static function actionsDataProvider(): array { return [ ['recede'], @@ -18,12 +18,9 @@ public static function actionsDataProvider() ]; } - /** - * @test - * - * @dataProvider actionsDataProvider - */ - public function recede_resume_or_refresh_when_native_or_redirect_when_not_without_flash(string $action) + #[\PHPUnit\Framework\Attributes\Test] + #[\PHPUnit\Framework\Attributes\DataProvider('actionsDataProvider')] + public function recede_resume_or_refresh_when_native_or_redirect_when_not_without_flash(string $action): void { $this->post(route('trays.store'), ['return_to' => "{$action}_or_redirect"]) ->assertRedirect(route('trays.show', 1)); @@ -35,12 +32,9 @@ public function recede_resume_or_refresh_when_native_or_redirect_when_not_withou ->assertRedirect(route("turbo_{$action}_historical_location")); } - /** - * @test - * - * @dataProvider actionsDataProvider - */ - public function recede_resume_or_refresh_when_native_or_redirect_when_not_with_flash(string $action) + #[\PHPUnit\Framework\Attributes\Test] + #[\PHPUnit\Framework\Attributes\DataProvider('actionsDataProvider')] + public function recede_resume_or_refresh_when_native_or_redirect_when_not_with_flash(string $action): void { // Non-Turbo Native redirect with only flash... $this->post(route('trays.store'), ['return_to' => "{$action}_or_redirect", 'with' => true]) @@ -94,12 +88,9 @@ public function recede_resume_or_refresh_when_native_or_redirect_when_not_with_f ->assertSessionMissing('status'); } - /** - * @test - * - * @dataProvider actionsDataProvider - */ - public function recede_resume_or_refresh_when_native_or_redirect_back(string $action) + #[\PHPUnit\Framework\Attributes\Test] + #[\PHPUnit\Framework\Attributes\DataProvider('actionsDataProvider')] + public function recede_resume_or_refresh_when_native_or_redirect_back(string $action): void { $this->post(route('trays.store'), ['return_to' => "{$action}_or_redirect_back"]) ->assertRedirect(route('trays.show', 5)); @@ -114,8 +105,8 @@ public function recede_resume_or_refresh_when_native_or_redirect_back(string $ac ->assertRedirect(route("turbo_{$action}_historical_location")); } - /** @test */ - public function historical_location_url_responds_with_html() + #[\PHPUnit\Framework\Attributes\Test] + public function historical_location_url_responds_with_html(): void { $this->get(route('turbo_recede_historical_location')) ->assertOk() diff --git a/tests/Http/MacroablePendingStreamTest.php b/tests/Http/MacroablePendingStreamTest.php index e6d95a3..e00a30b 100644 --- a/tests/Http/MacroablePendingStreamTest.php +++ b/tests/Http/MacroablePendingStreamTest.php @@ -12,20 +12,20 @@ class MacroablePendingStreamTest extends TestCase { use InteractsWithTurbo; - /** @test */ - public function turbo_stream_can_be_macroable() + #[\PHPUnit\Framework\Attributes\Test] + public function turbo_stream_can_be_macroable(): void { $article = ArticleFactory::new()->create(); $this->turbo() ->put(route('articles.update', $article), ['title' => 'Title Updated']) - ->assertTurboStream(fn (AssertableTurboStream $streams) => ( - $streams->hasTurboStream(fn (TurboStreamMatcher $stream) => ( + ->assertTurboStream(fn (AssertableTurboStream $streams): true => ( + $streams->hasTurboStream(fn (TurboStreamMatcher $stream): \HotwiredLaravel\TurboLaravel\Testing\TurboStreamMatcher => ( $stream->where('action', 'replace') ->where('target', 'article_'.$article->id) ->see('Title Updated') )) - && $streams->hasTurboStream(fn (TurboStreamMatcher $stream) => ( + && $streams->hasTurboStream(fn (TurboStreamMatcher $stream): \HotwiredLaravel\TurboLaravel\Testing\TurboStreamMatcher => ( $stream->where('action', 'append') ->where('target', 'notifications') ->see('Article updated.') diff --git a/tests/Http/Middleware/TurboMiddlewareTest.php b/tests/Http/Middleware/TurboMiddlewareTest.php index fe4d38a..5f1f135 100644 --- a/tests/Http/Middleware/TurboMiddlewareTest.php +++ b/tests/Http/Middleware/TurboMiddlewareTest.php @@ -11,8 +11,8 @@ class TurboMiddlewareTest extends TestCase { - /** @test */ - public function doesnt_change_redirect_response_when_not_turbo_visit() + #[\PHPUnit\Framework\Attributes\Test] + public function doesnt_change_redirect_response_when_not_turbo_visit(): void { $this->from('/articles') ->post('/articles', []) @@ -20,8 +20,8 @@ public function doesnt_change_redirect_response_when_not_turbo_visit() ->assertStatus(302); } - /** @test */ - public function handles_invalid_forms_with_an_internal_redirect() + #[\PHPUnit\Framework\Attributes\Test] + public function handles_invalid_forms_with_an_internal_redirect(): void { $this->from('/articles') ->post('/articles', headers: [ @@ -32,8 +32,8 @@ public function handles_invalid_forms_with_an_internal_redirect() ->assertStatus(422); } - /** @test */ - public function handles_invalid_forms_with_an_internal_redirect_when_using_form_requests() + #[\PHPUnit\Framework\Attributes\Test] + public function handles_invalid_forms_with_an_internal_redirect_when_using_form_requests(): void { $article = Article::create(['title' => 'Hello World']); @@ -47,8 +47,8 @@ public function handles_invalid_forms_with_an_internal_redirect_when_using_form_ ->assertStatus(422); } - /** @test */ - public function can_detect_hotwire_native_visits() + #[\PHPUnit\Framework\Attributes\Test] + public function can_detect_hotwire_native_visits(): void { ArticleFactory::new()->times(3)->create(); @@ -89,8 +89,8 @@ public function can_detect_hotwire_native_visits() ); } - /** @test */ - public function uses_the_redirect_to_when_guessed_route_doesnt_exist() + #[\PHPUnit\Framework\Attributes\Test] + public function uses_the_redirect_to_when_guessed_route_doesnt_exist(): void { $comment = CommentFactory::new()->create(); @@ -104,8 +104,8 @@ public function uses_the_redirect_to_when_guessed_route_doesnt_exist() ->assertUnprocessable(); } - /** @test */ - public function can_prevent_redirect_route() + #[\PHPUnit\Framework\Attributes\Test] + public function can_prevent_redirect_route(): void { config()->set('turbo-laravel.redirect_guessing_exceptions', [ '/articles*', @@ -118,8 +118,8 @@ public function can_prevent_redirect_route() ->assertRedirectToRoute('articles.index'); } - /** @test */ - public function sends_an_internal_redirect_to_resource_create_routes_on_failed_validation_follows_laravel_conventions_and_returns_422_status_code() + #[\PHPUnit\Framework\Attributes\Test] + public function sends_an_internal_redirect_to_resource_create_routes_on_failed_validation_follows_laravel_conventions_and_returns_422_status_code(): void { $this ->from(route('articles.index')) @@ -131,8 +131,8 @@ public function sends_an_internal_redirect_to_resource_create_routes_on_failed_v ->assertUnprocessable(); } - /** @test */ - public function redirects_back_to_resource_edit_routes_on_failed_validation_follows_laravel_conventions() + #[\PHPUnit\Framework\Attributes\Test] + public function redirects_back_to_resource_edit_routes_on_failed_validation_follows_laravel_conventions(): void { $article = ArticleFactory::new()->create(); @@ -145,8 +145,8 @@ public function redirects_back_to_resource_edit_routes_on_failed_validation_foll ->assertUnprocessable(); } - /** @test */ - public function redirects_include_query_params() + #[\PHPUnit\Framework\Attributes\Test] + public function redirects_include_query_params(): void { $article = ArticleFactory::new()->create(); @@ -160,8 +160,8 @@ public function redirects_include_query_params() ->assertUnprocessable(); } - /** @test */ - public function only_guess_route_on_resource_routes() + #[\PHPUnit\Framework\Attributes\Test] + public function only_guess_route_on_resource_routes(): void { $this->from(route('login')) ->post(route('login.store'), headers: [ @@ -171,8 +171,8 @@ public function only_guess_route_on_resource_routes() ->assertStatus(303); } - /** @test */ - public function passes_the_request_cookies_to_the_internal_request() + #[\PHPUnit\Framework\Attributes\Test] + public function passes_the_request_cookies_to_the_internal_request(): void { $article = ArticleFactory::new()->create(); @@ -187,8 +187,8 @@ public function passes_the_request_cookies_to_the_internal_request() ->assertUnprocessable(); } - /** @test */ - public function sets_turbo_tracking_request_id() + #[\PHPUnit\Framework\Attributes\Test] + public function sets_turbo_tracking_request_id(): void { $this->get('request-id') ->assertJson(['turbo_request_id' => null]); diff --git a/tests/Http/RequestMacrosTest.php b/tests/Http/RequestMacrosTest.php index abaabc8..7d0716d 100644 --- a/tests/Http/RequestMacrosTest.php +++ b/tests/Http/RequestMacrosTest.php @@ -9,8 +9,8 @@ class RequestMacrosTest extends TestCase { - /** @test */ - public function wants_turbo_stream() + #[\PHPUnit\Framework\Attributes\Test] + public function wants_turbo_stream(): void { $request = Request::create('/hello'); $this->assertFalse($request->wantsTurboStream(), 'Expected request to not want a turbo stream response, but it did.'); @@ -24,8 +24,8 @@ public function wants_turbo_stream() $this->assertTrue($request->wantsTurboStreams(), 'Expected request to want a turbo stream response, but it did not.'); } - /** @test */ - public function was_from_turbo_native() + #[\PHPUnit\Framework\Attributes\Test] + public function was_from_turbo_native(): void { $request = Request::create('/hello'); $this->assertFalse($request->wasFromTurboNative()); @@ -34,8 +34,8 @@ public function was_from_turbo_native() $this->assertTrue($request->wasFromTurboNative()); } - /** @test */ - public function was_from_hotwire_native() + #[\PHPUnit\Framework\Attributes\Test] + public function was_from_hotwire_native(): void { $request = Request::create('/hello'); $this->assertFalse($request->wasFromHotwireNative()); @@ -44,8 +44,8 @@ public function was_from_hotwire_native() $this->assertTrue($request->wasFromHotwireNative()); } - /** @test */ - public function was_from_turbo_frame() + #[\PHPUnit\Framework\Attributes\Test] + public function was_from_turbo_frame(): void { $request = Request::create('/hello', server: [ 'HTTP_Turbo-Frame' => 'testing', diff --git a/tests/Http/ResponseMacrosTest.php b/tests/Http/ResponseMacrosTest.php index 7219b6a..51fef67 100644 --- a/tests/Http/ResponseMacrosTest.php +++ b/tests/Http/ResponseMacrosTest.php @@ -21,8 +21,8 @@ class ResponseMacrosTest extends TestCase { - /** @test */ - public function streams_model_on_create() + #[\PHPUnit\Framework\Attributes\Test] + public function streams_model_on_create(): void { $article = ArticleFactory::new()->create(); @@ -35,16 +35,14 @@ public function streams_model_on_create() $resp = response()->turboStream($article)->toResponse(new Request); - $this->assertEquals(trim($expected), trim($resp->getContent())); + $this->assertEquals(trim($expected), trim((string) $resp->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $resp->headers->get('Content-Type')); } - /** @test */ - public function streams_broadcastable_models_for_create() + #[\PHPUnit\Framework\Attributes\Test] + public function streams_broadcastable_models_for_create(): void { - $comment = Comment::withoutEvents(function () { - return CommentFactory::new()->create(); - }); + $comment = Comment::withoutEvents(fn () => CommentFactory::new()->create()); $expected = view('turbo-laravel::turbo-stream', [ 'action' => 'append', @@ -55,16 +53,14 @@ public function streams_broadcastable_models_for_create() $resp = response()->turboStream($comment)->toResponse(new Request); - $this->assertEquals(trim($expected), trim($resp->getContent())); + $this->assertEquals(trim($expected), trim((string) $resp->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $resp->headers->get('Content-Type')); } - /** @test */ - public function streams_model_on_update() + #[\PHPUnit\Framework\Attributes\Test] + public function streams_model_on_update(): void { - $userProfile = Profile::withoutEvents(function () { - return ProfileFactory::new()->create()->fresh(); - }); + $userProfile = Profile::withoutEvents(fn () => ProfileFactory::new()->create()->fresh()); $expected = view('turbo-laravel::turbo-stream', [ 'action' => 'replace', @@ -75,16 +71,14 @@ public function streams_model_on_update() $resp = response()->turboStream($userProfile)->toResponse(new Request); - $this->assertEquals(trim($expected), trim($resp->getContent())); + $this->assertEquals(trim($expected), trim((string) $resp->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $resp->headers->get('Content-Type')); } - /** @test */ - public function streams_broadcastable_models_for_update() + #[\PHPUnit\Framework\Attributes\Test] + public function streams_broadcastable_models_for_update(): void { - $comment = Comment::withoutEvents(function () { - return CommentFactory::new()->create()->fresh(); - }); + $comment = Comment::withoutEvents(fn () => CommentFactory::new()->create()->fresh()); $expected = view('turbo-laravel::turbo-stream', [ 'action' => 'replace', @@ -95,16 +89,14 @@ public function streams_broadcastable_models_for_update() $resp = response()->turboStream($comment)->toResponse(new Request); - $this->assertEquals(trim($expected), trim($resp->getContent())); + $this->assertEquals(trim($expected), trim((string) $resp->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $resp->headers->get('Content-Type')); } - /** @test */ - public function streams_model_on_delete() + #[\PHPUnit\Framework\Attributes\Test] + public function streams_model_on_delete(): void { - $article = Article::withoutEvents(function () { - return tap(ArticleFactory::new()->create()->fresh())->delete(); - }); + $article = Article::withoutEvents(fn () => tap(ArticleFactory::new()->create()->fresh())->delete()); $expected = view('turbo-laravel::turbo-stream', [ 'action' => 'remove', @@ -113,16 +105,14 @@ public function streams_model_on_delete() $resp = response()->turboStream($article)->toResponse(new Request); - $this->assertEquals(trim($expected), trim($resp->getContent())); + $this->assertEquals(trim($expected), trim((string) $resp->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $resp->headers->get('Content-Type')); } - /** @test */ - public function streams_model_on_soft_delete() + #[\PHPUnit\Framework\Attributes\Test] + public function streams_model_on_soft_delete(): void { - $userProfile = Profile::withoutEvents(function () { - return tap(ProfileFactory::new()->create()->fresh())->delete(); - }); + $userProfile = Profile::withoutEvents(fn () => tap(ProfileFactory::new()->create()->fresh())->delete()); $expected = view('turbo-laravel::turbo-stream', [ 'action' => 'remove', @@ -131,16 +121,14 @@ public function streams_model_on_soft_delete() $resp = response()->turboStream($userProfile)->toResponse(new Request); - $this->assertEquals(trim($expected), trim($resp->getContent())); + $this->assertEquals(trim($expected), trim((string) $resp->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $resp->headers->get('Content-Type')); } - /** @test */ - public function streams_broadcastable_models_for_deleted() + #[\PHPUnit\Framework\Attributes\Test] + public function streams_broadcastable_models_for_deleted(): void { - $comment = Comment::withoutEvents(function () { - return tap(CommentFactory::new()->create()->fresh())->delete(); - }); + $comment = Comment::withoutEvents(fn () => tap(CommentFactory::new()->create()->fresh())->delete()); $expected = view('turbo-laravel::turbo-stream', [ 'action' => 'remove', @@ -149,12 +137,12 @@ public function streams_broadcastable_models_for_deleted() $resp = response()->turboStream($comment)->toResponse(new Request); - $this->assertEquals(trim($expected), trim($resp->getContent())); + $this->assertEquals(trim($expected), trim((string) $resp->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $resp->headers->get('Content-Type')); } - /** @test */ - public function streams_custom_view() + #[\PHPUnit\Framework\Attributes\Test] + public function streams_custom_view(): void { $article = ArticleFactory::new()->create(); @@ -166,12 +154,12 @@ public function streams_custom_view() 'article' => $article, ]); - $this->assertEquals($expected, trim($resp->getContent())); + $this->assertEquals($expected, trim((string) $resp->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $resp->headers->get('Content-Type')); } - /** @test */ - public function can_manually_build_turbo_stream_response() + #[\PHPUnit\Framework\Attributes\Test] + public function can_manually_build_turbo_stream_response(): void { $builder = response()->turboStream(); @@ -179,8 +167,8 @@ public function can_manually_build_turbo_stream_response() $this->assertInstanceOf(Responsable::class, $builder); } - /** @test */ - public function can_configure_manually_turbo_stream_rendering() + #[\PHPUnit\Framework\Attributes\Test] + public function can_configure_manually_turbo_stream_rendering(): void { $response = response() ->turboStream() @@ -198,12 +186,12 @@ public function can_configure_manually_turbo_stream_rendering() 'partialData' => $partialData, ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function can_use_view_instead_of_partial() + #[\PHPUnit\Framework\Attributes\Test] + public function can_use_view_instead_of_partial(): void { $response = response() ->turboStream() @@ -221,12 +209,12 @@ public function can_use_view_instead_of_partial() 'partialData' => $partialData, ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function append_shorthand_for_response_builder() + #[\PHPUnit\Framework\Attributes\Test] + public function append_shorthand_for_response_builder(): void { $response = response() ->turboStream() @@ -240,12 +228,12 @@ public function append_shorthand_for_response_builder() 'partialData' => ['article' => $article], ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function append_shorthand_passing_string() + #[\PHPUnit\Framework\Attributes\Test] + public function append_shorthand_passing_string(): void { $response = response() ->turboStream() @@ -258,12 +246,12 @@ public function append_shorthand_passing_string() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function append_shorthand_passing_html_string() + #[\PHPUnit\Framework\Attributes\Test] + public function append_shorthand_passing_html_string(): void { $response = response() ->turboStream() @@ -276,12 +264,12 @@ public function append_shorthand_passing_html_string() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function append_shorthand_passing_string_with_view_partial() + #[\PHPUnit\Framework\Attributes\Test] + public function append_shorthand_passing_string_with_view_partial(): void { $article = ArticleFactory::new()->create(); @@ -298,12 +286,12 @@ public function append_shorthand_passing_string_with_view_partial() 'partialData' => ['article' => $article], ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function append_shorthand_passing_as_string_and_view_as_content() + #[\PHPUnit\Framework\Attributes\Test] + public function append_shorthand_passing_as_string_and_view_as_content(): void { $response = response() ->turboStream() @@ -316,12 +304,12 @@ public function append_shorthand_passing_as_string_and_view_as_content() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function append_all_with_inline_content_string() + #[\PHPUnit\Framework\Attributes\Test] + public function append_all_with_inline_content_string(): void { $response = response() ->turboStream() @@ -334,30 +322,30 @@ public function append_all_with_inline_content_string() 'content' => 'Some inline content', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function append_all_passing_html_safe_string() + #[\PHPUnit\Framework\Attributes\Test] + public function append_all_passing_html_safe_string(): void { $response = response() ->turboStream() ->appendAll('.test_models', new HtmlString('
Some safe HTML content
')) ->toResponse(new Request); - $expected = <<<'HTML' + $expected = <<<'HTML_WRAP' - HTML; + HTML_WRAP; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function append_all_passing_view_as_content() + #[\PHPUnit\Framework\Attributes\Test] + public function append_all_passing_view_as_content(): void { $response = response() ->turboStream() @@ -370,12 +358,12 @@ public function append_all_passing_view_as_content() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function prepend_shorthand_for_response_builder() + #[\PHPUnit\Framework\Attributes\Test] + public function prepend_shorthand_for_response_builder(): void { $response = response() ->turboStream() @@ -389,12 +377,12 @@ public function prepend_shorthand_for_response_builder() 'partialData' => ['article' => $article], ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function prepend_shorthand_as_string() + #[\PHPUnit\Framework\Attributes\Test] + public function prepend_shorthand_as_string(): void { $response = response() ->turboStream() @@ -407,12 +395,12 @@ public function prepend_shorthand_as_string() 'content' => 'Hello World', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function prepend_all_with_inline_content_string() + #[\PHPUnit\Framework\Attributes\Test] + public function prepend_all_with_inline_content_string(): void { $response = response() ->turboStream() @@ -425,30 +413,30 @@ public function prepend_all_with_inline_content_string() 'content' => 'Some inline content', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function prepend_all_passing_html_safe_string() + #[\PHPUnit\Framework\Attributes\Test] + public function prepend_all_passing_html_safe_string(): void { $response = response() ->turboStream() ->prependAll('.test_models', new HtmlString('
Some safe HTML content
')) ->toResponse(new Request); - $expected = <<<'HTML' + $expected = <<<'HTML_WRAP' - HTML; + HTML_WRAP; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function prepend_all_passing_view_as_content() + #[\PHPUnit\Framework\Attributes\Test] + public function prepend_all_passing_view_as_content(): void { $response = response() ->turboStream() @@ -461,12 +449,12 @@ public function prepend_all_passing_view_as_content() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function update_shorthand_for_response_builder() + #[\PHPUnit\Framework\Attributes\Test] + public function update_shorthand_for_response_builder(): void { $response = response() ->turboStream() @@ -480,12 +468,12 @@ public function update_shorthand_for_response_builder() 'partialData' => ['article' => $article], ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function update_shorthand_as_string() + #[\PHPUnit\Framework\Attributes\Test] + public function update_shorthand_as_string(): void { $response = response() ->turboStream() @@ -498,12 +486,12 @@ public function update_shorthand_as_string() 'content' => 'Hello World', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function update_all_with_inline_content_string() + #[\PHPUnit\Framework\Attributes\Test] + public function update_all_with_inline_content_string(): void { $response = response() ->turboStream() @@ -516,30 +504,30 @@ public function update_all_with_inline_content_string() 'content' => 'Some inline content', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function update_all_passing_html_safe_string() + #[\PHPUnit\Framework\Attributes\Test] + public function update_all_passing_html_safe_string(): void { $response = response() ->turboStream() ->updateAll('.test_models', new HtmlString('
Some safe HTML content
')) ->toResponse(new Request); - $expected = <<<'HTML' + $expected = <<<'HTML_WRAP' - HTML; + HTML_WRAP; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function update_all_passing_view_as_content() + #[\PHPUnit\Framework\Attributes\Test] + public function update_all_passing_view_as_content(): void { $response = response() ->turboStream() @@ -552,12 +540,12 @@ public function update_all_passing_view_as_content() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function replace_shorthand_for_response_builder() + #[\PHPUnit\Framework\Attributes\Test] + public function replace_shorthand_for_response_builder(): void { $response = response() ->turboStream() @@ -571,12 +559,12 @@ public function replace_shorthand_for_response_builder() 'partialData' => ['article' => $article], ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function replace_shorthand_as_string() + #[\PHPUnit\Framework\Attributes\Test] + public function replace_shorthand_as_string(): void { $response = response() ->turboStream() @@ -589,12 +577,12 @@ public function replace_shorthand_as_string() 'content' => 'Hello World', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function replace_all_with_inline_content_string() + #[\PHPUnit\Framework\Attributes\Test] + public function replace_all_with_inline_content_string(): void { $response = response() ->turboStream() @@ -607,30 +595,30 @@ public function replace_all_with_inline_content_string() 'content' => 'Some inline content', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function replace_all_passing_html_safe_string() + #[\PHPUnit\Framework\Attributes\Test] + public function replace_all_passing_html_safe_string(): void { $response = response() ->turboStream() ->replaceAll('.test_models', new HtmlString('
Some safe HTML content
')) ->toResponse(new Request); - $expected = <<<'HTML' + $expected = <<<'HTML_WRAP' - HTML; + HTML_WRAP; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function replace_all_passing_view_as_content() + #[\PHPUnit\Framework\Attributes\Test] + public function replace_all_passing_view_as_content(): void { $response = response() ->turboStream() @@ -643,12 +631,12 @@ public function replace_all_passing_view_as_content() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function remove_shorthand_for_response_builder() + #[\PHPUnit\Framework\Attributes\Test] + public function remove_shorthand_for_response_builder(): void { $response = response() ->turboStream() @@ -660,12 +648,12 @@ public function remove_shorthand_for_response_builder() 'target' => dom_id($article), ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function remove_shorthand_as_string() + #[\PHPUnit\Framework\Attributes\Test] + public function remove_shorthand_as_string(): void { $response = response() ->turboStream() @@ -677,12 +665,12 @@ public function remove_shorthand_as_string() 'target' => 'test_models_target', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function remove_shorthand_accepts_string() + #[\PHPUnit\Framework\Attributes\Test] + public function remove_shorthand_accepts_string(): void { $response = response() ->turboStream() @@ -694,12 +682,12 @@ public function remove_shorthand_accepts_string() 'target' => 'target_dom_id', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function remove_all() + #[\PHPUnit\Framework\Attributes\Test] + public function remove_all(): void { $response = response() ->turboStream() @@ -711,12 +699,12 @@ public function remove_all() 'targets' => '.test_models', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function before_shorthand() + #[\PHPUnit\Framework\Attributes\Test] + public function before_shorthand(): void { $response = response() ->turboStream() @@ -731,12 +719,12 @@ public function before_shorthand() 'partialData' => ['article' => $article], ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function before_shorthand_as_string() + #[\PHPUnit\Framework\Attributes\Test] + public function before_shorthand_as_string(): void { $response = response() ->turboStream() @@ -749,12 +737,12 @@ public function before_shorthand_as_string() 'content' => 'Hello World', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function before_shorthand_passing_as_string_target_and_view_as_content() + #[\PHPUnit\Framework\Attributes\Test] + public function before_shorthand_passing_as_string_target_and_view_as_content(): void { $response = response() ->turboStream() @@ -767,12 +755,12 @@ public function before_shorthand_passing_as_string_target_and_view_as_content() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function before_all_with_inline_content_string() + #[\PHPUnit\Framework\Attributes\Test] + public function before_all_with_inline_content_string(): void { $response = response() ->turboStream() @@ -785,30 +773,30 @@ public function before_all_with_inline_content_string() 'content' => 'Some inline content', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function before_all_passing_html_safe_string() + #[\PHPUnit\Framework\Attributes\Test] + public function before_all_passing_html_safe_string(): void { $response = response() ->turboStream() ->beforeAll('.test_models', new HtmlString('
Some safe HTML content
')) ->toResponse(new Request); - $expected = <<<'HTML' + $expected = <<<'HTML_WRAP' - HTML; + HTML_WRAP; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function before_all_passing_view_as_content() + #[\PHPUnit\Framework\Attributes\Test] + public function before_all_passing_view_as_content(): void { $response = response() ->turboStream() @@ -821,12 +809,12 @@ public function before_all_passing_view_as_content() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function after_shorthand() + #[\PHPUnit\Framework\Attributes\Test] + public function after_shorthand(): void { $response = response() ->turboStream() @@ -841,12 +829,12 @@ public function after_shorthand() 'partialData' => ['article' => $article], ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function after_shorthand_as_string() + #[\PHPUnit\Framework\Attributes\Test] + public function after_shorthand_as_string(): void { $response = response() ->turboStream() @@ -859,12 +847,12 @@ public function after_shorthand_as_string() 'content' => 'Hello World', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function after_all_with_inline_content_string() + #[\PHPUnit\Framework\Attributes\Test] + public function after_all_with_inline_content_string(): void { $response = response() ->turboStream() @@ -877,30 +865,30 @@ public function after_all_with_inline_content_string() 'content' => 'Some inline content', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function after_all_passing_html_safe_string() + #[\PHPUnit\Framework\Attributes\Test] + public function after_all_passing_html_safe_string(): void { $response = response() ->turboStream() ->afterAll('.test_models', new HtmlString('
Some safe HTML content
')) ->toResponse(new Request); - $expected = <<<'HTML' + $expected = <<<'HTML_WRAP' - HTML; + HTML_WRAP; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function after_all_passing_view_as_content() + #[\PHPUnit\Framework\Attributes\Test] + public function after_all_passing_view_as_content(): void { $response = response() ->turboStream() @@ -913,12 +901,12 @@ public function after_all_passing_view_as_content() HTML; - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function targets() + #[\PHPUnit\Framework\Attributes\Test] + public function targets(): void { $response = response() ->turboStream() @@ -931,12 +919,12 @@ public function targets() 'targets' => '.some_dom_class', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function builds_multiple_turbo_stream_responses() + #[\PHPUnit\Framework\Attributes\Test] + public function builds_multiple_turbo_stream_responses(): void { $article = ArticleFactory::new()->create(); @@ -965,12 +953,12 @@ public function builds_multiple_turbo_stream_responses() ])->render(), ])->implode(PHP_EOL); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function response_builder_fails_when_partial_is_missing_and_not_a_remove_action() + #[\PHPUnit\Framework\Attributes\Test] + public function response_builder_fails_when_partial_is_missing_and_not_a_remove_action(): void { $this->expectException(TurboStreamResponseFailedException::class); @@ -981,8 +969,8 @@ public function response_builder_fails_when_partial_is_missing_and_not_a_remove_ ->toResponse(new Request); } - /** @test */ - public function response_builder_doesnt_fail_when_partial_is_empty_string() + #[\PHPUnit\Framework\Attributes\Test] + public function response_builder_doesnt_fail_when_partial_is_empty_string(): void { $response = response() ->turboStream() @@ -995,11 +983,11 @@ public function response_builder_doesnt_fail_when_partial_is_empty_string() 'content' => '', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); } - /** @test */ - public function refresh_shorthand() + #[\PHPUnit\Framework\Attributes\Test] + public function refresh_shorthand(): void { $response = response() ->turboStream() @@ -1010,12 +998,12 @@ public function refresh_shorthand() 'action' => 'refresh', ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } - /** @test */ - public function refresh_shorthand_with_request_id() + #[\PHPUnit\Framework\Attributes\Test] + public function refresh_shorthand_with_request_id(): void { FacadesTurbo::setTurboTrackingRequestId('123'); @@ -1031,7 +1019,7 @@ public function refresh_shorthand_with_request_id() ], ])->render(); - $this->assertEquals(trim($expected), trim($response->getContent())); + $this->assertEquals(trim($expected), trim((string) $response->getContent())); $this->assertEquals(Turbo::TURBO_STREAM_FORMAT, $response->headers->get('Content-Type')); } } diff --git a/tests/Http/TestResponseMacrosTest.php b/tests/Http/TestResponseMacrosTest.php index 6c31504..8093b8c 100644 --- a/tests/Http/TestResponseMacrosTest.php +++ b/tests/Http/TestResponseMacrosTest.php @@ -10,13 +10,12 @@ class TestResponseMacrosTest extends TestCase use InteractsWithTurbo; /** - * @test - * * @testWith ["recede_or_redirect", "turbo_recede_historical_location", "assertRedirectRecede"] * ["resume_or_redirect", "turbo_resume_historical_location", "assertRedirectResume"] * ["refresh_or_redirect", "turbo_refresh_historical_location", "assertRedirectRefresh"] */ - public function asserts_historical_locations_without_flashes($returnTo, $route, $method) + #[\PHPUnit\Framework\Attributes\Test] + public function asserts_historical_locations_without_flashes($returnTo, $route, $method): void { $this->turboNative()->post(route('trays.store', 1), [ 'return_to' => $returnTo, @@ -28,13 +27,12 @@ public function asserts_historical_locations_without_flashes($returnTo, $route, } /** - * @test - * * @testWith ["recede_or_redirect", "turbo_recede_historical_location", "assertRedirectRecede"] * ["resume_or_redirect", "turbo_resume_historical_location", "assertRedirectResume"] * ["refresh_or_redirect", "turbo_refresh_historical_location", "assertRedirectRefresh"] */ - public function asserts_historical_locations_with_flashes($returnTo, $route, $method) + #[\PHPUnit\Framework\Attributes\Test] + public function asserts_historical_locations_with_flashes($returnTo, $route, $method): void { $this->turboNative()->post(route('trays.store', 1), [ 'return_to' => $returnTo, diff --git a/tests/Http/TurboStreamResponseTest.php b/tests/Http/TurboStreamResponseTest.php index deee5b7..7ac926b 100644 --- a/tests/Http/TurboStreamResponseTest.php +++ b/tests/Http/TurboStreamResponseTest.php @@ -11,8 +11,8 @@ class TurboStreamResponseTest extends TestCase { use InteractsWithTurbo; - /** @test */ - public function turbo_stream_response() + #[\PHPUnit\Framework\Attributes\Test] + public function turbo_stream_response(): void { $article = ArticleFactory::new()->create(); @@ -23,8 +23,8 @@ public function turbo_stream_response() ->assertTurboStream(); } - /** @test */ - public function not_turbo_response() + #[\PHPUnit\Framework\Attributes\Test] + public function not_turbo_response(): void { $article = ArticleFactory::new()->create(); @@ -34,26 +34,26 @@ public function not_turbo_response() ->assertNotTurboStream(); } - /** @test */ - public function turbo_assert_count_of_turbo_streams() + #[\PHPUnit\Framework\Attributes\Test] + public function turbo_assert_count_of_turbo_streams(): void { $article = ArticleFactory::new()->create(); $this->turbo() ->post(route('articles.comments.store', $article), ['content' => 'Hello World']) - ->assertTurboStream(fn (AssertableTurboStream $turboStream) => ( + ->assertTurboStream(fn (AssertableTurboStream $turboStream): \HotwiredLaravel\TurboLaravel\Testing\AssertableTurboStream => ( $turboStream->has(2) )); } - /** @test */ - public function turbo_assert_has_turbo_stream() + #[\PHPUnit\Framework\Attributes\Test] + public function turbo_assert_has_turbo_stream(): void { $article = ArticleFactory::new()->create(); $this->turbo() ->post(route('articles.comments.store', $article), ['content' => 'Hello World']) - ->assertTurboStream(fn (AssertableTurboStream $turboStreams) => ( + ->assertTurboStream(fn (AssertableTurboStream $turboStreams): true => ( $turboStreams->has(2) && $turboStreams->hasTurboStream(fn ($turboStream) => ( $turboStream->where('target', 'comments') @@ -68,8 +68,8 @@ public function turbo_assert_has_turbo_stream() )); } - /** @test */ - public function turbo_allows_custom_actions_with_no_view() + #[\PHPUnit\Framework\Attributes\Test] + public function turbo_allows_custom_actions_with_no_view(): void { $this->assertEquals( <<<'HTML' diff --git a/tests/Models/BroadcastsModelTest.php b/tests/Models/BroadcastsModelTest.php index c54a7f4..26ffb41 100644 --- a/tests/Models/BroadcastsModelTest.php +++ b/tests/Models/BroadcastsModelTest.php @@ -31,8 +31,8 @@ protected function setUp(): void TurboStream::fake(); } - /** @test */ - public function manually_broadcast_append() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_broadcast_append(): void { $article = ArticleFactory::new()->create(); @@ -40,7 +40,7 @@ public function manually_broadcast_append() $article->broadcastAppend(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals('private-articles', $broadcast->channels[0]->name); $this->assertEquals('articles', $broadcast->target); @@ -53,8 +53,8 @@ public function manually_broadcast_append() }); } - /** @test */ - public function manually_append_with_overrides() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_append_with_overrides(): void { $article = ArticleFactory::new()->create(); @@ -65,7 +65,7 @@ public function manually_append_with_overrides() ->target('some_other_target') ->partial('another_partial', ['lorem' => 'ipsum']); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($channel) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($channel): true { $this->assertCount(1, $broadcast->channels); $this->assertSame($channel, $broadcast->channels[0]); $this->assertEquals('some_other_target', $broadcast->target); @@ -78,8 +78,8 @@ public function manually_append_with_overrides() }); } - /** @test */ - public function manually_before_with_overrides() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_before_with_overrides(): void { $article = ArticleFactory::new()->create(); @@ -92,7 +92,7 @@ public function manually_before_with_overrides() 'lorem' => 'ipsum', ]); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article, $channel) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article, $channel): true { $this->assertCount(1, $broadcast->channels); $this->assertSame($channel, $broadcast->channels[0]); $this->assertEquals('articles_card', $broadcast->target); @@ -105,8 +105,8 @@ public function manually_before_with_overrides() }); } - /** @test */ - public function manually_after_with_overrides() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_after_with_overrides(): void { $article = ArticleFactory::new()->create(); @@ -119,7 +119,7 @@ public function manually_after_with_overrides() 'lorem' => 'ipsum', ]); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article, $channel) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article, $channel): true { $this->assertCount(1, $broadcast->channels); $this->assertSame($channel, $broadcast->channels[0]); $this->assertEquals('article_cards', $broadcast->target); @@ -132,8 +132,8 @@ public function manually_after_with_overrides() }); } - /** @test */ - public function manually_before_to_with_overrides() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_before_to_with_overrides(): void { $article = ArticleFactory::new()->create(); @@ -145,7 +145,7 @@ public function manually_before_to_with_overrides() 'lorem' => 'ipsum', ]); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article, $channel) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article, $channel): true { $this->assertCount(1, $broadcast->channels); $this->assertSame($channel, $broadcast->channels[0]); $this->assertEquals('example_dom_id_target', $broadcast->target); @@ -158,8 +158,8 @@ public function manually_before_to_with_overrides() }); } - /** @test */ - public function manually_after_to_with_overrides() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_after_to_with_overrides(): void { $article = ArticleFactory::new()->create(); @@ -171,7 +171,7 @@ public function manually_after_to_with_overrides() 'lorem' => 'ipsum', ]); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article, $channel) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article, $channel): true { $this->assertCount(1, $broadcast->channels); $this->assertSame($channel, $broadcast->channels[0]); $this->assertEquals('example_dom_id_target', $broadcast->target); @@ -184,8 +184,8 @@ public function manually_after_to_with_overrides() }); } - /** @test */ - public function manually_broadcast_replace() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_broadcast_replace(): void { $article = ArticleFactory::new()->create(); @@ -193,7 +193,7 @@ public function manually_broadcast_replace() $article->broadcastReplace(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals(sprintf('private-%s', $article->broadcastChannel()), $broadcast->channels[0]->name); $this->assertEquals("article_{$article->id}", $broadcast->target); @@ -206,8 +206,8 @@ public function manually_broadcast_replace() }); } - /** @test */ - public function manually_broadcast_remove() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_broadcast_remove(): void { $article = ArticleFactory::new()->create(); @@ -215,7 +215,7 @@ public function manually_broadcast_remove() $article->broadcastRemove(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals(sprintf('private-%s', $article->broadcastChannel()), $broadcast->channels[0]->name); $this->assertEquals("article_{$article->id}", $broadcast->target); @@ -228,12 +228,12 @@ public function manually_broadcast_remove() }); } - /** @test */ - public function can_auto_broadcast() + #[\PHPUnit\Framework\Attributes\Test] + public function can_auto_broadcast(): void { $comment = CommentFactory::new()->create(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($comment) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($comment): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals('private-'.$comment->article->broadcastChannel(), $broadcast->channels[0]->name); $this->assertEquals('comments', $broadcast->target); @@ -246,12 +246,12 @@ public function can_auto_broadcast() }); } - /** @test */ - public function can_auto_broadcast_with_custom_overrides() + #[\PHPUnit\Framework\Attributes\Test] + public function can_auto_broadcast_with_custom_overrides(): void { $company = CompanyFactory::new()->create(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($company) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($company): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals('private-custom-channel', $broadcast->channels[0]->name); $this->assertEquals('companies', $broadcast->target); @@ -264,8 +264,8 @@ public function can_auto_broadcast_with_custom_overrides() }); } - /** @test */ - public function can_configure_auto_broadcast_to_parent_model_using_a_method() + #[\PHPUnit\Framework\Attributes\Test] + public function can_configure_auto_broadcast_to_parent_model_using_a_method(): void { $company = Company::withoutEvents(fn () => CompanyFactory::new()->create()); @@ -273,7 +273,7 @@ public function can_configure_auto_broadcast_to_parent_model_using_a_method() 'company_id' => $company, ]); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($company, $contact) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($company, $contact): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals(sprintf('private-%s', $company->broadcastChannel()), $broadcast->channels[0]->name); $this->assertEquals('contacts', $broadcast->target); @@ -286,8 +286,8 @@ public function can_configure_auto_broadcast_to_parent_model_using_a_method() }); } - /** @test */ - public function manually_broadcast_append_targets() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_broadcast_append_targets(): void { $article = ArticleFactory::new()->create(); @@ -296,7 +296,7 @@ public function manually_broadcast_append_targets() $article->broadcastAppend() ->targets('.test_targets'); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals('private-articles', $broadcast->channels[0]->name); $this->assertNull($broadcast->target); @@ -309,8 +309,8 @@ public function manually_broadcast_append_targets() }); } - /** @test */ - public function broadcasts_on_model_touching() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcasts_on_model_touching(): void { $oldUpdatedAt = now()->subDays(10); @@ -329,7 +329,7 @@ public function broadcasts_on_model_touching() // Must have updated the parent timestamps... $this->assertFalse($comment->fresh()->updated_at->isSameDay($oldUpdatedAt)); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($comment) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($comment): true { $this->assertCount(1, $broadcast->channels); // The comment model is configured to broadacst to the article's channel... $this->assertEquals('private-'.$comment->article->broadcastChannel(), $broadcast->channels[0]->name); @@ -345,8 +345,8 @@ public function broadcasts_on_model_touching() }); } - /** @test */ - public function manually_broadcast_refresh() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_broadcast_refresh(): void { $article = ArticleFactory::new()->create(); @@ -354,7 +354,7 @@ public function manually_broadcast_refresh() $article->broadcastRefresh(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals('private-articles', $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -367,8 +367,8 @@ public function manually_broadcast_refresh() }); } - /** @test */ - public function manually_broadcast_refresh_with_overrides() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_broadcast_refresh_with_overrides(): void { $article = ArticleFactory::new()->create(); @@ -376,7 +376,7 @@ public function manually_broadcast_refresh_with_overrides() $article->broadcastRefresh()->to($channel = new Channel('hello')); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($channel) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($channel): true { $this->assertCount(1, $broadcast->channels); $this->assertSame($channel, $broadcast->channels[0]); $this->assertEquals('refresh', $broadcast->action); @@ -389,8 +389,8 @@ public function manually_broadcast_refresh_with_overrides() }); } - /** @test */ - public function manually_broadcast_refresh_with_current_request_id() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_broadcast_refresh_with_current_request_id(): void { Turbo::setTurboTrackingRequestId('123'); @@ -400,7 +400,7 @@ public function manually_broadcast_refresh_with_current_request_id() $article->broadcastRefresh()->to($channel = new Channel('hello')); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($channel) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($channel): true { $this->assertCount(1, $broadcast->channels); $this->assertSame($channel, $broadcast->channels[0]); $this->assertEquals('refresh', $broadcast->action); @@ -414,8 +414,8 @@ public function manually_broadcast_refresh_with_current_request_id() }); } - /** @test */ - public function manually_broadcast_refresh_to() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_broadcast_refresh_to(): void { $article = ArticleFactory::new()->create(); @@ -423,7 +423,7 @@ public function manually_broadcast_refresh_to() $article->broadcastRefreshTo($channel = new Channel('hello')); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($channel) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($channel): true { $this->assertCount(1, $broadcast->channels); $this->assertSame($channel, $broadcast->channels[0]); $this->assertEquals('refresh', $broadcast->action); @@ -437,14 +437,14 @@ public function manually_broadcast_refresh_to() }); } - /** @test */ - public function auto_broadcast_refreshes_on_create() + #[\PHPUnit\Framework\Attributes\Test] + public function auto_broadcast_refreshes_on_create(): void { TurboStream::assertNothingWasBroadcasted(); BoardFactory::new()->create(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-boards', $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -458,8 +458,8 @@ public function auto_broadcast_refreshes_on_create() }); } - /** @test */ - public function auto_broadcast_refreshes_on_create_with_current_request_id() + #[\PHPUnit\Framework\Attributes\Test] + public function auto_broadcast_refreshes_on_create_with_current_request_id(): void { Turbo::setTurboTrackingRequestId('123'); @@ -467,7 +467,7 @@ public function auto_broadcast_refreshes_on_create_with_current_request_id() BoardFactory::new()->create(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-boards', $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -481,8 +481,8 @@ public function auto_broadcast_refreshes_on_create_with_current_request_id() }); } - /** @test */ - public function auto_broadcast_refreshes_on_update() + #[\PHPUnit\Framework\Attributes\Test] + public function auto_broadcast_refreshes_on_update(): void { TurboStream::assertNothingWasBroadcasted(); @@ -492,7 +492,7 @@ public function auto_broadcast_refreshes_on_update() $board->update(['name' => 'Updated']); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-'.$board->broadcastChannel(), $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -506,8 +506,8 @@ public function auto_broadcast_refreshes_on_update() }); } - /** @test */ - public function auto_broadcast_refreshes_on_delete() + #[\PHPUnit\Framework\Attributes\Test] + public function auto_broadcast_refreshes_on_delete(): void { TurboStream::assertNothingWasBroadcasted(); @@ -518,7 +518,7 @@ public function auto_broadcast_refreshes_on_delete() $board->delete(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-'.$board->broadcastChannel(), $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -532,8 +532,8 @@ public function auto_broadcast_refreshes_on_delete() }); } - /** @test */ - public function auto_broadcast_refreshes_to_on_create() + #[\PHPUnit\Framework\Attributes\Test] + public function auto_broadcast_refreshes_to_on_create(): void { $board = Board::withoutEvents(fn () => BoardFactory::new()->create()->fresh()); @@ -541,7 +541,7 @@ public function auto_broadcast_refreshes_to_on_create() TaskFactory::new()->for($board)->create(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-'.$board->broadcastChannel(), $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -555,10 +555,10 @@ public function auto_broadcast_refreshes_to_on_create() }); } - /** @test */ - public function auto_broadcast_refreshes_to_on_update() + #[\PHPUnit\Framework\Attributes\Test] + public function auto_broadcast_refreshes_to_on_update(): void { - [$board, $task] = Model::withoutEvents(fn () => [ + [$board, $task] = Model::withoutEvents(fn (): array => [ $board = BoardFactory::new()->create()->fresh(), TaskFactory::new()->for($board)->create()->fresh(), ]); @@ -567,7 +567,7 @@ public function auto_broadcast_refreshes_to_on_update() $task->update(['title' => 'Updated']); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-'.$board->broadcastChannel(), $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -581,10 +581,10 @@ public function auto_broadcast_refreshes_to_on_update() }); } - /** @test */ - public function auto_broadcast_refreshes_to_on_delete() + #[\PHPUnit\Framework\Attributes\Test] + public function auto_broadcast_refreshes_to_on_delete(): void { - [$board, $task] = Model::withoutEvents(fn () => [ + [$board, $task] = Model::withoutEvents(fn (): array => [ $board = BoardFactory::new()->create()->fresh(), TaskFactory::new()->for($board)->create()->fresh(), ]); @@ -593,7 +593,7 @@ public function auto_broadcast_refreshes_to_on_delete() $task->delete(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($board): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-'.$board->broadcastChannel(), $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -607,8 +607,8 @@ public function auto_broadcast_refreshes_to_on_delete() }); } - /** @test */ - public function auto_broadcast_refreshes_to_on_create_debouncing() + #[\PHPUnit\Framework\Attributes\Test] + public function auto_broadcast_refreshes_to_on_create_debouncing(): void { $this->freezeTime(); @@ -621,7 +621,7 @@ public function auto_broadcast_refreshes_to_on_create_debouncing() ->for($board) ->create(); - TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use ($board) { + TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use ($board): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-'.$board->broadcastChannel(), $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -643,7 +643,7 @@ public function auto_broadcast_refreshes_to_on_create_debouncing() ->for($board) ->create(); - TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use ($board) { + TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use ($board): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-'.$board->broadcastChannel(), $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -657,8 +657,8 @@ public function auto_broadcast_refreshes_to_on_create_debouncing() }, times: 1); } - /** @test */ - public function can_disable_manual_broadcasts() + #[\PHPUnit\Framework\Attributes\Test] + public function can_disable_manual_broadcasts(): void { /** @var Board $board */ $board = Board::withoutEvents(fn () => BoardFactory::new()->create()); @@ -673,7 +673,7 @@ public function can_disable_manual_broadcasts() $board->broadcastAppend(); - TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use ($board) { + TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use ($board): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals('private-boards', $broadcast->channels[0]->name); $this->assertEquals('boards', $broadcast->target); @@ -686,8 +686,8 @@ public function can_disable_manual_broadcasts() }, times: 1); } - /** @test */ - public function can_disable_auto_broadcasts() + #[\PHPUnit\Framework\Attributes\Test] + public function can_disable_auto_broadcasts(): void { $board = Board::withoutEvents(fn () => BoardFactory::new()->create()->fresh()); @@ -705,7 +705,7 @@ public function can_disable_auto_broadcasts() ->for($board) ->create(); - TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use ($board) { + TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use ($board): true { $this->assertCount(1, $broadcast->channels); $this->assertSame('private-'.$board->broadcastChannel(), $broadcast->channels[0]->name); $this->assertEquals('refresh', $broadcast->action); @@ -719,8 +719,8 @@ public function can_disable_auto_broadcasts() }, times: 1); } - /** @test */ - public function broadcasts_with_extra_attributes_to_turbo_stream() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcasts_with_extra_attributes_to_turbo_stream(): void { TurboStream::fake(); @@ -733,7 +733,7 @@ public function broadcasts_with_extra_attributes_to_turbo_stream() attributes: $attributes = ['data-foo' => 'bar'], ); - TurboStream::assertBroadcasted(function (PendingBroadcast $turboStream) use ($channel, $action, $attributes) { + TurboStream::assertBroadcasted(function (PendingBroadcast $turboStream) use ($channel, $action, $attributes): true { $this->assertEquals("private-{$channel}", $turboStream->channels[0]->name); $this->assertEquals($action, $turboStream->action); $this->assertEquals($attributes, $turboStream->attributes); @@ -742,8 +742,8 @@ public function broadcasts_with_extra_attributes_to_turbo_stream() }); } - /** @test */ - public function broadcasts_with_extra_attributes_to_turbo_stream_with_rendering() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcasts_with_extra_attributes_to_turbo_stream_with_rendering(): void { TurboStream::fake(); @@ -758,7 +758,7 @@ public function broadcasts_with_extra_attributes_to_turbo_stream_with_rendering( 'board' => $board, ]); - TurboStream::assertBroadcasted(function (PendingBroadcast $turboStream) use ($channel, $action, $attributes) { + TurboStream::assertBroadcasted(function (PendingBroadcast $turboStream) use ($channel, $action, $attributes): true { $this->assertEquals("private-{$channel}", $turboStream->channels[0]->name); $this->assertEquals($action, $turboStream->action); $this->assertEquals($attributes, $turboStream->attributes); @@ -768,14 +768,14 @@ public function broadcasts_with_extra_attributes_to_turbo_stream_with_rendering( }); } - /** @test */ - public function broadcasts_replace_morph() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcasts_replace_morph(): void { $article = ArticleFactory::new()->create(); $article->broadcastReplace()->morph(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals(sprintf('private-%s', $article->broadcastChannel()), $broadcast->channels[0]->name); $this->assertEquals("article_{$article->id}", $broadcast->target); @@ -789,14 +789,14 @@ public function broadcasts_replace_morph() }); } - /** @test */ - public function broadcasts_update_morph() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcasts_update_morph(): void { $article = ArticleFactory::new()->create(); $article->broadcastUpdate()->morph(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals(sprintf('private-%s', $article->broadcastChannel()), $broadcast->channels[0]->name); $this->assertEquals("article_{$article->id}", $broadcast->target); @@ -810,14 +810,14 @@ public function broadcasts_update_morph() }); } - /** @test */ - public function unsets_method_when_overriding_with_null() + #[\PHPUnit\Framework\Attributes\Test] + public function unsets_method_when_overriding_with_null(): void { $article = ArticleFactory::new()->create(); $article->broadcastUpdate()->morph()->method(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article): true { $this->assertCount(1, $broadcast->channels); $this->assertEquals(sprintf('private-%s', $article->broadcastChannel()), $broadcast->channels[0]->name); $this->assertEquals("article_{$article->id}", $broadcast->target); diff --git a/tests/Models/BroadcastsToOthersTest.php b/tests/Models/BroadcastsToOthersTest.php index 43a0e31..9706703 100644 --- a/tests/Models/BroadcastsToOthersTest.php +++ b/tests/Models/BroadcastsToOthersTest.php @@ -7,20 +7,20 @@ class BroadcastsToOthersTest extends TestCase { - /** @test */ - public function should_broadcast_to_others() + #[\PHPUnit\Framework\Attributes\Test] + public function should_broadcast_to_others(): void { $this->assertFalse(Turbo::shouldBroadcastToOthers()); - Turbo::broadcastToOthers(function () { + Turbo::broadcastToOthers(function (): void { $this->assertTrue(Turbo::shouldBroadcastToOthers()); }); $this->assertFalse(Turbo::shouldBroadcastToOthers()); } - /** @test */ - public function should_broadcast_to_others_forever() + #[\PHPUnit\Framework\Attributes\Test] + public function should_broadcast_to_others_forever(): void { $this->assertFalse(Turbo::shouldBroadcastToOthers()); diff --git a/tests/Models/NamesResolverTest.php b/tests/Models/NamesResolverTest.php index af93c7e..3f7170e 100644 --- a/tests/Models/NamesResolverTest.php +++ b/tests/Models/NamesResolverTest.php @@ -10,16 +10,16 @@ class NamesResolverTest extends TestCase { - /** @test */ - public function resolves_partial_naming() + #[\PHPUnit\Framework\Attributes\Test] + public function resolves_partial_naming(): void { $article = ArticleFactory::new()->make(); $this->assertEquals('articles._article', NamesResolver::partialNameFor($article)); } - /** @test */ - public function resolves_partial_naming_using_subfolder() + #[\PHPUnit\Framework\Attributes\Test] + public function resolves_partial_naming_using_subfolder(): void { $article = ArticleFactory::new()->make(); @@ -28,12 +28,12 @@ public function resolves_partial_naming_using_subfolder() $this->assertEquals('articles.partials.article', NamesResolver::partialNameFor($article)); } - /** @test */ - public function resolves_using_custom_closure() + #[\PHPUnit\Framework\Attributes\Test] + public function resolves_using_custom_closure(): void { $article = ArticleFactory::new()->make(); - Turbo::resolvePartialsPathUsing(fn (Model $model) => 'partials.article'); + Turbo::resolvePartialsPathUsing(fn (Model $model): string => 'partials.article'); $this->assertEquals('partials.article', NamesResolver::partialNameFor($article)); } diff --git a/tests/Models/NamingTest.php b/tests/Models/NamingTest.php index 40a8f89..de393d8 100644 --- a/tests/Models/NamingTest.php +++ b/tests/Models/NamingTest.php @@ -8,8 +8,7 @@ class NamingTest extends TestCase { - /** @var Name */ - private $modelName; + private \HotwiredLaravel\TurboLaravel\Models\Naming\Name $modelName; protected function setUp(): void { @@ -18,32 +17,32 @@ protected function setUp(): void $this->modelName = Name::build(Models\User\Profile::class); } - /** @test */ - public function class_name() + #[\PHPUnit\Framework\Attributes\Test] + public function class_name(): void { $this->assertEquals(Models\User\Profile::class, $this->modelName->className); } - /** @test */ - public function class_name_without_root_namespace() + #[\PHPUnit\Framework\Attributes\Test] + public function class_name_without_root_namespace(): void { $this->assertEquals('User\\Profile', $this->modelName->classNameWithoutRootNamespace); } - /** @test */ - public function singular() + #[\PHPUnit\Framework\Attributes\Test] + public function singular(): void { $this->assertEquals('user_profile', $this->modelName->singular); } - /** @test */ - public function plural() + #[\PHPUnit\Framework\Attributes\Test] + public function plural(): void { $this->assertEquals('user_profiles', $this->modelName->plural); } - /** @test */ - public function element() + #[\PHPUnit\Framework\Attributes\Test] + public function element(): void { $this->assertEquals('profile', $this->modelName->element); } diff --git a/tests/Testing/InteractsWithTurboTest.php b/tests/Testing/InteractsWithTurboTest.php index e172959..bc8cfc1 100644 --- a/tests/Testing/InteractsWithTurboTest.php +++ b/tests/Testing/InteractsWithTurboTest.php @@ -10,8 +10,8 @@ class InteractsWithTurboTest extends TestCase { use InteractsWithTurbo; - /** @test */ - public function was_from_turbo_frame_works_when_no_frame_set() + #[\PHPUnit\Framework\Attributes\Test] + public function was_from_turbo_frame_works_when_no_frame_set(): void { $article = ArticleFactory::new()->create(); diff --git a/tests/Testing/TurboStreamMatcherTest.php b/tests/Testing/TurboStreamMatcherTest.php index 8ea01ad..96404bf 100644 --- a/tests/Testing/TurboStreamMatcherTest.php +++ b/tests/Testing/TurboStreamMatcherTest.php @@ -45,31 +45,31 @@ protected function setUp(): void $this->streams = (new ConvertTestResponseToTurboStreamCollection)($this->response)->mapInto(TurboStreamMatcher::class); } - /** @test */ - public function converts_streams_to_collections() + #[\PHPUnit\Framework\Attributes\Test] + public function converts_streams_to_collections(): void { $this->assertCount(4, $this->streams); } - /** @test */ - public function filters_by_attributes() + #[\PHPUnit\Framework\Attributes\Test] + public function filters_by_attributes(): void { // Matches on action... - $appends = $this->streams->filter(fn (TurboStreamMatcher $matcher) => ( + $appends = $this->streams->filter(fn (TurboStreamMatcher $matcher): bool => ( $matcher->where('action', 'append')->matches() )); $this->assertCount(2, $appends); // Matches on target... - $appends = $appends->filter(fn (TurboStreamMatcher $matcher) => ( + $appends = $appends->filter(fn (TurboStreamMatcher $matcher): bool => ( $matcher->where('target', 'item_2')->matches() )); $this->assertCount(1, $appends); // Matches both on action and target... - $remove_item_3 = $this->streams->filter(fn (TurboStreamMatcher $matcher) => ( + $remove_item_3 = $this->streams->filter(fn (TurboStreamMatcher $matcher): bool => ( $matcher->where('action', 'remove') ->where('target', 'item_3') ->matches() @@ -78,17 +78,17 @@ public function filters_by_attributes() $this->assertCount(1, $remove_item_3); // Matches on targets attribute... - $targets = $this->streams->filter(fn (TurboStreamMatcher $matcher) => ( + $targets = $this->streams->filter(fn (TurboStreamMatcher $matcher): bool => ( $matcher->where('targets', '.items')->matches() )); $this->assertCount(1, $targets); } - /** @test */ - public function can_see_text() + #[\PHPUnit\Framework\Attributes\Test] + public function can_see_text(): void { - $firstItem = $this->streams->filter(fn (TurboStreamMatcher $matcher) => ( + $firstItem = $this->streams->filter(fn (TurboStreamMatcher $matcher): bool => ( $matcher->where('action', 'append') ->where('target', 'item_1') ->see('First Item') @@ -98,11 +98,11 @@ public function can_see_text() $this->assertCount(1, $firstItem); } - /** @test */ - public function fails_when_string_doesnt_match() + #[\PHPUnit\Framework\Attributes\Test] + public function fails_when_string_doesnt_match(): void { try { - $this->streams->filter(fn (TurboStreamMatcher $matcher) => ( + $this->streams->filter(fn (TurboStreamMatcher $matcher): bool => ( $matcher->where('action', 'append') ->where('target', 'item_1') ->see('Second Item') @@ -110,7 +110,7 @@ public function fails_when_string_doesnt_match() )); $this->fail('Should have failed to match the text, but did not.'); - } catch (ExpectationFailedException $_e) { + } catch (ExpectationFailedException) { return; } } diff --git a/tests/TurboStreamsBroadcastingTest.php b/tests/TurboStreamsBroadcastingTest.php index 127cf97..04335b6 100644 --- a/tests/TurboStreamsBroadcastingTest.php +++ b/tests/TurboStreamsBroadcastingTest.php @@ -27,8 +27,6 @@ protected function setUp(): void } /** - * @test - * * @testWith ["append"] * ["prepend"] * ["before"] @@ -36,7 +34,8 @@ protected function setUp(): void * ["update"] * ["replace"] */ - public function can_manually_broadcast_append_streams(string $action) + #[\PHPUnit\Framework\Attributes\Test] + public function can_manually_broadcast_append_streams(string $action): void { $method = sprintf('broadcast%s', ucfirst($action)); @@ -65,8 +64,8 @@ class="px-4 py-2 shadow-lg opacity-90 bg-gray-900 text-white rounded-full mx-aut $this->assertEquals('general', $broadcasting->channels[0]->name); } - /** @test */ - public function manually_broadcast_remove_stream() + #[\PHPUnit\Framework\Attributes\Test] + public function manually_broadcast_remove_stream(): void { $broadcasting = TurboStream::broadcastRemove( channel: 'general', @@ -84,8 +83,8 @@ public function manually_broadcast_remove_stream() $this->assertEquals('general', $broadcasting->channels[0]->name); } - /** @test */ - public function can_broadcast_to_multiple_public_channels() + #[\PHPUnit\Framework\Attributes\Test] + public function can_broadcast_to_multiple_public_channels(): void { $broadcasting = TurboStream::broadcastRemove( channel: ['general', 'todolist.123'], @@ -101,8 +100,8 @@ public function can_broadcast_to_multiple_public_channels() $this->assertEquals('todolist.123', $broadcasting->channels[1]->name); } - /** @test */ - public function can_manually_broadcast_to_private_channels() + #[\PHPUnit\Framework\Attributes\Test] + public function can_manually_broadcast_to_private_channels(): void { $broadcasting = TurboStream::broadcastRemove( target: 'todo_123', @@ -112,8 +111,8 @@ public function can_manually_broadcast_to_private_channels() $this->assertEquals('private-user.123', $broadcasting->channels[0]->name); } - /** @test */ - public function can_manually_broadcast_to_multiple_private_channels() + #[\PHPUnit\Framework\Attributes\Test] + public function can_manually_broadcast_to_multiple_private_channels(): void { $broadcasting = TurboStream::broadcastRemove( target: 'todo_123', @@ -128,8 +127,8 @@ public function can_manually_broadcast_to_multiple_private_channels() $this->assertEquals('private-todolist.123', $broadcasting->channels[1]->name); } - /** @test */ - public function can_manually_broadcast_to_presence_channels() + #[\PHPUnit\Framework\Attributes\Test] + public function can_manually_broadcast_to_presence_channels(): void { $broadcasting = TurboStream::broadcastRemove( target: 'todo_123', @@ -139,8 +138,8 @@ public function can_manually_broadcast_to_presence_channels() $this->assertEquals('presence-user.123', $broadcasting->channels[0]->name); } - /** @test */ - public function can_manually_broadcast_to_multiple_presence_channels() + #[\PHPUnit\Framework\Attributes\Test] + public function can_manually_broadcast_to_multiple_presence_channels(): void { $broadcasting = TurboStream::broadcastRemove( target: 'todo_123', @@ -155,20 +154,20 @@ public function can_manually_broadcast_to_multiple_presence_channels() $this->assertEquals('presence-todolist.123', $broadcasting->channels[1]->name); } - /** @test */ - public function can_assert_nothing_was_broadcasted() + #[\PHPUnit\Framework\Attributes\Test] + public function can_assert_nothing_was_broadcasted(): void { TurboStream::assertNothingWasBroadcasted(); } - /** @test */ - public function can_assert_broadcasted() + #[\PHPUnit\Framework\Attributes\Test] + public function can_assert_broadcasted(): void { TurboStream::broadcastRemove('todo_123'); $called = false; - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use (&$called) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use (&$called): bool { $called = true; return @@ -179,15 +178,15 @@ public function can_assert_broadcasted() $this->assertTrue($called, 'The given filter callback was not called.'); } - /** @test */ - public function can_assert_broadcasted_times() + #[\PHPUnit\Framework\Attributes\Test] + public function can_assert_broadcasted_times(): void { TurboStream::broadcastRemove('todo_123'); TurboStream::broadcastRemove('todo_123'); $called = 0; - TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use (&$called) { + TurboStream::assertBroadcastedTimes(function (PendingBroadcast $broadcast) use (&$called): bool { $called++; return $broadcast->target === 'todo_123' && $broadcast->action === 'remove'; @@ -196,8 +195,8 @@ public function can_assert_broadcasted_times() $this->assertEquals(2, $called, 'The given filter callback was not called.'); } - /** @test */ - public function broadcast_inline_content() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_inline_content(): void { $broadcast = TurboStream::broadcastUpdate( channel: 'general', @@ -214,8 +213,8 @@ public function broadcast_inline_content() $this->assertEquals(trim($expected), trim($broadcast->render())); } - /** @test */ - public function broadcast_inline_content_escaped() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_inline_content_escaped(): void { $broadcast = TurboStream::broadcastAppend( channel: 'general', @@ -232,8 +231,8 @@ public function broadcast_inline_content_escaped() $this->assertEquals(trim($expected), trim($broadcast->render())); } - /** @test */ - public function broadcast_inline_content_as_html_string() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_inline_content_as_html_string(): void { $broadcast = TurboStream::broadcastAppend( channel: 'general', @@ -250,38 +249,32 @@ public function broadcast_inline_content_as_html_string() $this->assertEquals(trim($expected), trim($broadcast->render())); } - /** @test */ - public function can_cancel_broadcasting() + #[\PHPUnit\Framework\Attributes\Test] + public function can_cancel_broadcasting(): void { TurboStream::broadcastRemove('todo_123')->cancel(); TurboStream::assertNothingWasBroadcasted(); } - /** @test */ - public function can_conditionally_cancel_broadcasting() + #[\PHPUnit\Framework\Attributes\Test] + public function can_conditionally_cancel_broadcasting(): void { TurboStream::broadcastRemove('todo_123')->cancelIf(true); - TurboStream::broadcastRemove('todo_123')->cancelIf(function () { - return true; - }); + TurboStream::broadcastRemove('todo_123')->cancelIf(fn (): true => true); TurboStream::assertNothingWasBroadcasted(); TurboStream::broadcastRemove('todo_123')->cancelIf(false); - TurboStream::broadcastRemove('todo_123')->cancelIf(function () { - return false; - }); + TurboStream::broadcastRemove('todo_123')->cancelIf(fn (): false => false); - TurboStream::assertBroadcastedTimes(function ($broadcast) { - return $broadcast->action === 'remove' && $broadcast->target === 'todo_123'; - }, 2); + TurboStream::assertBroadcastedTimes(fn ($broadcast): bool => $broadcast->action === 'remove' && $broadcast->target === 'todo_123', 2); } - /** @test */ - public function can_pass_model_without_broadcasts_trait_as_channel() + #[\PHPUnit\Framework\Attributes\Test] + public function can_pass_model_without_broadcasts_trait_as_channel(): void { $message = MessageFactory::new()->create(); @@ -289,7 +282,7 @@ public function can_pass_model_without_broadcasts_trait_as_channel() $called = false; - TurboStream::assertBroadcasted(function ($broadcast) use ($message, &$called) { + TurboStream::assertBroadcasted(function ($broadcast) use ($message, &$called): bool { $called = true; return count($broadcast->channels) === 1 @@ -299,8 +292,8 @@ public function can_pass_model_without_broadcasts_trait_as_channel() $this->assertTrue($called, 'Expected callback to be called, but it was not.'); } - /** @test */ - public function can_pass_model_with_broadcasts_trait_as_channel() + #[\PHPUnit\Framework\Attributes\Test] + public function can_pass_model_with_broadcasts_trait_as_channel(): void { $article = ArticleFactory::new()->create(); @@ -308,7 +301,7 @@ public function can_pass_model_with_broadcasts_trait_as_channel() $called = false; - TurboStream::assertBroadcasted(function ($broadcast) use ($article, &$called) { + TurboStream::assertBroadcasted(function ($broadcast) use ($article, &$called): bool { $called = true; return count($broadcast->channels) === 1 @@ -318,8 +311,8 @@ public function can_pass_model_with_broadcasts_trait_as_channel() $this->assertTrue($called, 'Expected callback to be called, but it was not.'); } - /** @test */ - public function can_pass_recently_created_model_as_target() + #[\PHPUnit\Framework\Attributes\Test] + public function can_pass_recently_created_model_as_target(): void { $article = ArticleFactory::new()->create(); @@ -327,7 +320,7 @@ public function can_pass_recently_created_model_as_target() $called = false; - TurboStream::assertBroadcasted(function ($broadcast) use ($article, &$called) { + TurboStream::assertBroadcasted(function ($broadcast) use ($article, &$called): bool { $called = true; return $broadcast->target === Name::forModel($article)->plural; @@ -336,8 +329,8 @@ public function can_pass_recently_created_model_as_target() $this->assertTrue($called, 'Expected callback to be called, but it was not.'); } - /** @test */ - public function can_pass_existing_model_as_target() + #[\PHPUnit\Framework\Attributes\Test] + public function can_pass_existing_model_as_target(): void { $article = ArticleFactory::new()->create()->fresh(); @@ -345,7 +338,7 @@ public function can_pass_existing_model_as_target() $called = false; - TurboStream::assertBroadcasted(function ($broadcast) use ($article, &$called) { + TurboStream::assertBroadcasted(function ($broadcast) use ($article, &$called): bool { $called = true; return $broadcast->target === dom_id($article); @@ -354,8 +347,8 @@ public function can_pass_existing_model_as_target() $this->assertTrue($called, 'Expected callback to be called, but it was not.'); } - /** @test */ - public function broadcast_custom_action() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_custom_action(): void { $broadcast = TurboStream::broadcastAction('console_log', attributes: [ 'value' => 'Hello World', @@ -373,7 +366,7 @@ public function broadcast_custom_action() $called = false; - TurboStream::assertBroadcasted(function ($broadcast) use (&$called) { + TurboStream::assertBroadcasted(function ($broadcast) use (&$called): bool { $called = true; return $broadcast->action === 'console_log' && $broadcast->attributes == [ @@ -384,8 +377,8 @@ public function broadcast_custom_action() $this->assertTrue($called, 'Expected callback to be called, but it was not.'); } - /** @test */ - public function pass_attributes_via_setter_method() + #[\PHPUnit\Framework\Attributes\Test] + public function pass_attributes_via_setter_method(): void { $broadcast = TurboStream::broadcastAction('console_log')->attributes([ 'value' => 'Testing', @@ -399,8 +392,8 @@ public function pass_attributes_via_setter_method() $this->assertEquals(trim($expected), trim($broadcast->render())); } - /** @test */ - public function override_action_and_content_via_setter_methods() + #[\PHPUnit\Framework\Attributes\Test] + public function override_action_and_content_via_setter_methods(): void { $broadcast = TurboStream::broadcastAction('console_log') ->action('update_title') @@ -412,11 +405,11 @@ public function override_action_and_content_via_setter_methods() HTML; - $this->assertEquals(trim($expected), trim($broadcast->render())); + $this->assertEquals(trim($expected), trim((string) $broadcast->render())); } - /** @test */ - public function send_to_others() + #[\PHPUnit\Framework\Attributes\Test] + public function send_to_others(): void { $broadcast = TurboStream::broadcastAppend('Hello World'); @@ -427,8 +420,8 @@ public function send_to_others() $this->assertTrue($broadcast->sendToOthers); } - /** @test */ - public function broadcasts_using_the_response_builder_function() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcasts_using_the_response_builder_function(): void { $response = turbo_stream() ->append('notifications', 'Hello World') @@ -436,7 +429,7 @@ public function broadcasts_using_the_response_builder_function() $this->assertInstanceOf(PendingTurboStreamResponse::class, $response); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast): true { $this->assertEquals('append', $broadcast->action); $this->assertEquals('Hello World', $broadcast->inlineContent); $this->assertCount(1, $broadcast->channels); @@ -448,8 +441,8 @@ public function broadcasts_using_the_response_builder_function() }); } - /** @test */ - public function broadcast_to_private_channels_using_response_builder_function() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_to_private_channels_using_response_builder_function(): void { $response = turbo_stream() ->append('notifications', 'Hello World') @@ -457,7 +450,7 @@ public function broadcast_to_private_channels_using_response_builder_function() $this->assertInstanceOf(PendingTurboStreamResponse::class, $response); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast): true { $this->assertEquals('append', $broadcast->action); $this->assertEquals('Hello World', $broadcast->inlineContent); $this->assertCount(1, $broadcast->channels); @@ -469,8 +462,8 @@ public function broadcast_to_private_channels_using_response_builder_function() }); } - /** @test */ - public function broadcast_to_presence_channels_using_response_builder_function() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_to_presence_channels_using_response_builder_function(): void { $response = turbo_stream() ->append('notifications', 'Hello World') @@ -478,7 +471,7 @@ public function broadcast_to_presence_channels_using_response_builder_function() $this->assertInstanceOf(PendingTurboStreamResponse::class, $response); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast): true { $this->assertEquals('append', $broadcast->action); $this->assertEquals('Hello World', $broadcast->inlineContent); $this->assertCount(1, $broadcast->channels); @@ -490,8 +483,8 @@ public function broadcast_to_presence_channels_using_response_builder_function() }); } - /** @test */ - public function broadcast_to_model_channel_using_response_builder_function() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_to_model_channel_using_response_builder_function(): void { $article = ArticleFactory::new()->create()->fresh(); @@ -501,7 +494,7 @@ public function broadcast_to_model_channel_using_response_builder_function() $this->assertInstanceOf(PendingTurboStreamResponse::class, $response); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article): true { $this->assertEquals('append', $broadcast->action); $this->assertEquals('Hello World', $broadcast->inlineContent); $this->assertCount(1, $broadcast->channels); @@ -513,8 +506,8 @@ public function broadcast_to_model_channel_using_response_builder_function() }); } - /** @test */ - public function broadcast_to_model_as_private_channel_using_response_builder_function() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_to_model_as_private_channel_using_response_builder_function(): void { $article = ArticleFactory::new()->create()->fresh(); @@ -524,7 +517,7 @@ public function broadcast_to_model_as_private_channel_using_response_builder_fun $this->assertInstanceOf(PendingTurboStreamResponse::class, $response); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($article): true { $this->assertEquals('append', $broadcast->action); $this->assertEquals('Hello World', $broadcast->inlineContent); $this->assertCount(1, $broadcast->channels); @@ -536,8 +529,8 @@ public function broadcast_to_model_as_private_channel_using_response_builder_fun }); } - /** @test */ - public function broadcast_to_model_as_presence_channel_using_response_builder_function() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_to_model_as_presence_channel_using_response_builder_function(): void { $message = MessageFactory::new()->create()->fresh(); @@ -547,7 +540,7 @@ public function broadcast_to_model_as_presence_channel_using_response_builder_fu $this->assertInstanceOf(PendingTurboStreamResponse::class, $response); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($message) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($message): true { $this->assertEquals('append', $broadcast->action); $this->assertEquals('Hello World', $broadcast->inlineContent); $this->assertCount(1, $broadcast->channels); @@ -559,8 +552,8 @@ public function broadcast_to_model_as_presence_channel_using_response_builder_fu }); } - /** @test */ - public function broadcast_model_changes_using_function() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_model_changes_using_function(): void { $message = MessageFactory::new()->create(); @@ -569,7 +562,7 @@ public function broadcast_model_changes_using_function() $this->assertInstanceOf(PendingTurboStreamResponse::class, $response); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($message) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($message): true { $this->assertEquals('append', $broadcast->action); $this->assertEquals('messages._message', $broadcast->partialView); $this->assertEquals(['message' => $message], $broadcast->partialData); @@ -582,8 +575,8 @@ public function broadcast_model_changes_using_function() }); } - /** @test */ - public function broadcast_passing_model_with_broadcasts_trait_to_channel() + #[\PHPUnit\Framework\Attributes\Test] + public function broadcast_passing_model_with_broadcasts_trait_to_channel(): void { $comment = Comment::withoutEvents(fn () => CommentFactory::new()->create()->fresh()); @@ -592,7 +585,7 @@ public function broadcast_passing_model_with_broadcasts_trait_to_channel() $this->assertInstanceOf(PendingTurboStreamResponse::class, $response); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($comment) { + TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) use ($comment): true { $this->assertEquals('replace', $broadcast->action); $this->assertEquals('comments._comment', $broadcast->partialView); $this->assertEquals(['comment' => $comment], $broadcast->partialData); @@ -605,8 +598,8 @@ public function broadcast_passing_model_with_broadcasts_trait_to_channel() }); } - /** @test */ - public function can_disable_turbo_stream_broadcasts() + #[\PHPUnit\Framework\Attributes\Test] + public function can_disable_turbo_stream_broadcasts(): void { TurboStream::withoutBroadcasts(fn () => ( TurboStream::broadcastRemove('todo_123') @@ -616,15 +609,12 @@ public function can_disable_turbo_stream_broadcasts() TurboStream::broadcastRemove('todo_123'); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) { - return - $broadcast->target === 'todo_123' - && $broadcast->action === 'remove'; - }); + TurboStream::assertBroadcasted(fn (PendingBroadcast $broadcast): bool => $broadcast->target === 'todo_123' + && $broadcast->action === 'remove'); } - /** @test */ - public function globally_disabling_turbo_stream_broadcasts_also_disable_models() + #[\PHPUnit\Framework\Attributes\Test] + public function globally_disabling_turbo_stream_broadcasts_also_disable_models(): void { $article = ArticleFactory::new()->create()->fresh(); @@ -636,8 +626,6 @@ public function globally_disabling_turbo_stream_broadcasts_also_disable_models() $article->broadcastAppend(); - TurboStream::assertBroadcasted(function (PendingBroadcast $broadcast) { - return $broadcast->target === 'articles' && $broadcast->action === 'append'; - }); + TurboStream::assertBroadcasted(fn (PendingBroadcast $broadcast): bool => $broadcast->target === 'articles' && $broadcast->action === 'append'); } } diff --git a/tests/Views/ComponentsTest.php b/tests/Views/ComponentsTest.php index 7b3b402..612376e 100644 --- a/tests/Views/ComponentsTest.php +++ b/tests/Views/ComponentsTest.php @@ -12,8 +12,8 @@ class ComponentsTest extends TestCase { use InteractsWithViews; - /** @test */ - public function frames() + #[\PHPUnit\Framework\Attributes\Test] + public function frames(): void { // With all the attributes... $this->blade('', []) @@ -62,8 +62,8 @@ public function frames() ->assertSee('', false); } - /** @test */ - public function streams() + #[\PHPUnit\Framework\Attributes\Test] + public function streams(): void { $this->blade(<<<'BLADE' @@ -125,8 +125,8 @@ public function streams() ->assertSee('method="morph"', false); } - /** @test */ - public function stream_from() + #[\PHPUnit\Framework\Attributes\Test] + public function stream_from(): void { $this->blade('', [ 'model' => $article = ArticleFactory::new()->create(), @@ -137,8 +137,8 @@ public function stream_from() ])->assertSee('', false); } - /** @test */ - public function stream_target_targets_should_throw_exception() + #[\PHPUnit\Framework\Attributes\Test] + public function stream_target_targets_should_throw_exception(): void { $this->expectException(ViewException::class); @@ -149,8 +149,8 @@ public function stream_target_targets_should_throw_exception() BLADE); } - /** @test */ - public function stream_null_target_targets_should_throw_exception() + #[\PHPUnit\Framework\Attributes\Test] + public function stream_null_target_targets_should_throw_exception(): void { $this->expectException(ViewException::class); @@ -161,8 +161,8 @@ public function stream_null_target_targets_should_throw_exception() BLADE); } - /** @test */ - public function allows_custom_actions_with_extra_attributes() + #[\PHPUnit\Framework\Attributes\Test] + public function allows_custom_actions_with_extra_attributes(): void { $this->blade(<<<'BLADE' @@ -177,8 +177,8 @@ public function allows_custom_actions_with_extra_attributes() ->assertDontSee('target=', false); } - /** @test */ - public function refresh_strategy() + #[\PHPUnit\Framework\Attributes\Test] + public function refresh_strategy(): void { foreach (['replace', 'morph'] as $method) { foreach (['reset', 'preserve'] as $scroll) { @@ -191,8 +191,8 @@ public function refresh_strategy() } } - /** @test */ - public function invalid_refresh_method() + #[\PHPUnit\Framework\Attributes\Test] + public function invalid_refresh_method(): void { $this->expectException(ViewException::class); $this->expectExceptionMessage('Invalid refresh method given "invalid". Allowed values are: replace or morph.'); @@ -202,8 +202,8 @@ public function invalid_refresh_method() BLADE, ['method' => 'invalid', 'scroll' => RefreshesWith::DEFAULT_SCROLL]); } - /** @test */ - public function invalid_refresh_scroll() + #[\PHPUnit\Framework\Attributes\Test] + public function invalid_refresh_scroll(): void { $this->expectException(ViewException::class); $this->expectExceptionMessage('Invalid refresh scroll given "invalid". Allowed values are: reset or preserve.'); @@ -213,8 +213,8 @@ public function invalid_refresh_scroll() BLADE, ['method' => RefreshesWith::DEFAULT_METHOD, 'scroll' => 'invalid']); } - /** @test */ - public function turbo_drive_components() + #[\PHPUnit\Framework\Attributes\Test] + public function turbo_drive_components(): void { $this->blade( <<<'BLADE' diff --git a/tests/Views/RecordIdentifierStreamableTest.php b/tests/Views/RecordIdentifierStreamableTest.php index 441b2f7..504cd25 100644 --- a/tests/Views/RecordIdentifierStreamableTest.php +++ b/tests/Views/RecordIdentifierStreamableTest.php @@ -10,9 +10,9 @@ class RecordIdentifierStreamableTest extends TestCase { - private $streamable; + private \Workbench\App\Models\ReviewStatus $streamable; - private $singular; + private string $singular; protected function setUp(): void { @@ -22,20 +22,20 @@ protected function setUp(): void $this->singular = 'review_status'; } - /** @test */ - public function dom_id_of_streamable() + #[\PHPUnit\Framework\Attributes\Test] + public function dom_id_of_streamable(): void { $this->assertEquals("{$this->singular}_{$this->streamable->value}", (new RecordIdentifier($this->streamable))->domId()); } - /** @test */ - public function dom_id_of_streamable_with_custom_prefix() + #[\PHPUnit\Framework\Attributes\Test] + public function dom_id_of_streamable_with_custom_prefix(): void { $this->assertEquals("custom_prefix_{$this->singular}_{$this->streamable->value}", (new RecordIdentifier($this->streamable))->domId('custom_prefix')); } - /** @test */ - public function exception_is_thrown_when_given_non_streamable_instance() + #[\PHPUnit\Framework\Attributes\Test] + public function exception_is_thrown_when_given_non_streamable_instance(): void { $this->expectException(UnidentifiableRecordException::class); diff --git a/tests/Views/RecordIdentifierTest.php b/tests/Views/RecordIdentifierTest.php index 359068a..def83ef 100644 --- a/tests/Views/RecordIdentifierTest.php +++ b/tests/Views/RecordIdentifierTest.php @@ -8,9 +8,9 @@ class RecordIdentifierTest extends TestCase { - private $model; + private \Workbench\App\Models\Article $model; - private $singular; + private string $singular; protected function setUp(): void { @@ -20,48 +20,48 @@ protected function setUp(): void $this->singular = 'article'; } - /** @test */ - public function dom_id_of_new_record() + #[\PHPUnit\Framework\Attributes\Test] + public function dom_id_of_new_record(): void { $this->assertEquals("create_{$this->singular}", (new RecordIdentifier($this->model))->domId()); } - /** @test */ - public function dom_id_of_new_record_with_custom_prefix() + #[\PHPUnit\Framework\Attributes\Test] + public function dom_id_of_new_record_with_custom_prefix(): void { $this->assertEquals("custom_prefix_{$this->singular}", (new RecordIdentifier($this->model))->domId('custom_prefix')); } - /** @test */ - public function dom_id_of_saved_record() + #[\PHPUnit\Framework\Attributes\Test] + public function dom_id_of_saved_record(): void { $this->model->save(); $this->assertEquals("{$this->singular}_{$this->model->getKey()}", (new RecordIdentifier($this->model))->domId()); } - /** @test */ - public function dom_id_of_saved_record_with_custom_prefix() + #[\PHPUnit\Framework\Attributes\Test] + public function dom_id_of_saved_record_with_custom_prefix(): void { $this->model->save(); $this->assertEquals("custom_prefix_{$this->singular}_{$this->model->getKey()}", (new RecordIdentifier($this->model))->domId('custom_prefix')); } - /** @test */ - public function dom_class() + #[\PHPUnit\Framework\Attributes\Test] + public function dom_class(): void { $this->assertEquals($this->singular, (new RecordIdentifier($this->model))->domClass()); } - /** @test */ - public function dom_class_with_custom_prefix() + #[\PHPUnit\Framework\Attributes\Test] + public function dom_class_with_custom_prefix(): void { $this->assertEquals("custom_prefix_{$this->singular}", (new RecordIdentifier($this->model))->domClass('custom_prefix')); } - /** @test */ - public function channel_name_for_model() + #[\PHPUnit\Framework\Attributes\Test] + public function channel_name_for_model(): void { $this->model->save(); diff --git a/tests/Views/ViewHelpersTest.php b/tests/Views/ViewHelpersTest.php index 707514f..63a6f1d 100644 --- a/tests/Views/ViewHelpersTest.php +++ b/tests/Views/ViewHelpersTest.php @@ -6,7 +6,6 @@ use HotwiredLaravel\TurboLaravel\Testing\InteractsWithTurbo; use HotwiredLaravel\TurboLaravel\Tests\TestCase; use Illuminate\Support\Facades\Blade; -use PHPUnit\Framework\Attributes\Test; use Workbench\App\Models\Article; use Workbench\App\Models\ReviewStatus; use Workbench\App\Models\User\Profile; @@ -19,8 +18,8 @@ class ViewHelpersTest extends TestCase { use InteractsWithTurbo; - /** @test */ - public function renders_hotwire_native_correctly() + #[\PHPUnit\Framework\Attributes\Test] + public function renders_hotwire_native_correctly(): void { $article = ArticleFactory::new()->create(); @@ -36,7 +35,7 @@ public function renders_hotwire_native_correctly() ->assertSee('Visiting From Hotwire Native'); } - /** @test */ + #[\PHPUnit\Framework\Attributes\Test] public function renders_blade_native_helpers(): void { $this->assertEquals('Not Native', trim(Blade::render('@turbonative Yes Native @else Not Native @endturbonative'))); @@ -52,8 +51,8 @@ public function renders_blade_native_helpers(): void $this->assertEquals('Yes Native', trim(Blade::render('@unlesshotwirenative Not Native @else Yes Native @endunlesshotwirenative'))); } - /** @test */ - public function renders_unless_hotwire_native() + #[\PHPUnit\Framework\Attributes\Test] + public function renders_unless_hotwire_native(): void { $article = ArticleFactory::new()->create(); @@ -69,8 +68,8 @@ public function renders_unless_hotwire_native() ->assertDontSee('Back'); } - /** @test */ - public function renders_dom_id() + #[\PHPUnit\Framework\Attributes\Test] + public function renders_dom_id(): void { $article = ArticleFactory::new()->create(); @@ -83,8 +82,8 @@ public function renders_dom_id() $this->assertEquals('
', trim($rendersDomIdOfNewModel)); } - /** @test */ - public function dom_id_with_regular_classes() + #[\PHPUnit\Framework\Attributes\Test] + public function dom_id_with_regular_classes(): void { $renderedDomId = Blade::render('
', ['status' => ReviewStatus::Approved]); $renderedDomIdWithPrefix = Blade::render('
', ['status' => ReviewStatus::Approved]); @@ -93,8 +92,8 @@ public function dom_id_with_regular_classes() $this->assertEquals('
', trim($renderedDomIdWithPrefix)); } - /** @test */ - public function renders_dom_class() + #[\PHPUnit\Framework\Attributes\Test] + public function renders_dom_class(): void { $article = ArticleFactory::new()->create(); @@ -107,8 +106,8 @@ public function renders_dom_class() $this->assertEquals('
', trim($rendersDomClassOfNewModel)); } - /** @test */ - public function renders_streamable_dom_class() + #[\PHPUnit\Framework\Attributes\Test] + public function renders_streamable_dom_class(): void { $renderedDomClass = Blade::render('
', ['status' => ReviewStatus::Approved]); $renderedDomClassWithPrefix = Blade::render('
', ['status' => ReviewStatus::Approved]); @@ -117,8 +116,8 @@ public function renders_streamable_dom_class() $this->assertEquals('
', trim($renderedDomClassWithPrefix)); } - /** @test */ - public function can_use_helper_function() + #[\PHPUnit\Framework\Attributes\Test] + public function can_use_helper_function(): void { $article = ArticleFactory::new()->create(); @@ -126,8 +125,8 @@ public function can_use_helper_function() $this->assertEquals('favorites_article_'.$article->id, dom_id($article, 'favorites')); } - /** @test */ - public function generates_model_ids_for_models_in_nested_folders() + #[\PHPUnit\Framework\Attributes\Test] + public function generates_model_ids_for_models_in_nested_folders(): void { $profile = ProfileFactory::new()->create(); @@ -136,8 +135,8 @@ public function generates_model_ids_for_models_in_nested_folders() $this->assertEquals('create_user_profile', dom_id(new Profile)); } - /** @test */ - public function generates_channel_for_model() + #[\PHPUnit\Framework\Attributes\Test] + public function generates_channel_for_model(): void { $article = ArticleFactory::new()->create(); @@ -149,8 +148,8 @@ public function generates_channel_for_model() ); } - /** @test */ - public function configure_refresh_strategy() + #[\PHPUnit\Framework\Attributes\Test] + public function configure_refresh_strategy(): void { $this->get(route('trays.index')) ->assertSee('', false) From 372be1198fc0afd91cc8d6f30726d61bcee7d350 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 15:41:13 -0300 Subject: [PATCH 6/7] Remove fixed version of Carbon --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 51a3326..9181b86 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -43,7 +43,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "orchestra/workbench:${{ matrix.workbench }}" "nesbot/carbon:^2.64.1" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "orchestra/workbench:${{ matrix.workbench }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Execute tests From cec408b5c0dbb564ba0afa3744d4a65f1633fc9e Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 15:52:31 -0300 Subject: [PATCH 7/7] Remove support for Laravel 10 --- .github/workflows/run-tests.yml | 7 ++----- composer.json | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9181b86..338cb24 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,14 +8,11 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] php: [8.2, 8.3, 8.4] - laravel: [10.*, 11.*, 12.*] + laravel: [11.*, 12.*] stability: [prefer-lowest, prefer-stable] include: - - laravel: 10.* - testbench: 8.* - workbench: 8.* - laravel: 11.* testbench: 9.* workbench: 9.* diff --git a/composer.json b/composer.json index 1254ee9..3af1cde 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ ], "require": { "php": "^8.2", - "illuminate/support": "^10.0|^11.0|^12.0" + "illuminate/support": "^11.0|^12.0" }, "require-dev": { "laravel/pint": "^1.10", - "orchestra/testbench": "^8.14|^9.0|^10.0", - "orchestra/workbench": "^8.0|^9.0|^10.0", + "orchestra/testbench": "^9.0|^10.0", + "orchestra/workbench": "^9.0|^10.0", "phpunit/phpunit": "^10.5|^11.5" }, "autoload": {