$this->getHeaders($client)]; } protected function createTestUser( string $handle = 'test_user', string $email = self::USER_EMAIL, ) { return UserFactory::createOne([ 'handle' => $handle, 'email' => $email, 'password' => self::USER_PASSWORD, ]); } protected function getExampleProjectData(): array { return [ 'id' => 1, 'title' => 'Test Project', 'subtitle' => 'Test Project Subtitle', 'category' => Category::LibreSoftware, 'territory' => ['country' => 'ES'], 'description' => 'Test Project Description', 'deadline' => ProjectDeadline::Minimum, 'status' => ProjectStatus::InEditing, ]; } protected function createTestProjectOptimized(int $count = 1, array $attributes = []): array { $owner = $this->createTestUser(); $territory = new ProjectTerritory('ES'); $mergedAttributes = array_merge([ 'owner' => $owner, 'territory' => $territory, ], $attributes); return ProjectFactory::createMany($count, $mergedAttributes); } protected function getHeaders(Client $client): array { $method = $this->getMethod(); return $this->getAuthHeaders($client, self::USER_EMAIL, self::USER_PASSWORD, $method); } // Auxiliary Tests protected function testOneNotFound(): void { $this->createTestProjectOptimized(1); $client = static::createClient(); $client->request( $this->getMethod(), $this->getUri(999), $this->getRequestOptions($client) ); $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND); } protected function testInsert( array $data, string $uri = self::BASE_URI, int $expectedCode = Response::HTTP_OK, ): void { $client = static::createClient(); $client->request( $this->getMethod(), $uri, ['headers' => $this->getHeaders($client), 'json' => $data] ); $this->assertResponseStatusCodeSame($expectedCode); } protected function testInvalidToken( string $uri, string $contentType = 'application/json', int $expectedToken = Response::HTTP_UNAUTHORIZED, ): void { static::createClient()->request( $this->getMethod(), $uri, ['headers' => [ 'Authorization' => 'Bearer invalid_token', 'Content-Type' => $contentType, ]] ); $this->assertResponseStatusCodeSame($expectedToken); } protected function testForbidden(): void { $otherUser = $this->createTestUser('other_user', 'otheruser@example.com'); $this->createTestProjectOptimized(1, ['owner' => $otherUser]); $client = static::createClient(); $client->request( $this->getMethod(), $this->getUri(1), $this->getRequestOptions($client) ); $this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN); } }