'admin-secret', 'MONITOR_STATUS_FILE' => '/does/not/exist']); $this->app = new Application(Database::inMemory(), $config); } public function testUnknownRouteReturns404(): void { $response = $this->app->handle(Request::create('GET', '/nope')); self::assertSame(404, $response->status); } public function testWrongMethodReturns405(): void { $response = $this->app->handle(Request::create('DELETE', '/api/v1/tickets')); self::assertSame(405, $response->status); } public function testWritingWithoutAgentKeyReturns401(): void { $response = $this->app->handle(Request::create('POST', '/api/v1/tickets', body: ['title' => 'X'])); self::assertSame(401, $response->status); } public function testRegisterAgentRequiresAdminKey(): void { $response = $this->app->handle(Request::create('POST', '/api/v1/agents', body: [ 'display_name' => 'Alice', 'role' => 'entwickler', ])); self::assertSame(401, $response->status); } public function testFullFlowRegisterAgentThenCreateTicket(): void { $registerResponse = $this->app->handle(Request::create( 'POST', '/api/v1/agents', body: ['display_name' => 'Alice', 'role' => 'entwickler'], headers: ['X-Admin-Key' => 'admin-secret'] )); self::assertSame(201, $registerResponse->status); $apiKey = $registerResponse->body()['api_key']; $createResponse = $this->app->handle(Request::create( 'POST', '/api/v1/tickets', body: ['title' => 'Neues Ticket'], headers: ['X-Api-Key' => $apiKey] )); self::assertSame(201, $createResponse->status); $listResponse = $this->app->handle(Request::create('GET', '/api/v1/tickets')); self::assertCount(1, $listResponse->body()['tickets']); } /** * Regression: Ein unbekanntes Ticket lief bis in die FOREIGN-KEY-Constraint und kam als * ungefangene PDOException samt Stacktrace beim Client an. */ public function testActivityWithUnknownTicketReturns422WithoutInternals(): void { $registerResponse = $this->app->handle(Request::create( 'POST', '/api/v1/agents', body: ['display_name' => 'Alice', 'role' => 'entwickler'], headers: ['X-Admin-Key' => 'admin-secret'] )); $apiKey = $registerResponse->body()['api_key']; $agentId = $registerResponse->body()['agent']['id']; $response = $this->app->handle(Request::create( 'POST', '/api/v1/agents/' . $agentId . '/activity', body: ['state' => 'working', 'current_ticket' => 999], headers: ['X-Api-Key' => $apiKey] )); self::assertSame(422, $response->status); self::assertStringNotContainsString('PDOException', json_encode($response->body())); } public function testPatchUnknownTicketReturns404(): void { $registerResponse = $this->app->handle(Request::create( 'POST', '/api/v1/agents', body: ['display_name' => 'Alice', 'role' => 'entwickler'], headers: ['X-Admin-Key' => 'admin-secret'] )); $apiKey = $registerResponse->body()['api_key']; $response = $this->app->handle(Request::create( 'PATCH', '/api/v1/tickets/999', body: ['column' => 'bereit'], headers: ['X-Api-Key' => $apiKey] )); self::assertSame(404, $response->status); } }