Skip to content

Commit

Permalink
Update phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
bytestream committed Nov 25, 2024
1 parent 9a26d23 commit 8b08945
Show file tree
Hide file tree
Showing 9 changed files with 618 additions and 753 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
},
"require-dev": {
"brianium/paratest": "^4.0|^5.0|^6.0",
"jangregor/phpstan-prophecy": "^1.0",
"jangregor/phpstan-prophecy": "2.0.0",
"larapack/dd": "^1.1",
"phpmd/phpmd": "^2.9",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "1.11.2",
"phpstan/phpstan": "2.0.0",
"phpunit/phpunit": "^9.3",
"rregeer/phpunit-coverage-check": "^0.3.1",
"slevomat/coding-standard": "^8.15",
Expand Down
1,312 changes: 593 additions & 719 deletions composer.lock

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions test/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use GuzzleHttp\Psr7\Response;
use JsonException;
use Psr\Http\Message\StreamInterface;
use SupportPal\ApiClient\Api\Api;
use SupportPal\ApiClient\Model\Model;
Expand Down Expand Up @@ -56,8 +57,7 @@ public function testUnsuccessfulGetEndpoint(Response $response, string $endpoint
*/
public function testSuccessfulPostEndpoint(Model $model, array $responseData, string $functionName): void
{
/** @var string $jsonSuccessfulBody */
$jsonSuccessfulBody = json_encode($responseData);
$jsonSuccessfulBody = json_encode($responseData) ?: throw new JsonException('Failed to encode JSON.');
$this->appendRequestResponse(new Response(200, [], $jsonSuccessfulBody));
/** @var callable $callable */
$callable = [$this->getApi(), $functionName];
Expand Down Expand Up @@ -89,8 +89,7 @@ public function testSuccessfulPutEndpoint(
array $responseData,
string $functionName
): void {
/** @var string $jsonSuccessfulBody */
$jsonSuccessfulBody = json_encode($responseData);
$jsonSuccessfulBody = json_encode($responseData) ?: throw new JsonException('Failed to encode JSON data.');
$this->appendRequestResponse(new Response(200, [], $jsonSuccessfulBody));
/** @var callable $callable */
$callable = [$this->getApi(), $functionName];
Expand All @@ -117,8 +116,7 @@ public function testUnsuccessfulPutEndpoint(Response $response, string $endpoint
*/
public function testSuccessfulDeleteEndpoint(int $id, string $functionName): void
{
/** @var string $jsonSuccessfulBody */
$jsonSuccessfulBody = json_encode(['status' => 'success']);
$jsonSuccessfulBody = json_encode(['status' => 'success']) ?: throw new JsonException('Failed to encode JSON.');
$this->appendRequestResponse(new Response(200, [], $jsonSuccessfulBody));
/** @var callable $callable */
$callable = [$this->getApi(), $functionName];
Expand Down
7 changes: 3 additions & 4 deletions test/ContainerAwareBaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use JsonException;
use Psr\Http\Client\RequestExceptionInterface;
use ReflectionException;
use ReflectionObject;
Expand Down Expand Up @@ -45,16 +46,14 @@ public function provideUnsuccessfulResponses(): iterable
{
$jsonSuccessfulBody = $this->genericErrorResponse;
$jsonSuccessfulBody['status'] = 'success';
/** @var string $jsonSuccessfulBody */
$jsonSuccessfulBody = json_encode($jsonSuccessfulBody);
$jsonSuccessfulBody = json_encode($jsonSuccessfulBody) ?: throw new JsonException('Failed to encode JSON data.');

yield ['error 400 response' => new Response(400, [], $jsonSuccessfulBody)];
yield ['error 401 response' => new Response(401, [], $jsonSuccessfulBody)];
yield ['error 403 response' => new Response(403, [], $jsonSuccessfulBody)];
yield ['error 404 response' => new Response(404, [], $jsonSuccessfulBody)];

/** @var string $jsonErrorBody */
$jsonErrorBody = json_encode($this->genericErrorResponse);
$jsonErrorBody = json_encode($this->genericErrorResponse) ?: throw new JsonException('Failed to encode JSON data.');

yield [
'error status response' => new Response(200, [], $jsonErrorBody)
Expand Down
7 changes: 3 additions & 4 deletions test/Integration/ApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use JsonException;
use Psr\Http\Message\ResponseInterface;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Http\Client;
Expand Down Expand Up @@ -100,8 +101,7 @@ public function testUnsuccessfulGetEndpoint(Response $response, string $endpoint
*/
public function testPostModel(array $modelData, array $responseData, string $endpoint): void
{
/** @var string $jsonSuccessfulBody */
$jsonSuccessfulBody = json_encode($responseData);
$jsonSuccessfulBody = json_encode($responseData) ?: throw new JsonException('Failed to encode JSON data.');
$expectedResponse = new Response(200, [], $jsonSuccessfulBody);
$this->appendRequestResponse($expectedResponse);
$response = $this->makeClientCall($endpoint, [$modelData]);
Expand Down Expand Up @@ -134,8 +134,7 @@ public function testUnsuccessfulPostModel(Response $response, string $endpoint,
*/
public function testPutModel(array $modelData, array $responseData, string $endpoint): void
{
/** @var string $jsonSuccessfulBody */
$jsonSuccessfulBody = json_encode($responseData);
$jsonSuccessfulBody = json_encode($responseData) ?: throw new JsonException('Failed to encode JSON data.');
$expectedResponse = new Response(200, [], $jsonSuccessfulBody);
$this->appendRequestResponse($expectedResponse);
$response = $this->makeClientCall($endpoint, [self::TEST_ID, $modelData]);
Expand Down
4 changes: 0 additions & 4 deletions test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ protected function assertApiDataMatchesModels(Model|Collection $models, array $d
return;
}

if (! ($models instanceof Model)) {
return;
}

$this->assertArrayEqualsObjectFields($models, $data['data']);
}

Expand Down
21 changes: 10 additions & 11 deletions test/Unit/ApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Request as BaseRequest;
use JsonException;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Client\ClientExceptionInterface;
Expand All @@ -32,10 +33,10 @@ class ApiClientTest extends TestCase
'data' => []
];

/** @var ObjectProphecy|ClientInterface */
/** @var ObjectProphecy<ClientInterface> */
protected $httpClient;

/** @var ObjectProphecy|Request */
/** @var ObjectProphecy<Request> */
protected $requestFactory;

/** @var Client $apiClient */
Expand Down Expand Up @@ -106,16 +107,14 @@ public function provideUnsuccessfulTestCases(): iterable
{
$jsonErrorBody = $this->genericErrorResponse;
$jsonErrorBody['status'] = 'success';
/** @var string $jsonSuccessfulBody */
$jsonSuccessfulBody = json_encode($jsonErrorBody);
$jsonSuccessfulBody = json_encode($jsonErrorBody) ?: throw new JsonException('Failed to encode JSON data.');

yield ['error 400 response' => 400, $jsonSuccessfulBody];
yield ['error 401 response' => 401, $jsonSuccessfulBody];
yield ['error 403 response' => 403, $jsonSuccessfulBody];
yield ['error 404 response' => 404, $jsonSuccessfulBody];

/** @var string $jsonErrorBody */
$jsonErrorBody = json_encode($this->genericErrorResponse);
$jsonErrorBody = json_encode($this->genericErrorResponse) ?: throw new JsonException('Failed to encode JSON data.');

yield [
'error status response' => 200, $jsonErrorBody,
Expand All @@ -127,7 +126,7 @@ public function provideUnsuccessfulTestCases(): iterable
* @param string $endpoint
* @param array<mixed> $parameters
* @param array<mixed> $body
* @return ObjectProphecy|BaseRequest
* @return ObjectProphecy<BaseRequest>
*/
protected function requestCommonExpectations(
string $method,
Expand Down Expand Up @@ -160,8 +159,8 @@ protected function requestCommonExpectations(
/**
* @param int $statusCode
* @param string $responseBody
* @param ObjectProphecy|BaseRequest $request
* @return ObjectProphecy|ResponseInterface
* @param ObjectProphecy<BaseRequest> $request
* @return ObjectProphecy<ResponseInterface>
*/
protected function sendRequestCommonExpectations(
int $statusCode,
Expand All @@ -182,11 +181,11 @@ protected function sendRequestCommonExpectations(
}

/**
* @param ObjectProphecy|BaseRequest $request
* @param ObjectProphecy<BaseRequest> $request
*/
protected function throwClientExceptionCommonExpectations(ObjectProphecy $request): void
{
/** @var ObjectProphecy|Exception $clientExceptionInterface */
/** @var ObjectProphecy<Exception> $clientExceptionInterface */
$clientExceptionInterface = $this->prophesize(ClientExceptionInterface::class);
$this->httpClient
->sendRequest($request->reveal())
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class ApiTest extends TestCase
{
protected const TEST_ID = 1;

/** @var ObjectProphecy|Client */
/** @var ObjectProphecy<Client> */
protected $apiClient;

/** @var Api */
Expand Down Expand Up @@ -70,7 +70,7 @@ protected function makeCommonExpectations(array $responseData, string $model): a
}

/**
* @return ObjectProphecy|ResponseInterface
* @return ObjectProphecy<ResponseInterface>
*/
protected function makeSuccessResponse()
{
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Cache/CacheStrategyConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class CacheStrategyConfiguratorTest extends TestCase
{
/** @var ObjectProphecy|ApiCacheMap */
/** @var ObjectProphecy<ApiCacheMap> */
private $apiCacheMap;

/** @var CacheStrategyConfigurator */
Expand Down

0 comments on commit 8b08945

Please sign in to comment.