Skip to content

Commit c1e8d7c

Browse files
committed
Add tests
1 parent d80e72c commit c1e8d7c

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

tests/Dashboards/APCuTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Tests\Dashboards;
1414

1515
use RobiNN\Pca\Dashboards\APCu\APCuDashboard;
16+
use RobiNN\Pca\Http;
1617
use RobiNN\Pca\Template;
1718
use Tests\TestCase;
1819

@@ -93,4 +94,19 @@ public function testGetKey(): void {
9394
apcu_delete('pu-test-'.$key);
9495
}
9596
}
97+
98+
public function testSaveKey(): void {
99+
$key = 'pu-test-save';
100+
101+
$_POST['key'] = $key;
102+
$_POST['value'] = 'test-value';
103+
$_POST['encoder'] = 'none';
104+
105+
Http::stopRedirect();
106+
self::callMethod($this->apcu, 'saveKey');
107+
108+
$this->assertSame('test-value', self::callMethod($this->apcu, 'getKey', $key));
109+
110+
apcu_delete($key);
111+
}
96112
}

tests/Dashboards/MemcachedTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use RobiNN\Pca\Dashboards\Memcached\MemcacheCompatibility\Memcache;
1616
use RobiNN\Pca\Dashboards\Memcached\MemcacheCompatibility\Memcached;
1717
use RobiNN\Pca\Dashboards\Memcached\MemcachedDashboard;
18+
use RobiNN\Pca\Http;
1819
use RobiNN\Pca\Template;
1920
use Tests\TestCase;
2021

@@ -101,4 +102,19 @@ public function testGetKey(): void {
101102
$this->memcached->delete('pu-test-'.$key);
102103
}
103104
}
105+
106+
public function testSaveKey(): void {
107+
$key = 'pu-test-save';
108+
109+
$_POST['key'] = $key;
110+
$_POST['value'] = 'test-value';
111+
$_POST['encoder'] = 'none';
112+
113+
Http::stopRedirect();
114+
self::callMethod($this->dashboard, 'saveKey', $this->memcached);
115+
116+
$this->assertSame('test-value', $this->memcached->getKey($key));
117+
118+
$this->memcached->delete($key);
119+
}
104120
}

tests/Dashboards/RedisTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Redis;
1616
use RedisException;
1717
use RobiNN\Pca\Dashboards\Redis\RedisDashboard;
18+
use RobiNN\Pca\Http;
1819
use RobiNN\Pca\Template;
1920
use Tests\TestCase;
2021

@@ -110,4 +111,25 @@ public function testGetKey(): void {
110111
echo $e->getMessage();
111112
}
112113
}
114+
115+
public function testSaveKey(): void {
116+
try {
117+
$key = 'pu-test-save';
118+
119+
$_POST['redis_type'] = 'string';
120+
$_POST['key'] = $key;
121+
$_POST['value'] = 'test-value';
122+
$_POST['expire'] = -1;
123+
$_POST['encoder'] = 'none';
124+
125+
Http::stopRedirect();
126+
self::callMethod($this->dashboard, 'saveKey', $this->redis);
127+
128+
$this->assertSame('test-value', $this->redis->get($key));
129+
130+
$this->redis->del($key);
131+
} catch (RedisException $e) {
132+
echo $e->getMessage();
133+
}
134+
}
113135
}

0 commit comments

Comments
 (0)