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\Tests\TestCase as Base; 16 17use Tmdb\Client; 18 19abstract class TestCase extends Base 20{ 21 protected $repository; 22 23 /** 24 * @var Client 25 */ 26 private $_client; 27 28 abstract protected function getRepositoryClass(); 29 30 /** 31 * Return regular objects but replace the http adapter to not actually send requests 32 * 33 * @param array $methods 34 * @param null $sessionToken 35 * @return mixed 36 */ 37 protected function getRepositoryWithMockedHttpAdapter(array $methods = [], $sessionToken = null) 38 { 39 $this->_client = $this->getClientWithMockedHttpClient($methods); 40 41 if ($sessionToken) { 42 $this->_client->setSessionToken($sessionToken); 43 } 44 45 $repositoryClass = $this->getRepositoryClass(); 46 47 return new $repositoryClass($this->_client); 48 } 49 50 protected function getRepositoryWithMockedHttpClient() 51 { 52 $class = $this->getRepositoryClass(); 53 54 return new $class($this->getMockedTmdbClient()); 55 } 56 57 protected function getRepositoryMock($client = null, array $methods = []) 58 { 59 if ($client == null) { 60 $client = $this->getMockedTmdbClient(); 61 } 62 63 return $this->getMock($this->getRepositoryClass(), array_merge(['getApi'], $methods), [$client]); 64 } 65 66 /** 67 * Shortcut to obtain the http client adapter 68 * 69 * @return \Tmdb\HttpClient\Adapter\AdapterInterface 70 */ 71 protected function getAdapter() 72 { 73 return $this->_client->getHttpClient()->getAdapter(); 74 } 75} 76