Skip to content

Commit

Permalink
fix phpcd
Browse files Browse the repository at this point in the history
  • Loading branch information
jshah4517 committed May 24, 2024
1 parent 9258343 commit 8d49a65
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions test/Unit/Factory/RequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,14 @@ public function testDefaultValues(array $data): void
$defaultParameters = ['testparams' => 'value', 'test_data2' => 'not_overwriten'];
$defaultBody = ['testbody' => 'value', 'test_data2' => 'not_overwriten'];

$expectedBody = array_merge($defaultBody, $data['body']);
[$encodedBody, $headersArray, $request] = $this
->commonCreateRequest($expectedBody, $defaultBody, $defaultParameters, $data);

self::assertInstanceOf(Request::class, $request);
self::assertSame($data['method'], $request->getMethod());
self::assertSame('test' . $data['endpoint'], $request->getUri()->getPath());
self::assertEquals($headersArray, $request->getHeaders());
self::assertSame($encodedBody, json_decode($request->getBody()->getContents(), true));
self::assertSame(
http_build_query(array_merge($defaultParameters, $data['parameters'])),
$request->getUri()->getQuery()
);
$this->createAndAssert($defaultBody, $data, $defaultParameters);
}

public function testProvidedDataOverwritesDefaults(): void
{
$defaultParameters = ['testparams' => 'value'];
$defaultBody = ['testbody' => 'value'];


$data = [
'method' => 'DELETE',
'endpoint' => 'test/api/core',
Expand All @@ -120,19 +107,7 @@ public function testProvidedDataOverwritesDefaults(): void
'parameters' => ['testparams' => 'overwrite_value']
];

$expectedBody = array_merge($defaultBody, $data['body']);
[$encodedBody, $headersArray, $request] = $this
->commonCreateRequest($expectedBody, $defaultBody, $defaultParameters, $data);

self::assertInstanceOf(Request::class, $request);
self::assertSame($data['method'], $request->getMethod());
self::assertSame('test' . $data['endpoint'], $request->getUri()->getPath());
self::assertEquals($headersArray, $request->getHeaders());
self::assertSame($encodedBody, json_decode($request->getBody()->getContents(), true));
self::assertSame(
http_build_query(array_merge($defaultParameters, $data['parameters'])),
$request->getUri()->getQuery()
);
$this->createAndAssert($defaultBody, $data, $defaultParameters);
}

/**
Expand Down Expand Up @@ -231,4 +206,27 @@ private function commonCreateRequest(

return [$expectedBody, $headersArray, $request];
}

/**
* @param mixed[] $defaultBody
* @param mixed[] $data
* @param mixed[] $defaultParameters
* @return void
*/
private function createAndAssert(array $defaultBody, array $data, array $defaultParameters): void
{
$expectedBody = array_merge($defaultBody, $data['body']);
[$encodedBody, $headersArray, $request] = $this
->commonCreateRequest($expectedBody, $defaultBody, $defaultParameters, $data);

self::assertInstanceOf(Request::class, $request);
self::assertSame($data['method'], $request->getMethod());
self::assertSame('test' . $data['endpoint'], $request->getUri()->getPath());
self::assertEquals($headersArray, $request->getHeaders());
self::assertSame($encodedBody, json_decode($request->getBody()->getContents(), true));
self::assertSame(
http_build_query(array_merge($defaultParameters, $data['parameters'])),
$request->getUri()->getQuery()
);
}
}

0 comments on commit 8d49a65

Please sign in to comment.