diff --git a/spec/NewTwitchApi/HelixGuzzleClientSpec.php b/spec/NewTwitchApi/HelixGuzzleClientSpec.php index dad4ddf..31366e6 100644 --- a/spec/NewTwitchApi/HelixGuzzleClientSpec.php +++ b/spec/NewTwitchApi/HelixGuzzleClientSpec.php @@ -2,15 +2,19 @@ namespace spec\NewTwitchApi; -use GuzzleHttp\Psr7\Uri; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class HelixGuzzleClientSpec extends ObjectBehavior { + function let(HelixGuzzleClient $guzzleClient) + { + $this->beConstructedWith('TEST_CLIENT_ID'); + } + function it_should_have_correct_base_uri() { - $this->beConstructedThrough('getClient', ['client-id']); - $this->shouldHaveType('\GuzzleHttp\Client'); + $this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient'); /** @var Uri $uri */ $uri = $this->getConfig('base_uri'); @@ -21,22 +25,21 @@ function it_should_have_correct_base_uri() function it_should_have_client_id_header() { - $this->beConstructedThrough('getClient', ['client-id']); - $this->shouldHaveType('\GuzzleHttp\Client'); - $this->getConfig('headers')->shouldHaveKeyWithValue('Client-ID', 'client-id'); + $this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient'); + $this->getConfig('headers')->shouldHaveKeyWithValue('Client-ID', 'TEST_CLIENT_ID'); } function it_should_have_json_content_type_header() { - $this->beConstructedThrough('getClient', ['client-id']); - $this->shouldHaveType('\GuzzleHttp\Client'); + + $this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient'); $this->getConfig('headers')->shouldHaveKeyWithValue('Content-Type', 'application/json'); } function it_should_have_passed_in_config_params_instead_of_defaults() { - $this->beConstructedThrough('getClient', ['client-id', ['base_uri' => 'https://different.url']]); - $this->shouldHaveType('\GuzzleHttp\Client'); + $this->beConstructedWith('TEST_CLIENT_ID', ['base_uri' => 'https://different.url']); + $this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient'); $this->getConfig('base_uri')->getHost()->shouldBe('different.url'); } } diff --git a/spec/NewTwitchApi/NewTwitchApiSpec.php b/spec/NewTwitchApi/NewTwitchApiSpec.php index 31a7ffd..55b95b8 100644 --- a/spec/NewTwitchApi/NewTwitchApiSpec.php +++ b/spec/NewTwitchApi/NewTwitchApiSpec.php @@ -2,8 +2,8 @@ namespace spec\NewTwitchApi; -use GuzzleHttp\Client; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use NewTwitchApi\Auth\OauthApi; use NewTwitchApi\Resources\AdsApi; use NewTwitchApi\Resources\AnalyticsApi; @@ -28,7 +28,7 @@ class NewTwitchApiSpec extends ObjectBehavior { - function let(Client $guzzleClient) + function let(HelixGuzzleClient $guzzleClient) { $this->beConstructedWith($guzzleClient, 'client-id', 'client-secret'); } diff --git a/spec/NewTwitchApi/Resources/AdsApiSpec.php b/spec/NewTwitchApi/Resources/AdsApiSpec.php index 682a08d..bd7232e 100644 --- a/spec/NewTwitchApi/Resources/AdsApiSpec.php +++ b/spec/NewTwitchApi/Resources/AdsApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class AdsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/AnalyticsApiSpec.php b/spec/NewTwitchApi/Resources/AnalyticsApiSpec.php index e95ad3b..c1d7ccf 100644 --- a/spec/NewTwitchApi/Resources/AnalyticsApiSpec.php +++ b/spec/NewTwitchApi/Resources/AnalyticsApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class AnalyticsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/BitsApiSpec.php b/spec/NewTwitchApi/Resources/BitsApiSpec.php index 3d0d8ad..e81275c 100644 --- a/spec/NewTwitchApi/Resources/BitsApiSpec.php +++ b/spec/NewTwitchApi/Resources/BitsApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class BitsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php b/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php index f4b98f4..d3e7eaf 100644 --- a/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php +++ b/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class ChannelPointsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/ChannelsApiSpec.php b/spec/NewTwitchApi/Resources/ChannelsApiSpec.php index d060681..a192304 100644 --- a/spec/NewTwitchApi/Resources/ChannelsApiSpec.php +++ b/spec/NewTwitchApi/Resources/ChannelsApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class ChannelsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/ChatApiSpec.php b/spec/NewTwitchApi/Resources/ChatApiSpec.php index 7db8f2b..ff8b333 100644 --- a/spec/NewTwitchApi/Resources/ChatApiSpec.php +++ b/spec/NewTwitchApi/Resources/ChatApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class ChatApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/EntitlementsApiSpec.php b/spec/NewTwitchApi/Resources/EntitlementsApiSpec.php index a3478b6..942603c 100644 --- a/spec/NewTwitchApi/Resources/EntitlementsApiSpec.php +++ b/spec/NewTwitchApi/Resources/EntitlementsApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class EntitlementsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/EventSubApiSpec.php b/spec/NewTwitchApi/Resources/EventSubApiSpec.php index 622794b..eb64c0f 100644 --- a/spec/NewTwitchApi/Resources/EventSubApiSpec.php +++ b/spec/NewTwitchApi/Resources/EventSubApiSpec.php @@ -2,10 +2,10 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class EventSubApiSpec extends ObjectBehavior @@ -31,7 +31,7 @@ private function createEventSubSubscription(string $type, string $version, array return $requestGenerator->generate('POST', 'eventsub/subscriptions', $this->bearer, [], $bodyParams); } - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/GamesApiSpec.php b/spec/NewTwitchApi/Resources/GamesApiSpec.php index a942204..e7e9124 100644 --- a/spec/NewTwitchApi/Resources/GamesApiSpec.php +++ b/spec/NewTwitchApi/Resources/GamesApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class GamesApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/ModerationApiSpec.php b/spec/NewTwitchApi/Resources/ModerationApiSpec.php index 79f1d9d..ccd4fb9 100644 --- a/spec/NewTwitchApi/Resources/ModerationApiSpec.php +++ b/spec/NewTwitchApi/Resources/ModerationApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class ModerationApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/PollsApiSpec.php b/spec/NewTwitchApi/Resources/PollsApiSpec.php index 3898000..088ed4e 100644 --- a/spec/NewTwitchApi/Resources/PollsApiSpec.php +++ b/spec/NewTwitchApi/Resources/PollsApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class PollsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/PredictionsApiSpec.php b/spec/NewTwitchApi/Resources/PredictionsApiSpec.php index 4a935ec..f08757f 100644 --- a/spec/NewTwitchApi/Resources/PredictionsApiSpec.php +++ b/spec/NewTwitchApi/Resources/PredictionsApiSpec.php @@ -2,15 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; class PredictionsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/StreamsApiSpec.php b/spec/NewTwitchApi/Resources/StreamsApiSpec.php index 17d713c..da4e7ca 100644 --- a/spec/NewTwitchApi/Resources/StreamsApiSpec.php +++ b/spec/NewTwitchApi/Resources/StreamsApiSpec.php @@ -2,16 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; -use Psr\Http\Message\ResponseInterface; class StreamsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/SubscriptionsApiSpec.php b/spec/NewTwitchApi/Resources/SubscriptionsApiSpec.php index 9bbd6a6..8d09a74 100644 --- a/spec/NewTwitchApi/Resources/SubscriptionsApiSpec.php +++ b/spec/NewTwitchApi/Resources/SubscriptionsApiSpec.php @@ -2,16 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; -use Psr\Http\Message\ResponseInterface; class SubscriptionsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/TagsApiSpec.php b/spec/NewTwitchApi/Resources/TagsApiSpec.php index d2a2bef..0f5fc88 100644 --- a/spec/NewTwitchApi/Resources/TagsApiSpec.php +++ b/spec/NewTwitchApi/Resources/TagsApiSpec.php @@ -2,16 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; -use Psr\Http\Message\ResponseInterface; class TagsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/TeamsApiSpec.php b/spec/NewTwitchApi/Resources/TeamsApiSpec.php index 0a9f77f..0fd592f 100644 --- a/spec/NewTwitchApi/Resources/TeamsApiSpec.php +++ b/spec/NewTwitchApi/Resources/TeamsApiSpec.php @@ -2,16 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; -use Psr\Http\Message\ResponseInterface; class TeamsApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/UsersApiSpec.php b/spec/NewTwitchApi/Resources/UsersApiSpec.php index 2a64b88..9861910 100644 --- a/spec/NewTwitchApi/Resources/UsersApiSpec.php +++ b/spec/NewTwitchApi/Resources/UsersApiSpec.php @@ -2,16 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; -use Psr\Http\Message\ResponseInterface; class UsersApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/VideosApiSpec.php b/spec/NewTwitchApi/Resources/VideosApiSpec.php index b0cf32b..4245edf 100644 --- a/spec/NewTwitchApi/Resources/VideosApiSpec.php +++ b/spec/NewTwitchApi/Resources/VideosApiSpec.php @@ -2,16 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; -use Psr\Http\Message\ResponseInterface; class VideosApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Resources/WebhooksApiSpec.php b/spec/NewTwitchApi/Resources/WebhooksApiSpec.php index ae01093..77020d4 100644 --- a/spec/NewTwitchApi/Resources/WebhooksApiSpec.php +++ b/spec/NewTwitchApi/Resources/WebhooksApiSpec.php @@ -2,16 +2,15 @@ namespace spec\NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use NewTwitchApi\RequestGenerator; +use NewTwitchApi\HelixGuzzleClient; use PhpSpec\ObjectBehavior; -use Psr\Http\Message\ResponseInterface; class WebhooksApiSpec extends ObjectBehavior { - function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) { $this->beConstructedWith($guzzleClient, $requestGenerator); $guzzleClient->send($request)->willReturn($response); diff --git a/spec/NewTwitchApi/Webhooks/WebhooksSubscriptionApiSpec.php b/spec/NewTwitchApi/Webhooks/WebhooksSubscriptionApiSpec.php deleted file mode 100644 index 128c543..0000000 --- a/spec/NewTwitchApi/Webhooks/WebhooksSubscriptionApiSpec.php +++ /dev/null @@ -1,121 +0,0 @@ -beConstructedWith('client-id', 'client-secret', $guzzleClient); - } - - function it_validates_valid_signature() - { - $this->validateWebhookEventCallback( - 'sha256=4bce6127177f214c7e3efa547048148e9d607574412dedf93e67af17450473ba', - 'content' - )->shouldReturn(true); - } - - function it_rejects_invalid_signature() - { - $this->validateWebhookEventCallback( - 'sha256=invalidhash', - 'content' - )->shouldReturn(false); - } - - function it_subscribes_to_a_stream(Client $guzzleClient) - { - $guzzleClient->post('webhooks/hub', [ - 'headers' => [ - 'Authorization' => 'Bearer bearer-token', - 'Client-ID' => 'client-id', - ], - 'body' => '{"hub.callback":"https:\/\/redirect.url","hub.mode":"subscribe","hub.topic":"https:\/\/api.twitch.tv\/helix\/streams?user_id=12345","hub.lease_seconds":100,"hub.secret":"client-secret"}' - ])->shouldBeCalled(); - - $this->subscribeToStream('12345', 'https://redirect.url', 'bearer-token', 100); - } - - function it_subscribes_to_subscription_events(Client $guzzleClient) - { - $guzzleClient->post('webhooks/hub', [ - 'headers' => [ - 'Authorization' => 'Bearer bearer-token', - 'Client-ID' => 'client-id', - ], - 'body' => '{"hub.callback":"https:\/\/redirect.url","hub.mode":"subscribe","hub.topic":"https:\/\/api.twitch.tv\/helix\/subscriptions\/events?broadcaster_id=12345&first=1","hub.lease_seconds":100,"hub.secret":"client-secret"}' - ])->shouldBeCalled(); - - $this->subscribeToSubscriptionEvents('12345', 'https://redirect.url', 'bearer-token', 100); - } - - function it_subscribes_to_a_user(Client $guzzleClient) - { - $guzzleClient->post('webhooks/hub', [ - 'headers' => [ - 'Authorization' => 'Bearer bearer-token', - 'Client-ID' => 'client-id', - ], - 'body' => '{"hub.callback":"https:\/\/redirect.url","hub.mode":"subscribe","hub.topic":"https:\/\/api.twitch.tv\/helix\/users?id=12345","hub.lease_seconds":100,"hub.secret":"client-secret"}' - ])->shouldBeCalled(); - - $this->subscribeToUser('12345', 'https://redirect.url', 'bearer-token', 100); - } - - function it_subscribes_to_user_follows(Client $guzzleClient) - { - $guzzleClient->post('webhooks/hub', [ - 'headers' => [ - 'Authorization' => 'Bearer bearer-token', - 'Client-ID' => 'client-id', - ], - 'body' => '{"hub.callback":"https:\/\/redirect.url","hub.mode":"subscribe","hub.topic":"https:\/\/api.twitch.tv\/helix\/users\/follows?from_id=12345&to_id=54321&first=1","hub.lease_seconds":100,"hub.secret":"client-secret"}' - ])->shouldBeCalled(); - - $this->subscribeToUserFollows('12345', '54321', 1, 'https://redirect.url', 'bearer-token', 100); - } - - function it_unsubscribes_from_a_stream(Client $guzzleClient) - { - $guzzleClient->post('webhooks/hub', [ - 'headers' => [ - 'Authorization' => 'Bearer bearer-token', - 'Client-ID' => 'client-id', - ], - 'body' => '{"hub.callback":"https:\/\/redirect.url","hub.mode":"unsubscribe","hub.topic":"https:\/\/api.twitch.tv\/helix\/streams?user_id=12345"}' - ])->shouldBeCalled(); - - $this->unsubscribeFromStream('12345', 'https://redirect.url', 'bearer-token'); - } - - function it_unsubscribes_from_a_user(Client $guzzleClient) - { - $guzzleClient->post('webhooks/hub', [ - 'headers' => [ - 'Authorization' => 'Bearer bearer-token', - 'Client-ID' => 'client-id', - ], - 'body' => '{"hub.callback":"https:\/\/redirect.url","hub.mode":"unsubscribe","hub.topic":"https:\/\/api.twitch.tv\/helix\/users?id=12345"}' - ])->shouldBeCalled(); - - $this->unsubscribeFromUser('12345', 'https://redirect.url', 'bearer-token'); - } - - function it_unsubscribes_from_user_follows(Client $guzzleClient) - { - $guzzleClient->post('webhooks/hub', [ - 'headers' => [ - 'Authorization' => 'Bearer bearer-token', - 'Client-ID' => 'client-id', - ], - 'body' => '{"hub.callback":"https:\/\/redirect.url","hub.mode":"unsubscribe","hub.topic":"https:\/\/api.twitch.tv\/helix\/users\/follows?from_id=12345&to_id=54321&first=1"}' - ])->shouldBeCalled(); - - $this->unsubscribeFromUserFollows('12345', '54321', 1, 'https://redirect.url', 'bearer-token'); - } -} diff --git a/src/NewTwitchApi/HelixGuzzleClient.php b/src/NewTwitchApi/HelixGuzzleClient.php index 9909eca..7e41006 100644 --- a/src/NewTwitchApi/HelixGuzzleClient.php +++ b/src/NewTwitchApi/HelixGuzzleClient.php @@ -8,14 +8,41 @@ class HelixGuzzleClient { + private $client; private const BASE_URI = 'https://api.twitch.tv/helix/'; - public static function getClient(string $clientId, array $config = []): Client + public function __construct(string $clientId, array $config = [], string $baseUri = null) { - return new Client($config + [ - 'base_uri' => self::BASE_URI, - 'timeout' => 30, - 'headers' => ['Client-ID' => $clientId, 'Content-Type' => 'application/json'], - ]); + if ($baseUri == null) { + $baseUri = self::BASE_URI; + } + + $headers = [ + 'Client-ID' => $clientId, + 'Content-Type' => 'application/json', + ]; + + $client_config = [ + 'base_uri' => $baseUri, + 'headers' => $headers, + ]; + + if (isset($config['handler'])) { + $client_config = []; + } + + $client_config = array_merge($client_config, $config); + + $this->client = new Client($client_config); + } + + public function getConfig($option = null) + { + return $this->client->getConfig($option); + } + + public function send($request) + { + return $this->client->send($request); } } diff --git a/src/NewTwitchApi/NewTwitchApi.php b/src/NewTwitchApi/NewTwitchApi.php index 870d2c9..9d04eda 100644 --- a/src/NewTwitchApi/NewTwitchApi.php +++ b/src/NewTwitchApi/NewTwitchApi.php @@ -57,7 +57,7 @@ class NewTwitchApi private $webhooksApi; private $webhooksSubscriptionApi; - public function __construct(Client $helixGuzzleClient, string $clientId, string $clientSecret, Client $authGuzzleClient = null) + public function __construct(HelixGuzzleClient $helixGuzzleClient, string $clientId, string $clientSecret, Client $authGuzzleClient = null) { $requestGenerator = new RequestGenerator(); $this->oauthApi = new OauthApi($clientId, $clientSecret, $authGuzzleClient); diff --git a/src/NewTwitchApi/Resources/AbstractResource.php b/src/NewTwitchApi/Resources/AbstractResource.php index 310cca8..6db7eb0 100644 --- a/src/NewTwitchApi/Resources/AbstractResource.php +++ b/src/NewTwitchApi/Resources/AbstractResource.php @@ -4,8 +4,8 @@ namespace NewTwitchApi\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; +use NewTwitchApi\HelixGuzzleClient; use NewTwitchApi\RequestGenerator; use Psr\Http\Message\ResponseInterface; @@ -14,7 +14,7 @@ abstract class AbstractResource protected $guzzleClient; private $requestGenerator; - public function __construct(Client $guzzleClient, RequestGenerator $requestGenerator) + public function __construct(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator) { $this->guzzleClient = $guzzleClient; $this->requestGenerator = $requestGenerator; diff --git a/src/NewTwitchApi/Webhooks/WebhooksSubscriptionApi.php b/src/NewTwitchApi/Webhooks/WebhooksSubscriptionApi.php index 46080c7..2430f7c 100644 --- a/src/NewTwitchApi/Webhooks/WebhooksSubscriptionApi.php +++ b/src/NewTwitchApi/Webhooks/WebhooksSubscriptionApi.php @@ -4,7 +4,6 @@ namespace NewTwitchApi\Webhooks; -use GuzzleHttp\Client; use NewTwitchApi\HelixGuzzleClient; class WebhooksSubscriptionApi @@ -16,7 +15,7 @@ class WebhooksSubscriptionApi private $secret; private $guzzleClient; - public function __construct(string $clientId, string $secret, Client $guzzleClient = null) + public function __construct(string $clientId, string $secret, HelixGuzzleClient $guzzleClient = null) { $this->clientId = $clientId; $this->secret = $secret; diff --git a/test/NewTwitchApi/Resources/UsersTest.php b/test/NewTwitchApi/Resources/UsersTest.php index 7de359e..4ac338d 100644 --- a/test/NewTwitchApi/Resources/UsersTest.php +++ b/test/NewTwitchApi/Resources/UsersTest.php @@ -4,10 +4,10 @@ namespace NewTwitchApi\Tests\Resources; -use GuzzleHttp\Client; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; +use NewTwitchApi\HelixGuzzleClient; use NewTwitchApi\RequestGenerator; use NewTwitchApi\Resources\UsersApi; use PHPUnit\Framework\TestCase; @@ -16,7 +16,7 @@ class UsersTest extends TestCase { public function testGetUserByIdShouldReturnSuccessfulResponseWithUserData(): void { - $users = new UsersApi($this->getGuzzleClientWithMockUserResponse(), $this->getRequestGenerator()); + $users = new UsersApi($this->getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator()); $response = $users->getUserById('TEST_APP_ACCESS_TOKEN', '44322889'); $this->assertEquals(200, $response->getStatusCode()); @@ -26,7 +26,7 @@ public function testGetUserByIdShouldReturnSuccessfulResponseWithUserData(): voi public function testGetUserByUsernameShouldReturnSuccessfulResponseWithUserData(): void { - $users = new UsersApi($this->getGuzzleClientWithMockUserResponse(), $this->getRequestGenerator()); + $users = new UsersApi($this->getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator()); $response = $users->getUserByUsername('TEST_APP_ACCESS_TOKEN', 'dallas'); $this->assertEquals(200, $response->getStatusCode()); @@ -34,7 +34,7 @@ public function testGetUserByUsernameShouldReturnSuccessfulResponseWithUserData( $this->assertEquals(44322889, $contents->data[0]->id); } - private function getGuzzleClientWithMockUserResponse(): Client + private function getHelixGuzzleClientWithMockUserResponse(): HelixGuzzleClient { // Example response from https://dev.twitch.tv/docs/api/reference/#get-users $getUserReponseJson = << $handler]); + return new HelixGuzzleClient('TEST_CLIENT_ID', ['handler' => $handler]); } private function getRequestGenerator(): RequestGenerator