Skip to content

Commit

Permalink
Release 8.0 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev authored Feb 22, 2024
1 parent 907748a commit 9083124
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 49 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to `cybercog/youtrack-rest-php` will be documented in this f

## [Unreleased]

## [8.0.0] - 2024-02-22

### Added

- ([#59]) Added Docker dev environment
Expand Down
16 changes: 8 additions & 8 deletions tests/Feature/AbstractFeatureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Authenticator/CookieAuthorizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Authenticator/TokenAuthorizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
71 changes: 32 additions & 39 deletions tests/Traits/HasFakeHttpResponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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)) {
Expand All @@ -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');

Expand All @@ -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',
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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,
);
}
}

0 comments on commit 9083124

Please sign in to comment.