From 1bdeaf21244a76e53264f980e236bdbd396f0a32 Mon Sep 17 00:00:00 2001 From: Lennart Hengstmengel Date: Sat, 5 Aug 2023 19:28:24 +0200 Subject: [PATCH] more tests for proxy interface --- tests/ApiClientTest.php | 33 +++++++++++++++++++++++++++++++++ tests/OAuthTest.php | 11 +++++++++++ tests/PagingTest.php | 31 +++++++++++++++++++++++++++++++ tests/PreferencesTest.php | 12 ++++++++++++ tests/StatusTest.php | 18 ++++++++++++++++++ 5 files changed, 105 insertions(+) diff --git a/tests/ApiClientTest.php b/tests/ApiClientTest.php index 08a5a90..657f893 100644 --- a/tests/ApiClientTest.php +++ b/tests/ApiClientTest.php @@ -77,4 +77,37 @@ public function testGetLists(): void ->send(new ListsGetRequest()); self::assertInstanceOf(ListResult::class, $response); } + + public function testGetAccountAndListUsingProxy(): void + { + $account = $this->apiClient + ->setBaseUri('https://example.org') + ->methods() + ->accounts() + ->get('foo'); + + self::assertInstanceOf(AccountModel::class, $account); + self::assertEquals('23634', $account->id); + + $list = $this->apiClient + ->setBaseUri('https://example.org') + ->methods() + ->lists() + ->get() + ->first(); + + self::assertInstanceOf(ListModel::class, $list); + self::assertEquals(12345, $list->id); + self::assertEquals('Test List', $list->title); + } + + public function testGetListsUsingProxy(): void + { + $response = $this->apiClient + ->setBaseUri('https://example.org') + ->methods() + ->lists() + ->get(); + self::assertInstanceOf(ListResult::class, $response); + } } diff --git a/tests/OAuthTest.php b/tests/OAuthTest.php index 22c9f80..be4f334 100644 --- a/tests/OAuthTest.php +++ b/tests/OAuthTest.php @@ -35,4 +35,15 @@ public function testCreateOAuthToken(): void self::assertInstanceOf(TokenModel::class, $model); self::assertEquals('test_token', $model->access_token); } + + public function testCreateOAuthTokenUsingProxy(): void + { + $model = $this->apiClient + ->setBaseUri('https://example.org') + ->methods() + ->oauth() + ->token('client_credentials', 'code', 'clientid', 'clientsecret', 'redirecturi'); + self::assertInstanceOf(TokenModel::class, $model); + self::assertEquals('test_token', $model->access_token); + } } diff --git a/tests/PagingTest.php b/tests/PagingTest.php index d9972f2..eb86df0 100644 --- a/tests/PagingTest.php +++ b/tests/PagingTest.php @@ -71,4 +71,35 @@ public function testPagingRequestAndResult(): void $nextResult = $nextResult->getNextResult(); self::assertNull($nextResult); } + + public function testPagingRequestAndResultUsingProxy(): void + { + $this->apiClient->setBaseUri('https://example.org'); + + $result = $this->apiClient + ->methods() + ->accounts() + ->following('testid'); + + self::assertInstanceOf(AccountResult::class, $result); + + $accounts = $result->getModels(); + self::assertInstanceOf(AccountModel::class, $accounts[0]); + self::assertEquals(1, $accounts[0]->id); + + $previousResult = $result->getPreviousResult(); + self::assertNull($previousResult); + + $nextResult = $result->getNextResult(); + self::assertInstanceOf(AccountResult::class, $nextResult); + + $accounts = $nextResult->getModels(); + self::assertEquals(3, $accounts[0]->id); + + $previousResult = $nextResult->getPreviousResult(); + self::assertInstanceOf(AccountResult::class, $nextResult); + + $nextResult = $nextResult->getNextResult(); + self::assertNull($nextResult); + } } diff --git a/tests/PreferencesTest.php b/tests/PreferencesTest.php index e312820..9cc88ed 100644 --- a/tests/PreferencesTest.php +++ b/tests/PreferencesTest.php @@ -39,4 +39,16 @@ public function testGetPreferences(): void self::assertInstanceOf(PreferencesModel::class, $preferences); self::assertEquals('public', $preferences->posting_default_visibility); } + + public function testGetPreferencesUsingProxy(): void + { + $preferences = $this->apiClient + ->setBaseUri('foo') + ->methods() + ->preferences() + ->get(); + + self::assertInstanceOf(PreferencesModel::class, $preferences); + self::assertEquals('public', $preferences->posting_default_visibility); + } } diff --git a/tests/StatusTest.php b/tests/StatusTest.php index aff7907..a928f68 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -39,4 +39,22 @@ public function testGetStatus(): void self::assertInstanceOf(TagModel::class, $status->tags->first()); self::assertEquals('tagname1', $status->tags->first()->name); } + + public function testGetStatusUsingProxy(): void + { + $client = $this->createMockClient([ + $this->createJsonResponseFromFile(200, 'status.json'), + ])->setBaseUri('http://example.org'); + + $status = $client->methods()->statuses()->get('foo'); + + self::assertInstanceOf(StatusModel::class, $status); + self::assertEquals('103270115826048975', $status->id); + self::assertInstanceOf(AccountModel::class, $status->account); + self::assertEquals('1', $status->account->id); + self::assertInstanceOf(DateTimeInterface::class, $status->created_at); + self::assertInstanceOf(TagCollection::class, $status->tags); + self::assertInstanceOf(TagModel::class, $status->tags->first()); + self::assertEquals('tagname1', $status->tags->first()->name); + } }