From c35bb774bc368dd07a58f9094e68620a8e4565bb Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Mon, 9 Oct 2017 22:44:21 -0700 Subject: [PATCH] Added a test and cleaned up some other tests a bit --- tests/APCuTest.php | 5 +++++ tests/FileTest.php | 17 ++++++++++++++++- tests/ItemTest.php | 32 +++++++++++++++++++++++++++----- tests/MemcachedTest.php | 6 ++++++ 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/tests/APCuTest.php b/tests/APCuTest.php index f4356e2..0d1f1b6 100644 --- a/tests/APCuTest.php +++ b/tests/APCuTest.php @@ -12,4 +12,9 @@ public function setUp() { $this->stash = new Stash\Drivers\APCu(); } + + public function tearDown() + { + $this->stash->flush(); + } } diff --git a/tests/FileTest.php b/tests/FileTest.php index f0305b7..8c24a7d 100644 --- a/tests/FileTest.php +++ b/tests/FileTest.php @@ -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")); + } } diff --git a/tests/ItemTest.php b/tests/ItemTest.php index 5e00917..8670a5c 100644 --- a/tests/ItemTest.php +++ b/tests/ItemTest.php @@ -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() diff --git a/tests/MemcachedTest.php b/tests/MemcachedTest.php index 255a2a5..feacb5c 100644 --- a/tests/MemcachedTest.php +++ b/tests/MemcachedTest.php @@ -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')); } }