-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathClientTest.php
175 lines (153 loc) · 5.41 KB
/
ClientTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 4.0.0
*/
namespace Tmdb\Tests;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Tmdb\Client;
use Tmdb\Token\Api\ApiToken;
use Tmdb\Token\Session\GuestSessionToken;
use Tmdb\Token\Session\SessionToken;
class ClientTest extends TestCase
{
public const API_TOKEN = 'abcdef';
public const SESSION_TOKEN = '80b2bf99520cd795ff54e31af97917bc9e3a7c8c';
/**
* @var Client
*/
private $client = null;
public function setUp(): void
{
$token = new ApiToken(self::API_TOKEN);
$sessionToken = new GuestSessionToken(self::SESSION_TOKEN);
$eventDispatcher = new EventDispatcher();
$client = new Client(
[
'api_token' => $token,
'guest_session_token' => $sessionToken,
'event_dispatcher' => [
'adapter' => $eventDispatcher
]
]
);
$this->client = $client;
}
/**
* @test
*/
public function shouldNotHaveToPassHttpClientToConstructor()
{
$this->assertInstanceOf('Tmdb\HttpClient\HttpClient', $this->client->getHttpClient());
}
/**
* @test
*/
public function shouldContainGuestSessionToken()
{
$this->assertInstanceOf('Tmdb\Token\Session\GuestSessionToken', $this->client->getGuestSessionToken());
$this->assertEquals(self::SESSION_TOKEN, $this->client->getGuestSessionToken()->getToken());
}
/**
* @test
*/
public function assertInstances()
{
$this->assertInstancesOf(
$this->client,
[
'getAccountApi' => 'Tmdb\Api\Account',
'getAuthenticationApi' => 'Tmdb\Api\Authentication',
'getCertificationsApi' => 'Tmdb\Api\Certifications',
'getChangesApi' => 'Tmdb\Api\Changes',
'getCollectionsApi' => 'Tmdb\Api\Collections',
'getCompaniesApi' => 'Tmdb\Api\Companies',
'getConfigurationApi' => 'Tmdb\Api\Configuration',
'getCreditsApi' => 'Tmdb\Api\Credits',
'getDiscoverApi' => 'Tmdb\Api\Discover',
'getFindApi' => 'Tmdb\Api\Find',
'getGenresApi' => 'Tmdb\Api\Genres',
'getGuestSessionApi' => 'Tmdb\Api\GuestSession',
'getJobsApi' => 'Tmdb\Api\Jobs',
'getKeywordsApi' => 'Tmdb\Api\Keywords',
'getListsApi' => 'Tmdb\Api\Lists',
'getMoviesApi' => 'Tmdb\Api\Movies',
'getNetworksApi' => 'Tmdb\Api\Networks',
'getPeopleApi' => 'Tmdb\Api\People',
'getReviewsApi' => 'Tmdb\Api\Reviews',
'getSearchApi' => 'Tmdb\Api\Search',
'getTimezonesApi' => 'Tmdb\Api\Timezones',
'getTvApi' => 'Tmdb\Api\Tv',
'getTvSeasonApi' => 'Tmdb\Api\TvSeason',
'getTvEpisodeApi' => 'Tmdb\Api\TvEpisode',
]
);
}
/**
* @test
*/
public function shouldRespectSecureClientOption()
{
$client = new Client(
[
'api_token' => new ApiToken('test'),
'event_dispatcher' => ['adapter' => new EventDispatcher()]
]
);
$options = $client->getOptions();
$this->assertTrue(true === $options['secure']);
$this->assertTrue(false !== strpos($options['base_uri'], 'https://'));
$client = new Client(
[
'api_token' => new ApiToken('test'),
'secure' => true,
'event_dispatcher' => ['adapter' => new EventDispatcher()]
]
);
$options = $client->getOptions();
$this->assertTrue(true === $options['secure']);
$this->assertTrue(false !== strpos($options['base_uri'], 'https://'));
$client = new Client(
[
'api_token' => new ApiToken('test'),
'secure' => false,
'event_dispatcher' => ['adapter' => new EventDispatcher()]
]
);
$options = $client->getOptions();
$this->assertTrue(false === $options['secure']);
$this->assertTrue(false !== strpos($options['base_uri'], 'http://'));
}
public function testShouldSwitchHttpScheme()
{
$client = new Client(
[
'api_token' => new ApiToken(self::API_TOKEN),
'event_dispatcher' => ['adapter' => new EventDispatcher()]
]
);
$options = $client->getOptions();
$this->assertEquals('https://api.themoviedb.org/3', $options['base_uri']);
$options['secure'] = false;
$client = new Client($options);
$options = $client->getOptions();
$this->assertEquals('http://api.themoviedb.org/3', $options['base_uri']);
}
/**
* @test
*/
public function shouldBeAbleGetOption()
{
$token = $this->client->getOption('api_token');
$invalidOption = $this->client->getOption('invalid_key');
$this->assertEquals(self::API_TOKEN, $token);
$this->assertEquals(null, $invalidOption);
}
}