Skip to content

Commit

Permalink
Merge pull request #142 from nicklaw5/v7
Browse files Browse the repository at this point in the history
v7.0.0: Endpoint Coverage
  • Loading branch information
Brandin authored Aug 29, 2022
2 parents 7b10a2a + d6e16f7 commit 41c1f59
Show file tree
Hide file tree
Showing 19 changed files with 756 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
php: ['7.4', '8.0']
php: ['7.4', '8.0', '8.1']

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ composer-test.lock
vendor/
.idea
.DS_STORE
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
composer.lock
composer.lock
5 changes: 3 additions & 2 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
->in('test/')
;

return PhpCsFixer\Config::create()
->setRules([
$config = new PhpCsFixer\Config();

return $config->setRules([
'@PSR2' => true,
'@Symfony' => true,
'phpdoc_annotation_without_dot' => false,
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
test: cs-check test-phpunit test-phpspec

cs-check:
vendor/bin/php-cs-fixer fix --diff --diff-format=udiff --dry-run
vendor/bin/php-cs-fixer fix --diff --dry-run

test-phpunit:
vendor/bin/phpunit
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"guzzlehttp/guzzle": "~6.0|~7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.13",
"phpspec/phpspec": "^6.1",
"phpunit/phpunit": "^8.5"
"friendsofphp/php-cs-fixer": "^3.10",
"phpspec/phpspec": "^7.2",
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
Expand Down
48 changes: 48 additions & 0 deletions spec/TwitchApi/Resources/ChatApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,52 @@ function it_should_get_global_chat_badges(RequestGenerator $requestGenerator, Re
$requestGenerator->generate('GET', 'chat/badges/global', 'TEST_TOKEN', [], [])->willReturn($request);
$this->getGlobalChatBadges('TEST_TOKEN')->shouldBe($response);
}

function it_should_get_chat_settings(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'chat/settings', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
$this->getChatSettings('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_get_chat_settings_with_moderator_id(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'chat/settings', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456']], [])->willReturn($request);
$this->getChatSettings('TEST_TOKEN', '123', '456')->shouldBe($response);
}

function it_should_update_chat_settings_with_one_setting(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('PATCH', 'chat/settings', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456']], [['key' => 'emote_mode', 'value' => true]])->willReturn($request);
$this->updateChatSettings('TEST_TOKEN', '123', '456', ['emote_mode' => true])->shouldBe($response);
}

function it_should_update_chat_settings_with_multiple_settings(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('PATCH', 'chat/settings', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456']], [['key' => 'emote_mode', 'value' => true], ['key' => 'slow_mode_wait_time', 'value' => 10]])->willReturn($request);
$this->updateChatSettings('TEST_TOKEN', '123', '456', ['emote_mode' => true, 'slow_mode_wait_time' => 10])->shouldBe($response);
}

function it_should_send_a_chat_announcement(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('POST', 'chat/announcements', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456']], [['key' => 'message', 'value' => 'Hello World']])->willReturn($request);
$this->sendChatAnnouncement('TEST_TOKEN', '123', '456', 'Hello World')->shouldBe($response);
}

function it_should_send_a_chat_announcement_with_a_color(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('POST', 'chat/announcements', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456']], [['key' => 'message', 'value' => 'Hello World'], ['key' => 'color', 'value' => 'red']])->willReturn($request);
$this->sendChatAnnouncement('TEST_TOKEN', '123', '456', 'Hello World', 'red')->shouldBe($response);
}

function it_should_get_a_users_chat_color(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'chat/color', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request);
$this->getUserChatColor('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_update_a_users_chat_color(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('PUT', 'chat/color', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'color', 'value' => 'red']], [])->willReturn($request);
$this->updateUserChatColor('TEST_TOKEN', '123', 'red')->shouldBe($response);
}
}
38 changes: 37 additions & 1 deletion spec/TwitchApi/Resources/EventSubApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ function it_should_get_event_sub_subscription_with_type(RequestGenerator $reques
$this->getEventSubSubscription('TEST_TOKEN', null, 'channel.update')->shouldBe($response);
}

function it_should_get_event_sub_subscription_with_user_id(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'eventsub/subscriptions', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '789']], [])->willReturn($request);
$this->getEventSubSubscription('TEST_TOKEN', null, null, null, '789')->shouldBe($response);
}

function it_should_get_event_sub_subscription_with_after(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'eventsub/subscriptions', 'TEST_TOKEN', [['key' => 'after', 'value' => 'abc']], [])->willReturn($request);
Expand Down Expand Up @@ -249,7 +255,37 @@ function it_should_subscribe_to_user_update(RequestGenerator $requestGenerator,

function it_should_subscribe_to_extension_bits_transaction_create(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->createEventSubSubscription('extension.bits_transaction.create', 'beta', ['extension_client_id' => 'deadbeef'], $requestGenerator)->willReturn($request);
$this->createEventSubSubscription('extension.bits_transaction.create', '1', ['extension_client_id' => 'deadbeef'], $requestGenerator)->willReturn($request);
$this->subscribeToExtensionBitsTransactionCreate($this->bearer, $this->secret, $this->callback, 'deadbeef')->shouldBe($response);
}

function it_should_subscribe_to_user_authorization_revoke(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->createEventSubSubscription('user.authorization.revoke', '1', ['client_id' => '12345'], $requestGenerator)->willReturn($request);
$this->subscribeToUserAuthorizationRevoke($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
}

function it_should_subscribe_to_user_authorization_grant(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->createEventSubSubscription('user.authorization.grant', '1', ['client_id' => '12345'], $requestGenerator)->willReturn($request);
$this->subscribeToUserAuthorizationGrant($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
}

function it_should_subscribe_to_channel_goal_begin(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->createEventSubSubscription('channel.goal.begin', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
$this->subscribeToChannelGoalBegin($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
}

function it_should_subscribe_to_channel_goal_progress(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->createEventSubSubscription('channel.goal.progress', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
$this->subscribeToChannelGoalProgress($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
}

function it_should_subscribe_to_channel_goal_end(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->createEventSubSubscription('channel.goal.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
$this->subscribeToChannelGoalEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
}
}
30 changes: 30 additions & 0 deletions spec/TwitchApi/Resources/HypeTrainApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace spec\TwitchApi\Resources;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use TwitchApi\RequestGenerator;
use TwitchApi\HelixGuzzleClient;
use PhpSpec\ObjectBehavior;

class HypeTrainApiSpec extends ObjectBehavior
{
function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->beConstructedWith($guzzleClient, $requestGenerator);
$guzzleClient->send($request)->willReturn($response);
}

function it_should_get_hype_train_events(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'hypetrain/events', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
$this->getHypeTrainEvents('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_get_hype_train_events_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'hypetrain/events', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'cursor', 'value' => 'abc']], [])->willReturn($request);
$this->getHypeTrainEvents('TEST_TOKEN', '123', 100, 'abc')->shouldBe($response);
}
}
Loading

0 comments on commit 41c1f59

Please sign in to comment.