1<?php
2/**
3 * This file is part of the Tmdb PHP API created by Michael Roterman.
4 *
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
7 *
8 * @package Tmdb
9 * @author Michael Roterman <michael@wtfz.net>
10 * @copyright (c) 2013, Michael Roterman
11 * @version 0.0.1
12 */
13namespace Tmdb\Tests\Repository;
14
15use Tmdb\Model\Tv\Episode;
16use Tmdb\Model\Tv\Season;
17use Tmdb\Model\Tv;
18
19class TvEpisodeRepositoryTest extends TestCase
20{
21    const TV_ID      = 3572;
22    const SEASON_NUMBER  = 1;
23    const EPISODE_NUMBER = 1;
24
25    /**
26     * @test
27     */
28    public function shouldLoadTvEpisode()
29    {
30        $repository = $this->getRepositoryWithMockedHttpAdapter();
31
32        $this->getAdapter()->expects($this->once())
33            ->method('get')
34            ->with($this->getRequest(
35                'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER,
36                ['append_to_response' => 'credits,external_ids,images,changes,videos']
37            ))
38        ;
39
40        $repository->load(self::TV_ID, self::SEASON_NUMBER, self::EPISODE_NUMBER);
41    }
42
43    /**
44     * @test
45     */
46    public function shouldBeAbleToLoadTvSeasonWithTvAndSeason()
47    {
48        $repository = $this->getRepositoryWithMockedHttpAdapter();
49
50        $this->getAdapter()->expects($this->once())
51            ->method('get')
52            ->with($this->getRequest(
53                'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER,
54                ['append_to_response' => 'credits,external_ids,images,changes,videos']
55            ))
56        ;
57
58        $tv = new Tv();
59        $tv->setId(self::TV_ID);
60
61        $season = new Season();
62        $season->setSeasonNumber(self::SEASON_NUMBER);
63
64        $episode = new Episode();
65        $episode->setEpisodeNumber(self::EPISODE_NUMBER);
66
67        $repository->load($tv, $season, $episode);
68    }
69
70    /**
71     * @test
72     */
73    public function shouldGetCredits()
74    {
75        $repository = $this->getRepositoryWithMockedHttpAdapter();
76
77        $this->getAdapter()->expects($this->once())
78            ->method('get')
79            ->with($this->getRequest(
80                'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER . '/credits'
81            ))
82        ;
83
84        $tv = new Tv();
85        $tv->setId(self::TV_ID);
86
87        $season = new Season();
88        $season->setSeasonNumber(self::SEASON_NUMBER);
89
90        $episode = new Episode();
91        $episode->setEpisodeNumber(self::EPISODE_NUMBER);
92
93        $repository->getCredits($tv, $season, $episode);
94    }
95
96    /**
97     * @test
98     */
99    public function shouldGetExternalIds()
100    {
101        $repository = $this->getRepositoryWithMockedHttpAdapter();
102
103        $this->getAdapter()->expects($this->once())
104            ->method('get')
105            ->with($this->getRequest(
106                'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER . '/external_ids'
107            ))
108        ;
109
110        $tv = new Tv();
111        $tv->setId(self::TV_ID);
112
113        $season = new Season();
114        $season->setSeasonNumber(self::SEASON_NUMBER);
115
116        $episode = new Episode();
117        $episode->setEpisodeNumber(self::EPISODE_NUMBER);
118
119        $repository->getExternalIds($tv, $season, $episode);
120    }
121
122    /**
123     * @test
124     */
125    public function shouldGetImages()
126    {
127        $repository = $this->getRepositoryWithMockedHttpAdapter();
128
129        $this->getAdapter()->expects($this->once())
130            ->method('get')
131            ->with($this->getRequest(
132                'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER . '/images'
133            ))
134        ;
135
136        $tv = new Tv();
137        $tv->setId(self::TV_ID);
138
139        $season = new Season();
140        $season->setSeasonNumber(self::SEASON_NUMBER);
141
142        $episode = new Episode();
143        $episode->setEpisodeNumber(self::EPISODE_NUMBER);
144
145        $repository->getImages($tv, $season, $episode);
146    }
147
148    /**
149     * @test
150     */
151    public function shouldGetVideos()
152    {
153        $repository = $this->getRepositoryWithMockedHttpAdapter();
154
155        $this->getAdapter()->expects($this->once())
156            ->method('get')
157            ->with($this->getRequest(
158                'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER . '/videos'
159            ))
160        ;
161
162        $tv = new Tv();
163        $tv->setId(self::TV_ID);
164
165        $season = new Season();
166        $season->setSeasonNumber(self::SEASON_NUMBER);
167
168        $episode = new Episode();
169        $episode->setEpisodeNumber(self::EPISODE_NUMBER);
170
171        $repository->getVideos($tv, $season, $episode);
172    }
173
174    /**
175     * @expectedException Tmdb\Exception\RuntimeException
176     * @test
177     */
178    public function shouldThrowExceptionWhenConditionsNotMet()
179    {
180        $repository = $this->getRepositoryWithMockedHttpClient();
181
182        $tv = new Tv();
183        $tv->setId(self::TV_ID);
184
185        $season = new Season();
186        $season->setSeasonNumber(self::SEASON_NUMBER);
187
188        $repository->load($tv, $season, null);
189    }
190
191    /**
192     * @expectedException Tmdb\Exception\RuntimeException
193     * @test
194     */
195    public function shouldThrowExceptionWhenConditionsNotMetAll()
196    {
197        $repository = $this->getRepositoryWithMockedHttpClient();
198
199        $repository->load(null, null, null);
200    }
201
202    protected function getApiClass()
203    {
204        return 'Tmdb\Api\TvEpisode';
205    }
206
207    protected function getRepositoryClass()
208    {
209        return 'Tmdb\Repository\TvEpisodeRepository';
210    }
211}
212