This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated RedisStorage and added tests.
- Loading branch information
Marcel Araujo
committed
Feb 8, 2013
1 parent
8fe303c
commit 5d9013d
Showing
2 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
tests/Doctrine/Tests/KeyValueStore/Storage/RedisStorageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\KeyValueStore\Storage; | ||
|
||
use Doctrine\KeyValueStore\Storage\RedisStorage; | ||
|
||
/** | ||
* @author Marcel Araujo <admin@marcelaraujo.me> | ||
*/ | ||
class RedisStorageTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var RedisStorage | ||
*/ | ||
private $storage; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $redis; | ||
|
||
protected function setup() | ||
{ | ||
if ( ! extension_loaded('redis')) { | ||
$this->markTestSkipped('Redis Extension is not installed.'); | ||
} | ||
|
||
$this->redis = $this->getMockBuilder('\Redis') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->redis->expects($this->any()) | ||
->method('connect') | ||
->with('127.0.0.1', '6379') | ||
->will($this->returnValue(TRUE)); | ||
|
||
$this->storage = new RedisStorage($this->redis); | ||
} | ||
|
||
public function testSupportsPartialUpdates() | ||
{ | ||
$this->assertFalse($this->storage->supportsPartialUpdates()); | ||
} | ||
|
||
public function testSupportsCompositePrimaryKeys() | ||
{ | ||
$this->assertFalse($this->storage->supportsCompositePrimaryKeys()); | ||
} | ||
|
||
public function testRequiresCompositePrimaryKeys() | ||
{ | ||
$this->assertFalse($this->storage->requiresCompositePrimaryKeys()); | ||
} | ||
|
||
public function testInsert() | ||
{ | ||
$data = array( | ||
'author' => 'John Doe', | ||
'title' => 'example book', | ||
); | ||
|
||
$dbDataset = array(); | ||
|
||
$this->redis->expects($this->once()) | ||
->method('set') | ||
->will($this->returnCallback(function($key, $data) use (&$dbDataset) { | ||
$dbDataset[] = array('key' => $key, 'value' => $data); | ||
})); | ||
|
||
$this->storage->insert('redis', '1', $data); | ||
|
||
$this->assertCount(1, $dbDataset); | ||
$this->assertEquals(array(array('key' => $this->storage->getKeyName('1'), 'value' => json_encode($data))), $dbDataset); | ||
} | ||
|
||
public function testUpdate() | ||
{ | ||
|
||
$data = array( | ||
'author' => 'John Doe Updated', | ||
'title' => 'example book updated', | ||
); | ||
|
||
$dbDataset = array(); | ||
|
||
$this->redis->expects($this->once()) | ||
->method('set') | ||
->will($this->returnCallback(function($key, $data) use (&$dbDataset) { | ||
$dbDataset[] = array('key' => $key, 'value' => $data); | ||
})); | ||
|
||
|
||
$this->storage->update('redis', '1', $data); | ||
|
||
$this->assertCount(1, $dbDataset); | ||
$this->assertEquals(array(array('key' => $this->storage->getKeyName('1'), 'value' => json_encode($data))), $dbDataset); | ||
} | ||
|
||
public function testGetName() | ||
{ | ||
$this->assertEquals('redis', $this->storage->getName()); | ||
} | ||
} |