Skip to content

Commit

Permalink
Adding a StorageFactoryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
justinrainbow committed Jul 25, 2012
1 parent 82615c8 commit 97c880c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Presque/Storage/StorageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static function create($dsn, $prefix = null)
));
}

// @codeCoverageIgnoreStart
if (extension_loaded('redis')) {
$redis = new \Redis();
$redis->connect($url['host'], isset($url['port']) ? $url['port'] : 6379);
Expand All @@ -35,6 +36,7 @@ public static function create($dsn, $prefix = null)

$storage = new PredisStorage($redis);
}
// @codeCoverageIgnoreEnd

if (null !== $prefix) {
$storage->setPrefix($prefix);
Expand Down
50 changes: 50 additions & 0 deletions tests/Presque/Tests/Storage/StorageFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Presque package.
*
* (c) Justin Rainbow <justin.rainbow@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Presque\Tests\Storage;

use Presque\Tests\TestCase;
use Presque\Storage\StorageFactory;
use Mockery as m;

class StorageFactoryTest extends TestCase
{
/**
* @expectedException InvalidArgumentException
*/
public function testFailingToCreateStorage()
{
StorageFactory::create('tcp://:6379');
}

public function testCreatingStorageWithPrefix()
{
try {
$storage = StorageFactory::create('tcp://localhost:6379', 'test');

$this->assertInstanceOf('Presque\Storage\StorageInterface', $storage);
$this->assertEquals('test', $storage->getPrefix());
} catch (\RedisException $e) {
// this is OK - redis might not be running!
}
}

public function testCreatingStorage()
{
try {
$storage = StorageFactory::create('tcp://localhost:6379');

$this->assertInstanceOf('Presque\Storage\StorageInterface', $storage);
} catch (\RedisException $e) {
// this is OK - redis might not be running!
}
}
}

0 comments on commit 97c880c

Please sign in to comment.