3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
28 * Verify that CRM_Utils_Cache_ArrayDecorator complies with PSR-16.
32 class E2E_Cache_ArrayDecoratorTest
extends E2E_Cache_CacheTestCase
{
35 * @var CRM_Utils_Cache_Interface
39 public function createSimpleCache() {
40 return new CRM_Utils_Cache_ArrayDecorator(
41 $this->a
= CRM_Utils_Cache
::create([
42 'name' => 'e2e array-dec test',
43 'type' => ['ArrayCache'],
48 public function testDoubleLifeWithDelete() {
49 $this->assertFalse($this->a
->has('foo'));
50 $this->assertEquals('dfl-1', $this->a
->get('foo', 'dfl-1'));
52 $this->cache
->set('foo', 100);
54 $this->assertTrue($this->a
->has('foo'));
55 $this->assertEquals(100, $this->a
->get('foo', 'dfl-1')[1]);
57 $this->cache
->set('foo', 200);
59 $this->assertTrue($this->a
->has('foo'));
60 $this->assertEquals(200, $this->a
->get('foo', 'dfl-1')[1]);
62 $this->cache
->delete('foo');
64 $this->assertFalse($this->a
->has('foo'));
65 $this->assertEquals('dfl-1', $this->a
->get('foo', 'dfl-1'));
68 public function testDoubleLifeWithClear() {
69 $this->assertFalse($this->a
->has('foo'));
70 $this->assertEquals('dfl-1', $this->a
->get('foo', 'dfl-1'));
72 $this->cache
->set('foo', 100);
74 $this->assertTrue($this->a
->has('foo'));
75 $this->assertEquals(100, $this->a
->get('foo', 'dfl-1')[1]);
77 $this->cache
->clear();
79 $this->assertFalse($this->a
->has('foo'));
80 $this->assertEquals('dfl-1', $this->a
->get('foo', 'dfl-1'));
83 public function testSetTtl() {
84 // This test has exhibited some flakiness. It is overridden to
85 // dump more detailed information about failures; however, it should be
86 // substantively the same.
87 if (isset($this->skippedTests
[__FUNCTION__
])) {
88 $this->markTestSkipped($this->skippedTests
[__FUNCTION__
]);
90 $result = $this->cache
->set('key1', 'value', 1);
91 $this->assertTrue($result, 'set() must return true if success');
92 $this->assertEquals('value', $this->cache
->get('key1'));
94 $this->assertNull($this->cache
->get('key1'), 'Value must expire after ttl.');
96 $this->cache
->set('key2', 'value', new \
DateInterval('PT1S'));
97 $key2Value = $this->cache
->get('key2');
98 if ($key2Value !== 'value') {
99 // dump out contents of cache.
100 var_dump($this->cache
);
101 print_r(date('u') . 'Current UNIX timestamp');
103 $this->assertEquals('value', $key2Value);
105 $this->assertNull($this->cache
->get('key2'), 'Value must expire after ttl.');