Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Tmdb/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function setOptions(array $options = [])
/**
* Construct the http client
*
* In case you are implementing your own adapter, the base url will be passed on through the $parameters array
* In case you are implementing your own adapter, the base url will be passed on through the options bag
* at every call in the respective get / post methods etc. of the adapter.
*
* @return void
Expand Down Expand Up @@ -334,7 +334,7 @@ protected function postResolve(array $options = [])

if (!$this->options['adapter']) {
$this->options['adapter'] = new GuzzleAdapter(
new \GuzzleHttp\Client(['base_url' => $this->options['base_url']])
new \GuzzleHttp\Client()
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/Tmdb/HttpClient/Adapter/GuzzleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function getConfiguration(Request $request)
$this->request = $request;

return [
'base_uri' => $request->getOptions()->get('base_url'),
'headers' => $request->getHeaders()->all(),
'query' => $request->getParameters()->all()
];
Expand Down
2 changes: 2 additions & 0 deletions lib/Tmdb/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class HttpClient
* The base url to built requests on top of
*
* @var null
*
* @deprecated since 2.0.19, to be removed in 3.0. Use `base_url` of the request options instead.
*/
protected $base_url = null;

Expand Down
23 changes: 23 additions & 0 deletions test/Tmdb/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ public function assertInstances()
);
}

/**
* @test
*/
public function shouldRespectSecureClientOption()
{
$token = new ApiToken(self::API_TOKEN);

$client = new \Tmdb\Client($token);
$options = $client->getOptions();
$this->assertTrue(true === $options['secure']);
$this->assertTrue(false !== strpos($options['base_url'], 'https://'));

$client = new \Tmdb\Client($token, ['secure' => true]);
$options = $client->getOptions();
$this->assertTrue(true === $options['secure']);
$this->assertTrue(false !== strpos($options['base_url'], 'https://'));

$client = new \Tmdb\Client($token, ['secure' => false]);
$options = $client->getOptions();
$this->assertTrue(false === $options['secure']);
$this->assertTrue(false !== strpos($options['base_url'], 'http://'));
}

public function testShouldSwitchHttpScheme()
{
$token = new ApiToken(self::API_TOKEN);
Expand Down
13 changes: 10 additions & 3 deletions test/Tmdb/Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ protected function getMockedHttpClient(array $methods = [])
/**
* Get the expected request that will deliver a response
*
* @param $path
* @param string $url
* @param array $parameters
* @param string $method
* @param array $headers
* @param null $body
* @return Request
*/
protected function getRequest($path, $parameters = [], $method = 'GET', $headers = [], $body = null)
protected function getRequest($url, $parameters = [], $method = 'GET', $headers = [], $body = null)
{
if (
$method == 'POST' ||
Expand All @@ -165,6 +165,13 @@ protected function getRequest($path, $parameters = [], $method = 'GET', $headers
$headers['Accept'] = 'application/json';
$headers['User-Agent'] = sprintf('wtfzdotnet/php-tmdb-api (v%s)', Client::VERSION);

$baseUrl = 'https://api.themoviedb.org/3/';
if (strpos($url, $baseUrl) === 0) {
$path = substr($url, strlen($baseUrl));
} else {
$path = $url;
}

$request = new Request(
$path,
$method,
Expand All @@ -190,7 +197,7 @@ protected function getRequest($path, $parameters = [], $method = 'GET', $headers
],
'adapter' => $this->getMock('Tmdb\HttpClient\Adapter\AdapterInterface'),
'host' => 'api.themoviedb.org/3/',
'base_url' => 'https://api.themoviedb.org/3/',
'base_url' => $baseUrl,
'session_token' => null,
'event_dispatcher' => $this->eventDispatcher
]));
Expand Down