Skip to content

Commit 2251ec3

Browse files
minor symfony#26605 [Cache] Rely on mock for Doctrine ArrayCache (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Cache] Rely on mock for Doctrine ArrayCache | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - See also doctrine/cache#253 Commits ------- e4973ad [Cache] Rely on mock for Doctrine ArrayCache
2 parents 28f4662 + e4973ad commit 2251ec3

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<element><string>Cache\IntegrationTests</string></element>
6666
<element><string>Doctrine\Common\Cache</string></element>
6767
<element><string>Symfony\Component\Cache</string></element>
68+
<element><string>Symfony\Component\Cache\Tests\Fixtures</string></element>
6869
<element><string>Symfony\Component\Cache\Traits</string></element>
6970
<element><string>Symfony\Component\Console</string></element>
7071
<element><string>Symfony\Component\HttpFoundation</string></element>

src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14-
use Doctrine\Common\Cache\ArrayCache;
1514
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
15+
use Symfony\Component\Cache\Tests\Fixtures\ArrayCache;
1616

1717
/**
1818
* @group time-sensitive
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Symfony\Component\Cache\Tests\Fixtures;
4+
5+
use Doctrine\Common\Cache\CacheProvider;
6+
7+
class ArrayCache extends CacheProvider
8+
{
9+
private $data = array();
10+
11+
protected function doFetch($id)
12+
{
13+
return $this->doContains($id) ? $this->data[$id][0] : false;
14+
}
15+
16+
protected function doContains($id)
17+
{
18+
if (!isset($this->data[$id])) {
19+
return false;
20+
}
21+
22+
$expiry = $this->data[$id][1];
23+
24+
return !$expiry || time() <= $expiry || !$this->doDelete($id);
25+
}
26+
27+
protected function doSave($id, $data, $lifeTime = 0)
28+
{
29+
$this->data[$id] = array($data, $lifeTime ? time() + $lifeTime : false);
30+
31+
return true;
32+
}
33+
34+
protected function doDelete($id)
35+
{
36+
unset($this->data[$id]);
37+
38+
return true;
39+
}
40+
41+
protected function doFlush()
42+
{
43+
$this->data = array();
44+
45+
return true;
46+
}
47+
48+
protected function doGetStats()
49+
{
50+
return null;
51+
}
52+
}

src/Symfony/Component/Cache/Tests/Simple/DoctrineCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Simple;
1313

14-
use Doctrine\Common\Cache\ArrayCache;
1514
use Symfony\Component\Cache\Simple\DoctrineCache;
15+
use Symfony\Component\Cache\Tests\Fixtures\ArrayCache;
1616

1717
/**
1818
* @group time-sensitive

src/Symfony/Component/Cache/phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<element><string>Cache\IntegrationTests</string></element>
4040
<element><string>Doctrine\Common\Cache</string></element>
4141
<element><string>Symfony\Component\Cache</string></element>
42+
<element><string>Symfony\Component\Cache\Tests\Fixtures</string></element>
4243
<element><string>Symfony\Component\Cache\Traits</string></element>
4344
</array>
4445
</element>

0 commit comments

Comments
 (0)