Skip to content

Commit

Permalink
Small issues / improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Mar 2, 2014
1 parent 8ebbbed commit bc8be43
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
8 changes: 7 additions & 1 deletion lib/Tmdb/ApiToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @version 0.0.1
*/
namespace Tmdb;
use Tmdb\Exception\RuntimeException;

/**
* Class ApiToken
Expand All @@ -31,11 +32,16 @@ public function __construct($api_token = null)
}

/**
* @param null $apiToken
* @param string $apiToken
* @throws RuntimeException
* @return $this
*/
public function setToken($apiToken)
{
if (!is_string($apiToken)) {
throw new RuntimeException('The Apitoken must be set.');
}

$this->apiToken = $apiToken;

return $this;
Expand Down
12 changes: 6 additions & 6 deletions lib/Tmdb/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ private function constructHttpClient(ClientInterface $httpClient = null)

if ($this->cacheEnabled && !empty($this->cachePath)) {
if (!class_exists('Doctrine\Common\Cache\FilesystemCache')) {
/** @codeCoverageIgnoreStart */
//@codeCoverageIgnoreStart
throw new RuntimeException(
'Could not find the doctrine cache library,
have you added doctrine-cache to your composer.json?'
);
/** @codeCoverageIgnoreEnd */
//@codeCoverageIgnoreEnd
}

$cachePlugin = new CachePlugin(array(
Expand All @@ -173,16 +173,16 @@ private function constructHttpClient(ClientInterface $httpClient = null)

if ($this->logEnabled && !empty($this->logPath)) {
if (empty($this->logger) && !class_exists('\Monolog\Logger')) {
/** @codeCoverageIgnoreStart */
//@codeCoverageIgnoreStart
throw new RuntimeException(
'Could not find any logger set and the monolog logger library was not found
to provide a default, you have to set a custom logger on the client or
have you forgot adding monolog to your composer.json?'
);
/** @codeCoverageIgnoreEnd */
//@codeCoverageIgnoreEnd
} else {
$this->logger = new \Monolog\Logger('php-tmdb-api');
$this->logger->pushHandler(
$this->setLogger(new \Monolog\Logger('php-tmdb-api'));
$this->getLogger()->pushHandler(
new \Monolog\Handler\StreamHandler(
$this->logPath,
\Monolog\Logger::DEBUG
Expand Down
10 changes: 10 additions & 0 deletions test/Tmdb/Tests/ApiTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ public function testSetGet()

$this->assertEquals(self::API_TOKEN, $token->getToken());
}

/**
* @expectedException Tmdb\Exception\RuntimeException
* @test
*/
public function testThrowsErrorOnEmptyApiToken()
{
$token = new \Tmdb\ApiToken();
$token->setToken(null);
}
}
26 changes: 26 additions & 0 deletions test/Tmdb/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,30 @@ private function isListenerRegistered($listeners, $class)

return false;
}

/**
* @test
*/
public function shouldBeAbleSetCache()
{
$path = '/tmp/php-tmdb-api';

$this->client->setCaching(true, $path);

$this->assertEquals(true, $this->client->getCacheEnabled());
$this->assertEquals($path, $this->client->getCachePath());
}

/**
* @test
*/
public function shouldBeAbleSetLogging()
{
$path = '/tmp/php-tmdb-api.log';

$this->client->setLogging(true, $path);

$this->assertEquals(true, $this->client->getLogEnabled());
$this->assertEquals($path, $this->client->getLogPath());
}
}

0 comments on commit bc8be43

Please sign in to comment.