Skip to content

Commit

Permalink
Added a test and cleaned up some other tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
PHLAK committed Oct 10, 2017
1 parent 2e94151 commit c35bb77
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
5 changes: 5 additions & 0 deletions tests/APCuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public function setUp()
{
$this->stash = new Stash\Drivers\APCu();
}

public function tearDown()
{
$this->stash->flush();
}
}
17 changes: 16 additions & 1 deletion tests/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@ class FileTest extends PHPUnit_Framework_TestCase
{
use Cacheable;

protected $dirPath;
protected $stash;

public function setUp()
{
$this->stash = new Stash\Drivers\File(__DIR__ . '/cache');
$this->dirPath = __DIR__ . '/cache';
$this->stash = new Stash\Drivers\File($this->dirPath);
}

public function tearDown()
{
$this->stash->flush();
}

public function test_it_returns_false_for_an_expired_item()
{
$this->stash->put('expired', 'qwerty', -5);

$this->assertFalse($this->stash->get('expired'));
}

public function test_it_creates_a_cache_file_with_a_php_extension()
{
$this->stash->put('extension-test', 'asdf', 5);

$this->assertTrue(file_exists("{$this->dirPath}/27ab9a58aa0a5ed06a7935b9a8a8b1edf2d2ba70.cache.php"));
}
}
32 changes: 27 additions & 5 deletions tests/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,44 @@ public function setUp()
$this->item = new Stash\Item('Test data');
}

public function test_it_has_data()
public function test_it_can_contain_a_string()
{
$item = new Stash\Item('Some string');

$this->assertEquals('Some string', $item->data);
}

public function test_it_can_contain_an_integer()
{
$item = new Stash\Item(1337);

$this->assertEquals(1337, $item->data);
}

public function test_it_can_contain_an_array()
{
$item = new Stash\Item(['alice', 1337, false]);

$this->assertEquals(['alice', 1337, false], $item->data);
}

public function test_it_can_contain_booleans()
{
$trueItem = new Stash\Item(true);
$falseItem = new Stash\Item(false);

$this->assertTrue($trueItem->data);
$this->assertFalse($falseItem->data);
}

public function test_it_can_contain_an_object()
{
$class = new stdClass;
$class->boolean = true;

$item = new Stash\Item(true);
$this->assertTrue($item->data);
$item = new Stash\Item($class);

$item = new Stash\Item(false);
$this->assertFalse($item->data);
$this->assertTrue($item->data->boolean);
}

public function test_it_has_an_expiration()
Expand Down
6 changes: 6 additions & 0 deletions tests/MemcachedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ public function setUp()
]);
}

public function tearDown()
{
$this->stash->flush();
}

public function test_it_returns_false_for_an_expired_item()
{
$this->stash->put('expired', 'qwerty', -5);

$this->assertFalse($this->stash->get('expired'));
}
}

0 comments on commit c35bb77

Please sign in to comment.