Skip to content

Commit

Permalink
fix: oembed query not working (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
atymic authored Apr 15, 2021
1 parent 335feed commit fec288a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.1.3]

### Fixed

Fixed `getOembed` querying the wrong hostname/endpoint [#345](https://github.com/atymic/twitter/pull/345)


## [3.1.2]

### Fixed
Expand Down
6 changes: 1 addition & 5 deletions src/ApiV1/Traits/StatusTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,7 @@ public function getOembed($parameters = [])
throw new BadMethodCallException('Parameter required missing : url');
}

// TODO re-implement this
$this->tconfig['API_URL'] = 'publish.twitter.com';
$this->tconfig['API_VERSION'] = '';

return $this->get('oembed', $parameters);
return $this->directQuery('https://publish.twitter.com/oembed', 'GET', $parameters);
}

/**
Expand Down
29 changes: 16 additions & 13 deletions tests/Unit/ApiV1/Service/TwitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class TwitterTest extends TestCase
*/
public function testGetUsersWithScreenName(): void
{
$twitter = $this->getTwitterExpecting(
$twitter = $this->getTwitterExpectingQueryCall(
'users/show',
[
'screen_name' => 'my_screen_name',
Expand All @@ -46,7 +46,7 @@ public function testGetUsersWithScreenName(): void
*/
public function testGetUsersWithId(): void
{
$twitter = $this->getTwitterExpecting(
$twitter = $this->getTwitterExpectingQueryCall(
'users/show',
[
'user_id' => 1234567890,
Expand Down Expand Up @@ -83,7 +83,7 @@ public function testGetUsersInvalid(): void
*/
public function testGetUsersLookupWithIds(): void
{
$twitter = $this->getTwitterExpecting(
$twitter = $this->getTwitterExpectingQueryCall(
'users/lookup',
[
'user_id' => '1,2,3,4',
Expand All @@ -103,7 +103,7 @@ public function testGetUsersLookupWithIds(): void
*/
public function testGetUsersLookupWithScreenNames(): void
{
$twitter = $this->getTwitterExpecting(
$twitter = $this->getTwitterExpectingQueryCall(
'users/lookup',
[
'screen_name' => 'me,you,everybody',
Expand Down Expand Up @@ -305,12 +305,15 @@ public function providerGetListMemberBad(): array
*/
public function testGetOembed(): void
{
$twitter = $this->getTwitterExpecting(
'oembed',
[
'url' => 'https://twitter.com/jxeeno/status/1343506068236689408',
]
);
$twitter = $this->getTwitter();

$twitter->expects(self::once())
->method('directQuery')
->with(
'https://publish.twitter.com/oembed',
'GET',
['url' => 'https://twitter.com/jxeeno/status/1343506068236689408']
);

$twitter->getOembed(['url' => 'https://twitter.com/jxeeno/status/1343506068236689408']);
}
Expand All @@ -322,7 +325,7 @@ public function testGetOembed(): void
protected function getTwitter(): MockObject
{
return $this->getMockBuilder(Twitter::class)
->onlyMethods(['query'])
->onlyMethods(['query', 'directQuery'])
->disableOriginalConstructor()
->getMock();
}
Expand All @@ -331,7 +334,7 @@ protected function getTwitter(): MockObject
* @return MockObject|Twitter
* @throws Exception
*/
protected function getTwitterExpecting(string $endpoint, array $queryParams): MockObject
protected function getTwitterExpectingQueryCall(string $endpoint, array $queryParams): MockObject
{
$twitter = $this->getTwitter();
$twitter->expects(self::once())
Expand All @@ -350,7 +353,7 @@ protected function getTwitterExpecting(string $endpoint, array $queryParams): Mo
*/
private function paramTest(string $endpoint, string $testedMethod, array $params): void
{
$twitter = $this->getTwitterExpecting($endpoint, $params);
$twitter = $this->getTwitterExpectingQueryCall($endpoint, $params);

$twitter->{$testedMethod}($params);
}
Expand Down

0 comments on commit fec288a

Please sign in to comment.