Skip to content

Commit

Permalink
more tests for proxy interface
Browse files Browse the repository at this point in the history
  • Loading branch information
vazaha-nl committed Aug 5, 2023
1 parent 4ec97c2 commit 1bdeaf2
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/ApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions tests/OAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
31 changes: 31 additions & 0 deletions tests/PagingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions tests/PreferencesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
18 changes: 18 additions & 0 deletions tests/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1bdeaf2

Please sign in to comment.