. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\Http\Exceptions\HttpBadRequestException; use Fisharebest\Webtrees\Services\MessageService; use Fisharebest\Webtrees\TestCase; use Illuminate\Support\Collection; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(BroadcastPage::class)] class BroadcastPageTest extends TestCase { protected static bool $uses_database = true; public function testMissingParameterTo(): void { $message_service = $this->createStub(MessageService::class); $message_service->method('recipientTypes')->willReturn(['foo' => 'FOO']); $request = self::createRequest() ->withAttribute('to', 'bar'); $handler = new BroadcastPage($message_service); $this->expectException(HttpBadRequestException::class); $handler->handle($request); } public function testHandler(): void { $message_service = $this->createStub(MessageService::class); $message_service->method('recipientTypes')->willReturn(['foo' => 'FOO', 'bar' => 'BAR']); $message_service->method('recipientUsers')->willReturn(new Collection()); $request = self::createRequest() ->withAttribute('to', 'foo'); $handler = new BroadcastPage($message_service); $response = $handler->handle($request); self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); } }