start(); $this->controller = new TestableRegisterController(); } protected function tearDown(): void { session()->remove('captcha_answer'); session()->remove('user_email'); parent::tearDown(); } public function testIndexGeneratesCaptchaWhenMissing() { session()->remove('captcha_answer'); $response = $this->controller->index(); $this->assertIsString($response); $captcha = session()->get('captcha_answer'); $this->assertNotEmpty($captcha); $this->assertGreaterThanOrEqual(4, strlen($captcha)); $this->assertLessThanOrEqual(8, strlen($captcha)); } public function testIndexReusesExistingCaptcha() { session()->set('captcha_answer', 'EXISTING'); $response = $this->controller->index(); $this->assertIsString($response); $this->assertSame('EXISTING', session()->get('captcha_answer')); } public function testSuccessRedirectsWhenEmailMissing() { session()->remove('user_email'); $response = $this->controller->success(); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertStringContainsString('/register', $response->getHeaderLine('Location') ?: ''); } public function testSuccessReturnsViewWhenEmailPresent() { session()->set('user_email', 'parent@example.com'); $response = $this->controller->success(); $this->assertIsString($response); $this->assertSame('parent@example.com', session()->get('user_email')); } } }