Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Depend on client interface #70

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Imdhemy\AppStore;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
Expand All @@ -24,9 +25,9 @@ class ClientFactory
* @param bool $sandbox
* @param array $options
*
* @return Client
* @return ClientInterface
*/
public static function create(bool $sandbox = false, array $options = []): Client
public static function create(bool $sandbox = false, array $options = []): ClientInterface
{
if (empty($options['base_uri'])) {
$options['base_uri'] = $sandbox ? self::BASE_URI_SANDBOX : self::BASE_URI;
Expand All @@ -36,9 +37,9 @@ public static function create(bool $sandbox = false, array $options = []): Clien
}

/**
* @return Client
* @return ClientInterface
*/
public static function createSandbox(): Client
public static function createSandbox(): ClientInterface
{
return self::create(true);
}
Expand All @@ -50,9 +51,9 @@ public static function createSandbox(): Client
* @param array $transactions
*
* @psalm-suppress ReferenceConstraintViolation
* @return Client
* @return ClientInterface
*/
public static function mock(ResponseInterface $responseMock, array &$transactions = []): Client
public static function mock(ResponseInterface $responseMock, array &$transactions = []): ClientInterface
{
$mockHandler = new MockHandler([$responseMock]);
$handlerStack = HandlerStack::create($mockHandler);
Expand All @@ -68,9 +69,9 @@ public static function mock(ResponseInterface $responseMock, array &$transaction
* @param array $transactions
*
* @psalm-suppress ReferenceConstraintViolation
* @return Client
* @return ClientInterface
*/
public static function mockQueue(array $responseQueue, array &$transactions = []): Client
public static function mockQueue(array $responseQueue, array &$transactions = []): ClientInterface
{
$mockHandler = new MockHandler($responseQueue);
$handlerStack = HandlerStack::create($mockHandler);
Expand All @@ -86,9 +87,9 @@ public static function mockQueue(array $responseQueue, array &$transactions = []
* @param array $transactions
*
* @psalm-suppress ReferenceConstraintViolation
* @return Client
* @return ClientInterface
*/
public static function mockError(RequestExceptionInterface $error, array &$transactions = []): Client
public static function mockError(RequestExceptionInterface $error, array &$transactions = []): ClientInterface
{
$mockHandler = new MockHandler([$error]);
$handlerStack = HandlerStack::create($mockHandler);
Expand Down
21 changes: 12 additions & 9 deletions src/Receipts/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Imdhemy\AppStore\Receipts;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use Imdhemy\AppStore\ClientFactory;
use Imdhemy\AppStore\Exceptions\InvalidReceiptException;
Expand All @@ -21,7 +22,7 @@ class Verifier
public const VERIFY_RECEIPT_PATH = '/verifyReceipt';

/**
* @var Client
* @var ClientInterface
*/
protected $client;

Expand All @@ -38,25 +39,25 @@ class Verifier
/**
* Receipt constructor.
*
* @param Client $client
* @param ClientInterface $client
* @param string $receiptData
* @param string $password
*/
public function __construct(Client $client, string $receiptData, string $password)
public function __construct(ClientInterface $client, string $receiptData, string $password)
{
$this->client = $client;
$this->receiptData = $receiptData;
$this->password = $password;
}

/**
* @param Client|null $sandboxClient
* @param ClientInterface|null $sandboxClient
*
* @return ReceiptResponse
* @throws GuzzleException|InvalidReceiptException
* @deprecated Use verify() instead - this method will be removed in the next major release
*/
public function verifyRenewable(?Client $sandboxClient = null): ReceiptResponse
public function verifyRenewable(?ClientInterface $sandboxClient = null): ReceiptResponse
{
return $this->verify(true, $sandboxClient);
}
Expand All @@ -68,8 +69,10 @@ public function verifyRenewable(?Client $sandboxClient = null): ReceiptResponse
* @return ReceiptResponse
* @throws GuzzleException|InvalidReceiptException
*/
public function verify(bool $excludeOldTransactions = false, ?Client $sandboxClient = null): ReceiptResponse
{
public function verify(
bool $excludeOldTransactions = false,
?ClientInterface $sandboxClient = null
): ReceiptResponse {
$responseBody = $this->sendVerifyRequest($excludeOldTransactions);
$status = $responseBody['status'];

Expand All @@ -87,12 +90,12 @@ public function verify(bool $excludeOldTransactions = false, ?Client $sandboxCli

/**
* @param bool $excludeOldTransactions
* @param Client|null $client
* @param ClientInterface|null $client
*
* @return array
* @throws GuzzleException
*/
private function sendVerifyRequest(bool $excludeOldTransactions = false, ?Client $client = null): array
private function sendVerifyRequest(bool $excludeOldTransactions = false, ?ClientInterface $client = null): array
{
$client = $client ?? $this->client;
$options = $this->buildRequestOptions($excludeOldTransactions);
Expand Down
10 changes: 5 additions & 5 deletions src/ServerNotifications/TestNotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Imdhemy\AppStore\ServerNotifications;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use Imdhemy\AppStore\Jws\JwsGenerator;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -16,20 +16,20 @@
final class TestNotificationService
{
/**
* @var Client
* @var ClientInterface
*/
private Client $client;
private ClientInterface $client;

/**
* @var JwsGenerator
*/
private JwsGenerator $jwsGenerator;

/**
* @param Client $client
* @param ClientInterface $client
* @param JwsGenerator $jwsGenerator
*/
public function __construct(Client $client, JwsGenerator $jwsGenerator)
public function __construct(ClientInterface $client, JwsGenerator $jwsGenerator)
{
$this->client = $client;
$this->jwsGenerator = $jwsGenerator;
Expand Down