Skip to content

Commit

Permalink
Unit tests and some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fire015 committed Mar 11, 2014
1 parent ec20613 commit e490197
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
composer.lock
25 changes: 25 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/TestFixture.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>

<filter>
<whitelist>
<directory>src/Flintstone</directory>
</whitelist>
</filter>

<testsuites>
<testsuite name="Flintstone Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
9 changes: 9 additions & 0 deletions src/Flintstone/Flintstone.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ public static function load($database, $options = array()) {

return self::$instance[$database];
}

/**
* Unload a database
* @param string $database the database name
* @return void
*/
public static function unload($database) {
unset(self::$instance[$database]);
}
}
76 changes: 76 additions & 0 deletions tests/FeatureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Flintstone Unit Tests
*/

class FeatureTest extends TestFixture {

/**
* Test 'set' operations
*/
public function testSet() {
$this->assertTrue($this->db->set('a', '1'));
$this->assertTrue($this->db->set('b', 2));
$this->assertTrue($this->db->set('c', array(3, 4, 5)));
}

/**
* Test 'set' operations
* @expectedException Flintstone\FlintstoneException
*/
public function testSetException() {
$this->db->set('d', false);
}

/**
* Test 'replace' operations
*/
public function testReplace() {
$this->assertTrue($this->db->set('a', '1'));
$this->assertTrue($this->db->replace('a', '2'));
$this->assertSame($this->db->get('a'), '2');
}

/**
* Test 'get' operations
*/
public function testGet() {
$this->assertFalse($this->db->get('a'));
$this->assertTrue($this->db->set('a', '1'));
$this->assertSame($this->db->get('a'), '1');
}

/**
* Test 'delete' operations
*/
public function testDelete() {
$this->assertFalse($this->db->delete('a'));
$this->assertTrue($this->db->set('a', '1'));
$this->assertTrue($this->db->delete('a'));
$this->assertFalse($this->db->get('a'));
}

/**
* Test 'flush' operations
*/
public function testFlush() {
$this->assertTrue($this->db->set('a', '1'));
$this->assertTrue($this->db->set('b', 2));
$this->assertTrue($this->db->flush());
$this->assertFalse($this->db->get('a'));
$this->assertFalse($this->db->get('b'));
}

/**
* Test 'getKeys' operations
*/
public function testGetKeys() {
$this->assertTrue($this->db->set('a', '1'));
$this->assertTrue($this->db->set('b', 2));
$this->assertTrue($this->db->set('c', array(3, 4, 5)));
$keys = $this->db->getKeys();
$this->assertEquals(3, count($keys));
$this->assertContains('a', $keys);
}
}
35 changes: 35 additions & 0 deletions tests/TestFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* Flintstone Unit Tests
*/

require __DIR__ . '/../vendor/autoload.php';

use Flintstone\Flintstone;

class TestFixture extends \PHPUnit_Framework_TestCase {

/**
* Flintstone database
* @access protected
* @var object
*/
protected $db;

/**
* Load the test database
*/
public function setUp() {
$this->db = Flintstone::load('test', array('dir' => __DIR__));
}

/**
* Unload the test database and remove
*/
public function tearDown() {
Flintstone::unload('test');
$file = __DIR__ . '/test.dat';
unlink($file);
}
}

0 comments on commit e490197

Please sign in to comment.