|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +declare(strict_types=1); |
| 4 | + |
3 | 5 | namespace Imdhemy\AppStore\Tests\Unit; |
4 | 6 |
|
5 | 7 | use GuzzleHttp\Exception\RequestException; |
6 | 8 | use GuzzleHttp\Psr7\Request; |
7 | 9 | use GuzzleHttp\Psr7\Response; |
| 10 | +use GuzzleHttp\Psr7\Uri; |
8 | 11 | use Imdhemy\AppStore\ClientFactory; |
9 | 12 | use Imdhemy\AppStore\Tests\TestCase; |
10 | 13 | use ReflectionClass; |
11 | 14 |
|
12 | 15 | final class ClientFactoryTest extends TestCase |
13 | 16 | { |
| 17 | + /** @test */ |
| 18 | + public function create_for_store_kit(): void |
| 19 | + { |
| 20 | + $options = ['headers' => ['X-Custom-Header' => 'CustomValue']]; |
| 21 | + |
| 22 | + $storeKitClient = ClientFactory::createForStoreKit($options); |
| 23 | + |
| 24 | + /** @var array{base_uri: Uri, headers: array} $config */ |
| 25 | + $config = $this->getPropertyByReflection($storeKitClient, 'config'); |
| 26 | + $this->assertSame('https://api.storekit.itunes.apple.com', (string)$config['base_uri']); |
| 27 | + $this->assertSame('CustomValue', $config['headers']['X-Custom-Header']); |
| 28 | + } |
| 29 | + |
| 30 | + /** @test */ |
| 31 | + public function create_for_store_kit_sandbox(): void |
| 32 | + { |
| 33 | + $options = ['headers' => ['X-Custom-Header' => 'CustomValue']]; |
| 34 | + |
| 35 | + $storeKitClient = ClientFactory::createForStoreKitSandbox($options); |
| 36 | + |
| 37 | + /** @var array{base_uri: Uri, headers: array} $config */ |
| 38 | + $config = $this->getPropertyByReflection($storeKitClient, 'config'); |
| 39 | + $this->assertSame('https://api.storekit-sandbox.itunes.apple.com', (string)$config['base_uri']); |
| 40 | + $this->assertSame('CustomValue', $config['headers']['X-Custom-Header']); |
| 41 | + } |
| 42 | + |
| 43 | + /** @test */ |
| 44 | + public function create_for_i_tunes(): void |
| 45 | + { |
| 46 | + $options = ['headers' => ['X-Custom-Header' => 'CustomValue']]; |
| 47 | + |
| 48 | + $itunesClient = ClientFactory::createForITunes($options); |
| 49 | + |
| 50 | + /** @var array{base_uri: Uri, headers: array} $config */ |
| 51 | + $config = $this->getPropertyByReflection($itunesClient, 'config'); |
| 52 | + $this->assertSame('https://buy.itunes.apple.com', (string)$config['base_uri']); |
| 53 | + $this->assertSame('CustomValue', $config['headers']['X-Custom-Header']); |
| 54 | + } |
| 55 | + |
| 56 | + /** @test */ |
| 57 | + public function create_for_i_tunes_sandbox(): void |
| 58 | + { |
| 59 | + $options = ['headers' => ['X-Custom-Header' => 'CustomValue']]; |
| 60 | + |
| 61 | + $itunesClient = ClientFactory::createForITunesSandbox($options); |
| 62 | + |
| 63 | + /** @var array{base_uri: Uri, headers: array} $config */ |
| 64 | + $config = $this->getPropertyByReflection($itunesClient, 'config'); |
| 65 | + $this->assertSame('https://sandbox.itunes.apple.com', (string)$config['base_uri']); |
| 66 | + $this->assertSame('CustomValue', $config['headers']['X-Custom-Header']); |
| 67 | + } |
| 68 | + |
14 | 69 | /** |
15 | 70 | * @test |
16 | 71 | * @psalm-suppress MixedArrayAccess |
|
0 commit comments