forked from kaz29/cakephp-predis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPredisEngineTest.php
More file actions
69 lines (58 loc) · 1.83 KB
/
PredisEngineTest.php
File metadata and controls
69 lines (58 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Renan\Cake\Predis;
use Cake\Cache\Cache;
final class PredisEngineTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PredisEngine
*/
private $engine;
public function setUp()
{
$this->engine = new PredisEngine();
$this->engine->init();
}
public function tearDown()
{
$this->engine->clear(false);
unset($this->engine);
}
/**
* @param mixed $value
* @dataProvider writeAndReadDataTypes
*/
public function testWriteAndReadDataTypesAndThenDelete($value)
{
$this->assertTrue($this->engine->write('dataType', $value));
$this->assertEquals($value, $this->engine->read('dataType'));
$this->assertTrue($this->engine->delete('dataType'));
$this->assertFalse($this->engine->read('dataType'));
}
public function writeAndReadDataTypes()
{
return [
'string' => ['Hello world'],
'integer' => [42],
'float' => [13.37],
'true' => [true],
'false' => [false],
'array' => [['foo' => 'bar']],
];
}
public function testIncrement()
{
$this->assertFalse($this->engine->increment('key'));
$this->assertTrue($this->engine->write('key', 10));
$this->assertEquals(11, $this->engine->increment('key'));
$this->assertEquals(12, $this->engine->increment('key'));
$this->assertEquals(13, $this->engine->increment('key'));
}
public function testDecrement()
{
$this->assertFalse($this->engine->decrement('key'));
$this->assertTrue($this->engine->write('key', 10));
$this->assertEquals(9, $this->engine->decrement('key'));
$this->assertEquals(8, $this->engine->decrement('key'));
$this->assertEquals(7, $this->engine->decrement('key'));
}
}