From 150c1f5031a2131e67f7dcbbe4e799f3b49c685d Mon Sep 17 00:00:00 2001 From: Anton Komarev Date: Thu, 22 Feb 2024 18:43:41 +0300 Subject: [PATCH] Code style fix --- tests/Feature/AbstractFeatureTestCase.php | 16 ++--- .../Authenticator/CookieAuthorizerTest.php | 3 +- .../Authenticator/TokenAuthorizerTest.php | 3 +- tests/Traits/HasFakeHttpResponses.php | 71 +++++++++---------- 4 files changed, 44 insertions(+), 49 deletions(-) diff --git a/tests/Feature/AbstractFeatureTestCase.php b/tests/Feature/AbstractFeatureTestCase.php index ef872b9..e2b32dc 100644 --- a/tests/Feature/AbstractFeatureTestCase.php +++ b/tests/Feature/AbstractFeatureTestCase.php @@ -27,22 +27,22 @@ abstract class AbstractFeatureTestCase extends AbstractTestCase protected function initializeClient(): YouTrackClient { - $http = new GuzzleHttpClient(new HttpClient([ - 'base_uri' => $_SERVER['YOUTRACK_BASE_URI'], - ])); + $http = new GuzzleHttpClient( + new HttpClient([ + 'base_uri' => $_SERVER['YOUTRACK_BASE_URI'], + ]) + ); $authorizer = new TokenAuthorizer($_SERVER['YOUTRACK_TOKEN']); return new YouTrackClient($http, $authorizer); } /** - * @param string $path - * @return string - * * @throws \Exception */ - protected function stubsPath(string $path): string - { + protected function stubsPath( + string $path, + ): string { $path = realpath(__DIR__ . '/stubs/' . $path); if ($path === false) { diff --git a/tests/Feature/Authenticator/CookieAuthorizerTest.php b/tests/Feature/Authenticator/CookieAuthorizerTest.php index 9562faa..c4cdf44 100644 --- a/tests/Feature/Authenticator/CookieAuthorizerTest.php +++ b/tests/Feature/Authenticator/CookieAuthorizerTest.php @@ -22,10 +22,11 @@ use GuzzleHttp\Client as HttpClient; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; +use PHPUnit\Framework\Attributes\Test; final class CookieAuthorizerTest extends AbstractFeatureTestCase { - /** @test */ + #[Test] public function it_throws_exception_on_failed_cookie_authentication(): void { $mock = new MockHandler([ diff --git a/tests/Feature/Authenticator/TokenAuthorizerTest.php b/tests/Feature/Authenticator/TokenAuthorizerTest.php index 78c8276..91ceda5 100644 --- a/tests/Feature/Authenticator/TokenAuthorizerTest.php +++ b/tests/Feature/Authenticator/TokenAuthorizerTest.php @@ -21,10 +21,11 @@ use GuzzleHttp\Client as HttpClient; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; +use PHPUnit\Framework\Attributes\Test; final class TokenAuthorizerTest extends AbstractFeatureTestCase { - /** @test */ + #[Test] public function it_throws_exception_on_failed_token_authorization(): void { $mock = new MockHandler([ diff --git a/tests/Traits/HasFakeHttpResponses.php b/tests/Traits/HasFakeHttpResponses.php index 08c0743..ceedb13 100644 --- a/tests/Traits/HasFakeHttpResponses.php +++ b/tests/Traits/HasFakeHttpResponses.php @@ -20,13 +20,11 @@ trait HasFakeHttpResponses { /** * Instantiate fake HTTP Response. - * - * @param int $statusCode - * @param string|null $name - * @return \Psr\Http\Message\ResponseInterface */ - protected function createFakeResponse(int $statusCode = 200, string $name = null): ResponseInterface - { + protected function createFakeResponse( + int $statusCode = 200, + string | null $name = null, + ): ResponseInterface { if ($name === null) { return new Response($statusCode); } @@ -44,8 +42,9 @@ protected function createFakeResponse(int $statusCode = 200, string $name = null * @param string $name * @return array */ - protected function getFakeResponseHeaders(string $name): array - { + protected function getFakeResponseHeaders( + string $name, + ): array { $filePath = $this->buildFakeRequestFilePath($name, 'headers'); if (!file_exists($filePath)) { @@ -63,11 +62,8 @@ protected function getFakeResponseHeaders(string $name): array /** * Get fake HTTP Response body. - * - * @param string $name - * @return string|null */ - protected function getFakeResponseBody(string $name): ?string + protected function getFakeResponseBody(string $name): string | null { $filePath = $this->buildFakeRequestFilePath($name, 'body'); @@ -86,13 +82,11 @@ protected function getFakeResponseBody(string $name): ?string /** * Store HTTP response as fake data for later use. - * - * @param \Psr\Http\Message\ResponseInterface $response - * @param string $name - * @return void */ - protected function storeResponseAsFake(ResponseInterface $response, $name): void - { + protected function storeResponseAsFake( + ResponseInterface $response, + string $name, + ): void { $response = $this->unsetFakeResponseHeaders($response, [ 'Server', 'Date', @@ -135,8 +129,10 @@ protected function storeResponseAsFake(ResponseInterface $response, $name): void * @param string $value * @return array */ - protected function overwriteFakeRequestSessionCookie(array $headers, string $value): array - { + protected function overwriteFakeRequestSessionCookie( + array $headers, + string $value, + ): array { if (!isset($headers['Set-Cookie'])) { return $headers; } @@ -154,11 +150,10 @@ protected function overwriteFakeRequestSessionCookie(array $headers, string $val /** * Create directory for HTTP fake responses if not exists. - * - * @param string $name */ - private function createFakeResponseDirectory(string $name): void - { + private function createFakeResponseDirectory( + string $name, + ): void { $dir = $this->buildFakeRequestDirectoryPath($name); if (!file_exists($dir)) { mkdir($dir, 0777, true); @@ -174,8 +169,10 @@ private function createFakeResponseDirectory(string $name): void * @param array $headers * @return \Psr\Http\Message\ResponseInterface */ - private function unsetFakeResponseHeaders(ResponseInterface $response, array $headers = []): ResponseInterface - { + private function unsetFakeResponseHeaders( + ResponseInterface $response, + array $headers = [], + ): ResponseInterface { foreach ($headers as $header) { $response = $response->withoutHeader($header); } @@ -185,32 +182,28 @@ private function unsetFakeResponseHeaders(ResponseInterface $response, array $he /** * Build path to fake HTTP Response data directory. - * - * @param string $name - * @return string */ - private function buildFakeRequestDirectoryPath(string $name): string - { + private function buildFakeRequestDirectoryPath( + string $name, + ): string { return sprintf( '%s/../stubs/server-responses/2017.2/%s', __DIR__, - ltrim($name, '/') + ltrim($name, '/'), ); } /** * Build path to fake HTTP Response data file. - * - * @param string $name - * @param string $filename - * @return string */ - private function buildFakeRequestFilePath(string $name, string $filename): string - { + private function buildFakeRequestFilePath( + string $name, + string $filename, + ): string { return sprintf( '%s/%s.json', $this->buildFakeRequestDirectoryPath($name), - $filename + $filename, ); } }