session = $this->createMock(SessionInterface::class); $this->csrfGuard = new CsrfGuard($this->session); $this->container = new DefaultContainer(); $this->container->instance(CsrfGuard::class, $this->csrfGuard); $this->container->instance(SessionInterface::class, $this->session); $this->guard = new LiveComponentCsrfGuard($this->csrfGuard); } public function test_validates_valid_csrf_token(): void { // This test is skipped because CsrfProtection is final and cannot be mocked // The CSRF validation logic is tested in integration tests $this->markTestSkipped('CsrfProtection is final and cannot be mocked. Tested in integration tests.'); } public function test_rejects_missing_csrf_token(): void { $component = $this->createComponent(); $params = ActionParameters::fromArray([]); $context = $this->createContext($component, $params); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('CSRF token is required'); $this->guard->validate($context); } public function test_rejects_context_without_live_component_data(): void { $context = AttributeExecutionContext::forMethod( container: $this->container, className: ClassName::create('TestComponent'), methodName: MethodName::create('testMethod') ); $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('LiveComponentContextData'); $this->guard->validate($context); } public function test_uses_component_id_as_form_id(): void { // This test is skipped because CsrfProtection is final and cannot be mocked // The form ID generation logic is tested in integration tests $this->markTestSkipped('CsrfProtection is final and cannot be mocked. Tested in integration tests.'); } private function createComponent(): LiveComponentContract { return new TestComponent( ComponentId::create('test', 'demo'), CounterState::empty() ); } private function createContext(LiveComponentContract $component, ActionParameters $params): AttributeExecutionContext { return LiveComponentContextHelper::createForAction( container: $this->container, componentClass: ClassName::create($component::class), actionMethod: MethodName::create('testAction'), componentId: $component->id, actionParameters: $params, component: $component ); } }