Skip to content

Commit 5a091cc

Browse files
author
Andrey Helldar
authored
Merge pull request #9 from TheDragonCode/2.x
[2.x] Added tests
2 parents fcf01af + cbb5eb1 commit 5a091cc

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Cache\NotWhen;
6+
7+
use DragonCode\Cache\Services\Cache;
8+
9+
class MultiCallTest extends BaseTest
10+
{
11+
protected $cache = 'redis';
12+
13+
public function testGet()
14+
{
15+
$value1 = $this->cache(['foo', 'bar']);
16+
$value2 = $this->cache(['qwe', 'rty']);
17+
18+
$this->assertNull($value1->get());
19+
$this->assertNull($value2->get());
20+
21+
$value1->put(function () {
22+
return 'Foo';
23+
});
24+
25+
$value2->put(function () {
26+
return 'Bar';
27+
});
28+
29+
$this->assertNull($value1->get());
30+
$this->assertNull($value2->get());
31+
}
32+
33+
public function testForget()
34+
{
35+
$value1 = $this->cache(['foo', 'bar']);
36+
$value2 = $this->cache(['qwe', 'rty']);
37+
38+
$this->assertNull($value1->get());
39+
$this->assertNull($value2->get());
40+
41+
$value1->put(function () {
42+
return 'Foo';
43+
});
44+
45+
$value2->put(function () {
46+
return 'Bar';
47+
});
48+
49+
$this->assertNull($value1->get());
50+
$this->assertNull($value2->get());
51+
52+
$value1->forget();
53+
$value2->forget();
54+
55+
$this->assertNull($value1->get());
56+
$this->assertNull($value2->get());
57+
}
58+
59+
public function testHas()
60+
{
61+
$value1 = $this->cache(['foo', 'bar']);
62+
$value2 = $this->cache(['qwe', 'rty']);
63+
64+
$this->assertFalse($value1->has());
65+
$this->assertFalse($value2->has());
66+
67+
$value1->put(function () {
68+
return 'Foo';
69+
});
70+
71+
$value2->put(function () {
72+
return 'Bar';
73+
});
74+
75+
$this->assertFalse($value1->has());
76+
$this->assertFalse($value2->has());
77+
}
78+
79+
protected function cache(array $tags = null): Cache
80+
{
81+
return Cache::make()
82+
->when($this->when)
83+
->key(...$tags);
84+
}
85+
}

tests/Cache/When/MultiCallTest.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Cache\When;
6+
7+
use DragonCode\Cache\Services\Cache;
8+
9+
class MultiCallTest extends BaseTest
10+
{
11+
protected $cache = 'redis';
12+
13+
public function testGet()
14+
{
15+
$value1 = $this->cache(['foo', 'bar']);
16+
$value2 = $this->cache(['qwe', 'rty']);
17+
18+
$this->assertNull($value1->get());
19+
$this->assertNull($value2->get());
20+
21+
$value1->put(function () {
22+
return 'Foo';
23+
});
24+
25+
$value2->put(function () {
26+
return 'Bar';
27+
});
28+
29+
$this->assertSame('Foo', $value1->get());
30+
$this->assertSame('Bar', $value2->get());
31+
$this->assertSame('Foo', $value1->get());
32+
}
33+
34+
public function testForget()
35+
{
36+
$value1 = $this->cache(['foo', 'bar']);
37+
$value2 = $this->cache(['qwe', 'rty']);
38+
39+
$this->assertNull($value1->get());
40+
$this->assertNull($value2->get());
41+
42+
$value1->put(function () {
43+
return 'Foo';
44+
});
45+
46+
$value2->put(function () {
47+
return 'Bar';
48+
});
49+
50+
$this->assertSame('Foo', $value1->get());
51+
$this->assertSame('Bar', $value2->get());
52+
53+
$value1->forget();
54+
$value2->forget();
55+
56+
$this->assertNull($value1->get());
57+
$this->assertNull($value2->get());
58+
}
59+
60+
public function testHas()
61+
{
62+
$value1 = $this->cache(['foo', 'bar']);
63+
$value2 = $this->cache(['qwe', 'rty']);
64+
65+
$this->assertFalse($value1->has());
66+
$this->assertFalse($value2->has());
67+
68+
$value1->put(function () {
69+
return 'Foo';
70+
});
71+
72+
$value2->put(function () {
73+
return 'Bar';
74+
});
75+
76+
$this->assertTrue($value1->has());
77+
$this->assertTrue($value2->has());
78+
}
79+
80+
protected function cache(array $tags = null): Cache
81+
{
82+
return Cache::make()
83+
->when($this->when)
84+
->key(...$tags);
85+
}
86+
}

0 commit comments

Comments
 (0)