Completed
Push — master ( e0017c...6b1304 )
by Tom
14s queued 11s
created

Cache/DoctrineCacheStorageTest.php (106 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModuleTest\Cache;
6
7
use Doctrine\Common\Cache\ArrayCache;
8
use DoctrineModule\Cache\DoctrineCacheStorage;
9
use Laminas\Cache\Storage\Adapter\AdapterOptions;
10
use Laminas\Cache\Storage\StorageInterface;
11
use Laminas\Stdlib\ErrorHandler;
12
use PHPUnit\Framework\TestCase;
13
use stdClass;
14
use function array_keys;
15
use function count;
16
use function fopen;
17
use function is_string;
18
use function ksort;
19
use function method_exists;
20
use function rand;
21
use function settype;
22
use function sort;
23
use function sprintf;
24
use function str_replace;
25
use function ucwords;
26
27
/**
28
 * Tests for the cache bridge
29
 *
30
 * @link    http://www.doctrine-project.org/
31
 *
32
 * @todo extend \ZendTest\Cache\Storage\CommonAdapterTest instead
33
 * @covers \DoctrineModule\Cache\DoctrineCacheStorage
34
 */
35
class DoctrineCacheStorageTest extends TestCase
36
{
37
    /** @var AdapterOptions */
38
    protected $options;
39
40
    /**
41
     * The storage adapter
42
     *
43
     * @var StorageInterface
44
     */
45
    protected $storage;
46
47
    /**
48
     * All datatypes of PHP
49
     *
50
     * @var string[]
51
     */
52
    protected $phpDatatypes = ['NULL', 'boolean', 'integer', 'double', 'string', 'array', 'object', 'resource'];
53
54
    protected function setUp() : void
55
    {
56
        $this->options = new AdapterOptions();
57
        // @todo fix constructor as it is messy
58
        $this->storage = new DoctrineCacheStorage($this->options, new ArrayCache());
59
60
        $this->assertInstanceOf(
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
            'Laminas\Cache\Storage\StorageInterface',
62
            $this->storage,
63
            'Storage adapter instance is needed for tests'
64
        );
65
        $this->assertInstanceOf(
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
            'Laminas\Cache\Storage\Adapter\AdapterOptions',
67
            $this->options,
68
            'Options instance is needed for tests'
69
        );
70
    }
71
72
    protected function tearDown() : void
73
    {
74
        // be sure the error handler has been stopped
75
        if (! ErrorHandler::started()) {
76
            return;
77
        }
78
79
        ErrorHandler::stop();
80
        $this->fail('ErrorHandler not stopped');
81
    }
82
83
    public function testOptionNamesValid() : void
84
    {
85
        $options = $this->storage->getOptions()->toArray();
86
        foreach ($options as $name => $value) {
87
            $this->assertRegExp(
0 ignored issues
show
The method assertRegExp() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
                '/^[a-z]+[a-z0-9_]*[a-z0-9]+$/',
89
                $name,
90
                sprintf(
91
                    "Invalid option name '%s'",
92
                    $name
93
                )
94
            );
95
        }
96
    }
97
98
    public function testGettersAndSettersOfOptionsExists() : void
99
    {
100
        $options = $this->storage->getOptions();
101
        foreach ($options->toArray() as $option => $value) {
102
            if ($option === 'adapter') {
103
                // Skip this, as it's a "special" value
104
                continue;
105
            }
106
107
            $method = ucwords(str_replace('_', ' ', $option));
108
            $method = str_replace(' ', '', $method);
109
110
            $this->assertTrue(
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
111
                method_exists($options, 'set' . $method),
112
                sprintf(
113
                    "Missing method 'set'%s",
114
                    $method
115
                )
116
            );
117
118
            $this->assertTrue(
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
119
                method_exists($options, 'get' . $method),
120
                sprintf(
121
                    "Missing method 'get'%s",
122
                    $method
123
                )
124
            );
125
        }
126
    }
127
128
    public function testOptionsGetAndSetDefault() : void
129
    {
130
        $options = $this->storage->getOptions();
131
        $this->storage->setOptions($options);
132
        $this->assertSame($options, $this->storage->getOptions());
133
    }
134
135
    public function testOptionsFluentInterface() : void
136
    {
137
        $options = $this->storage->getOptions();
138
        foreach ($options->toArray() as $option => $value) {
139
            $method = ucwords(str_replace('_', ' ', $option));
140
            $method = 'set' . str_replace(' ', '', $method);
141
            $this->assertSame(
0 ignored issues
show
The method assertSame() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
142
                $options,
143
                $options->{$method}($value),
144
                sprintf(
145
                    "Method '%s' doesn't implement the fluent interface",
146
                    $method
147
                )
148
            );
149
        }
150
151
        $this->assertSame(
0 ignored issues
show
The method assertSame() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
152
            $this->storage,
153
            $this->storage->setOptions($options),
154
            "Method 'setOptions' doesn't implement the fluent interface"
155
        );
156
    }
157
158
    public function testGetCapabilities() : void
159
    {
160
        $capabilities = $this->storage->getCapabilities();
161
        $this->assertInstanceOf('Laminas\Cache\Storage\Capabilities', $capabilities);
162
    }
163
164
    public function testDatatypesCapability() : void
165
    {
166
        $capabilities = $this->storage->getCapabilities();
167
        $datatypes    = $capabilities->getSupportedDatatypes();
168
        $this->assertIsArray($datatypes);
169
170
        foreach ($datatypes as $sourceType => $targetType) {
171
            $this->assertContains($sourceType, $this->phpDatatypes, 'Unknown source type "' . $sourceType . '"');
172
173
            if (is_string($targetType)) {
174
                $this->assertContains($targetType, $this->phpDatatypes, 'Unknown source type "' . $sourceType . '"');
175
            } else {
176
                $this->assertIsBool($targetType, 'Target type must be a string or boolean');
177
            }
178
        }
179
    }
180
181
    public function testSupportedMetadataCapability() : void
182
    {
183
        $capabilities = $this->storage->getCapabilities();
184
        $metadata     = $capabilities->getSupportedMetadata();
185
        $this->assertIsArray($metadata);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
186
187
        foreach ($metadata as $property) {
188
            $this->assertIsString($property);
189
        }
190
    }
191
192
    public function testTtlCapabilities() : void
193
    {
194
        $capabilities = $this->storage->getCapabilities();
195
196
        $this->assertIsInt($capabilities->getMaxTtl());
197
        $this->assertGreaterThanOrEqual(0, $capabilities->getMaxTtl());
198
199
        $this->assertIsBool($capabilities->getStaticTtl());
0 ignored issues
show
The method assertIsBool() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
200
201
        $this->assertIsNumeric($capabilities->getTtlPrecision());
202
        $this->assertGreaterThan(0, $capabilities->getTtlPrecision());
203
204
        $this->assertIsBool($capabilities->getStaticTtl());
0 ignored issues
show
The method assertIsBool() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
205
    }
206
207
    public function testKeyCapabilities() : void
208
    {
209
        $capabilities = $this->storage->getCapabilities();
210
211
        $this->assertIsInt($capabilities->getMaxKeyLength());
212
        $this->assertGreaterThanOrEqual(-1, $capabilities->getMaxKeyLength());
213
214
        $this->assertIsBool($capabilities->getNamespaceIsPrefix());
215
216
        $this->assertIsString($capabilities->getNamespaceSeparator());
217
    }
218
219
    public function testHasItemReturnsTrueOnValidItem() : void
220
    {
221
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
222
        $this->assertTrue($this->storage->hasItem('key'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
223
    }
224
225
    public function testHasItemReturnsFalseOnMissingItem() : void
226
    {
227
        $this->assertFalse($this->storage->hasItem('key'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
228
    }
229
230
    public function testHasItemNonReadable() : void
231
    {
232
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
233
234
        $this->options->setReadable(false);
235
        $this->assertFalse($this->storage->hasItem('key'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
236
    }
237
238
    public function testHasItemsReturnsKeysOfFoundItems() : void
239
    {
240
        $this->assertTrue($this->storage->setItem('key1', 'value1'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
241
        $this->assertTrue($this->storage->setItem('key2', 'value2'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
242
243
        $result = $this->storage->hasItems(['missing', 'key1', 'key2']);
244
        sort($result);
245
246
        $expectedResult = ['key1', 'key2'];
247
        $this->assertEquals($expectedResult, $result);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
248
    }
249
250
    public function testHasItemsReturnsEmptyArrayIfNonReadable() : void
251
    {
252
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
253
254
        $this->options->setReadable(false);
255
        $this->assertEquals([], $this->storage->hasItems(['key']));
256
    }
257
258
    public function testGetItemReturnsNullOnMissingItem() : void
259
    {
260
        $this->assertNull($this->storage->getItem('unknown'));
261
    }
262
263
    public function testGetItemSetsSuccessFlag() : void
264
    {
265
        $success = null;
266
267
        // $success = false on get missing item
268
        $this->storage->getItem('unknown', $success);
269
        $this->assertFalse($success);
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
270
271
        // $success = true on get valid item
272
        $this->storage->setItem('test', 'test');
273
        $this->storage->getItem('test', $success);
274
        $this->assertTrue($success);
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
275
    }
276
277
    public function testGetItemReturnsNullIfNonReadable() : void
278
    {
279
        $this->options->setReadable(false);
280
281
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
282
        $this->assertNull($this->storage->getItem('key'));
0 ignored issues
show
The method assertNull() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
283
    }
284
285
    public function testGetItemsReturnsKeyValuePairsOfFoundItems() : void
286
    {
287
        $this->assertTrue($this->storage->setItem('key1', 'value1'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
288
        $this->assertTrue($this->storage->setItem('key2', 'value2'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
289
290
        $result = $this->storage->getItems(['missing', 'key1', 'key2']);
291
        ksort($result);
292
293
        $expectedResult = [
294
            'key1' => 'value1',
295
            'key2' => 'value2',
296
        ];
297
        $this->assertEquals($expectedResult, $result);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
298
    }
299
300
    public function testGetItemsReturnsEmptyArrayIfNonReadable() : void
301
    {
302
        $this->options->setReadable(false);
303
304
        $this->assertTrue($this->storage->setItem('key', 'value'));
305
        $this->assertEquals([], $this->storage->getItems(['key']));
306
    }
307
308
    public function testGetMetadata() : void
309
    {
310
        $capabilities       = $this->storage->getCapabilities();
311
        $supportedMetadatas = $capabilities->getSupportedMetadata();
312
313
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
314
        $metadata = $this->storage->getMetadata('key');
315
316
        $this->assertIsArray($metadata);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
317
        foreach ($supportedMetadatas as $supportedMetadata) {
318
            $this->assertArrayHasKey($supportedMetadata, $metadata);
0 ignored issues
show
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
319
        }
320
    }
321
322
    public function testGetMetadataReturnsFalseOnMissingItem() : void
323
    {
324
        $this->assertFalse($this->storage->getMetadata('unknown'));
325
    }
326
327
    public function testGetMetadataReturnsFalseIfNonReadable() : void
328
    {
329
        $this->options->setReadable(false);
330
331
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
332
        $this->assertFalse($this->storage->getMetadata('key'));
333
    }
334
335
    public function testGetMetadatas() : void
336
    {
337
        $capabilities       = $this->storage->getCapabilities();
338
        $supportedMetadatas = $capabilities->getSupportedMetadata();
339
340
        $items = [
341
            'key1' => 'value1',
342
            'key2' => 'value2',
343
        ];
344
        $this->assertSame([], $this->storage->setItems($items));
0 ignored issues
show
The method assertSame() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
345
346
        $metadatas = $this->storage->getMetadatas(array_keys($items));
347
        $this->assertIsArray($metadatas);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
348
        $this->assertSame(count($items), count($metadatas));
349
        foreach ($metadatas as $metadata) {
350
            $this->assertIsArray($metadata);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
351
            foreach ($supportedMetadatas as $supportedMetadata) {
352
                $this->assertArrayHasKey($supportedMetadata, $metadata);
0 ignored issues
show
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
353
            }
354
        }
355
    }
356
357
    public function testGetMetadatasReturnsEmptyArrayIfNonReadable() : void
358
    {
359
        $this->options->setReadable(false);
360
361
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
362
        $this->assertEquals([], $this->storage->getMetadatas(['key']));
363
    }
364
365
    public function testSetGetHasAndRemoveItem() : void
366
    {
367
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
368
        $this->assertEquals('value', $this->storage->getItem('key'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
369
        $this->assertTrue($this->storage->hasItem('key'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
370
371
        $this->assertTrue($this->storage->removeItem('key'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
372
        $this->assertFalse($this->storage->hasItem('key'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
373
        $this->assertNull($this->storage->getItem('key'));
0 ignored issues
show
The method assertNull() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
374
    }
375
376
    public function testSetGetHasAndRemoveItems() : void
377
    {
378
        $items = [
379
            'key1' => 'value1',
380
            'key2' => 'value2',
381
            'key3' => 'value3',
382
        ];
383
384
        $this->assertSame([], $this->storage->setItems($items));
0 ignored issues
show
The method assertSame() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
385
386
        $rs = $this->storage->getItems(array_keys($items));
387
        $this->assertIsArray($rs);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
388
        foreach ($items as $key => $value) {
389
            $this->assertArrayHasKey($key, $rs);
0 ignored issues
show
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
390
            $this->assertEquals($value, $rs[$key]);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
391
        }
392
393
        $rs = $this->storage->hasItems(array_keys($items));
394
        $this->assertIsArray($rs);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
395
        $this->assertEquals(count($items), count($rs));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
396
        foreach ($items as $key => $value) {
397
            $this->assertContains($key, $rs);
0 ignored issues
show
The method assertContains() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
398
        }
399
400
        $this->assertSame(['missing'], $this->storage->removeItems(['missing', 'key1', 'key3']));
0 ignored issues
show
The method assertSame() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
401
        unset($items['key1'], $items['key3']);
402
403
        $rs = $this->storage->getItems(array_keys($items));
404
        $this->assertIsArray($rs);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
405
        foreach ($items as $key => $value) {
406
            $this->assertArrayHasKey($key, $rs);
0 ignored issues
show
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
407
            $this->assertEquals($value, $rs[$key]);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
408
        }
409
410
        $rs = $this->storage->hasItems(array_keys($items));
411
        $this->assertIsArray($rs);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
412
        $this->assertEquals(count($items), count($rs));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
413
        foreach ($items as $key => $value) {
414
            $this->assertContains($key, $rs);
0 ignored issues
show
The method assertContains() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
415
        }
416
    }
417
418
    public function testSetGetHasAndRemoveItemWithNamespace() : void
419
    {
420
        // write "key" to default namespace
421
        $this->options->setNamespace('defaultns1');
422
        $this->assertTrue($this->storage->setItem('key', 'defaultns1'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
423
424
        // write "key" to an other default namespace
425
        $this->options->setNamespace('defaultns2');
426
        $this->assertTrue($this->storage->setItem('key', 'defaultns2'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
427
428
        // test value of defaultns2
429
        $this->assertTrue($this->storage->hasItem('key'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
430
        $this->assertEquals('defaultns2', $this->storage->getItem('key'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
431
432
        // test value of defaultns1
433
        $this->options->setNamespace('defaultns1');
434
        $this->assertTrue($this->storage->hasItem('key'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
435
        $this->assertEquals('defaultns1', $this->storage->getItem('key'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
436
437
        // remove item of defaultns1
438
        $this->options->setNamespace('defaultns1');
439
        $this->assertTrue($this->storage->removeItem('key'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
440
        $this->assertFalse($this->storage->hasItem('key'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
441
442
        // remove item of defaultns2
443
        $this->options->setNamespace('defaultns2');
444
        $this->assertTrue($this->storage->removeItem('key'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
445
        $this->assertFalse($this->storage->hasItem('key'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
446
    }
447
448
    public function testSetGetHasAndRemoveItemsWithNamespace() : void
449
    {
450
        $items = [
451
            'key1' => 'value1',
452
            'key2' => 'value2',
453
            'key3' => 'value3',
454
        ];
455
456
        $this->options->setNamespace('defaultns1');
457
        $this->assertSame([], $this->storage->setItems($items));
0 ignored issues
show
The method assertSame() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
458
459
        $this->options->setNamespace('defaultns2');
460
        $this->assertSame([], $this->storage->hasItems(array_keys($items)));
461
462
        $this->options->setNamespace('defaultns1');
463
        $rs = $this->storage->getItems(array_keys($items));
464
        $this->assertIsArray($rs);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
465
        foreach ($items as $key => $value) {
466
            $this->assertArrayHasKey($key, $rs);
0 ignored issues
show
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
467
            $this->assertEquals($value, $rs[$key]);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
468
        }
469
470
        $rs = $this->storage->hasItems(array_keys($items));
471
        $this->assertIsArray($rs);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
472
        $this->assertEquals(count($items), count($rs));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
473
        foreach ($items as $key => $value) {
474
            $this->assertContains($key, $rs);
0 ignored issues
show
The method assertContains() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
475
        }
476
477
        // remove the first and the last item
478
        $this->assertSame(['missing'], $this->storage->removeItems(['missing', 'key1', 'key3']));
0 ignored issues
show
The method assertSame() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
479
        unset($items['key1'], $items['key3']);
480
481
        $rs = $this->storage->getItems(array_keys($items));
482
        $this->assertIsArray($rs);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
483
        foreach ($items as $key => $value) {
484
            $this->assertArrayHasKey($key, $rs);
0 ignored issues
show
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
485
            $this->assertEquals($value, $rs[$key]);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
486
        }
487
488
        $rs = $this->storage->hasItems(array_keys($items));
489
        $this->assertIsArray($rs);
0 ignored issues
show
The method assertIsArray() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
490
        $this->assertEquals(count($items), count($rs));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
491
        foreach ($items as $key => $value) {
492
            $this->assertContains($key, $rs);
0 ignored issues
show
The method assertContains() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
493
        }
494
    }
495
496
    public function testSetAndGetItemOfDifferentTypes() : void
497
    {
498
        $capabilities = $this->storage->getCapabilities();
499
500
        $types = [
501
            'NULL'     => null,
502
            'boolean'  => true,
503
            'integer'  => 12345,
504
            'double'   => 123.45,
505
            'string'   => 'string', // already tested
506
            'array'    => ['one', 'tow' => 'two', 'three' => ['four' => 'four']],
507
            'object'   => new stdClass(),
508
            'resource' => fopen(__FILE__, 'r'),
509
        ];
510
511
        $types['object']->one        = 'one';
512
        $types['object']->two        = new stdClass();
513
        $types['object']->two->three = 'three';
514
515
        foreach ($capabilities->getSupportedDatatypes() as $sourceType => $targetType) {
516
            if ($targetType === false) {
517
                continue;
518
            }
519
520
            $value = $types[$sourceType];
521
            $this->assertTrue(
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
522
                $this->storage->setItem('key', $value),
523
                sprintf(
524
                    "Failed to set type '%s'",
525
                    $sourceType
526
                )
527
            );
528
529
            if ($targetType === true) {
530
                $this->assertSame($value, $this->storage->getItem('key'));
531
            } elseif (is_string($targetType)) {
532
                settype($value, $targetType);
533
                $this->assertEquals($value, $this->storage->getItem('key'));
534
            }
535
        }
536
    }
537
538
    public function testSetItemReturnsFalseIfNonWritable() : void
539
    {
540
        $this->options->setWritable(false);
541
542
        $this->assertFalse($this->storage->setItem('key', 'value'));
543
        $this->assertFalse($this->storage->hasItem('key'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
544
    }
545
546
    public function testAddNewItem() : void
547
    {
548
        $this->assertTrue($this->storage->addItem('key', 'value'));
549
        $this->assertTrue($this->storage->hasItem('key'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
550
    }
551
552
    public function testAddItemReturnsFalseIfItemAlreadyExists() : void
553
    {
554
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
555
        $this->assertFalse($this->storage->addItem('key', 'newValue'));
556
    }
557
558
    public function testAddItemReturnsFalseIfNonWritable() : void
559
    {
560
        $this->options->setWritable(false);
561
562
        $this->assertFalse($this->storage->addItem('key', 'value'));
563
        $this->assertFalse($this->storage->hasItem('key'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
564
    }
565
566
    public function testAddItemsReturnsFailedKeys() : void
567
    {
568
        $this->assertTrue($this->storage->setItem('key1', 'value1'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
569
570
        $failedKeys = $this->storage->addItems([
571
            'key1' => 'XYZ',
572
            'key2' => 'value2',
573
        ]);
574
575
        $this->assertSame(['key1'], $failedKeys);
0 ignored issues
show
The method assertSame() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
576
        $this->assertSame('value1', $this->storage->getItem('key1'));
577
        $this->assertTrue($this->storage->hasItem('key2'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
578
    }
579
580
    public function testReplaceExistingItem() : void
581
    {
582
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
583
        $this->assertTrue($this->storage->replaceItem('key', 'anOtherValue'));
584
        $this->assertEquals('anOtherValue', $this->storage->getItem('key'));
585
    }
586
587
    public function testReplaceItemReturnsFalseOnMissingItem() : void
588
    {
589
        $this->assertFalse($this->storage->replaceItem('missingKey', 'value'));
590
    }
591
592
    public function testReplaceItemReturnsFalseIfNonWritable() : void
593
    {
594
        $this->storage->setItem('key', 'value');
595
        $this->options->setWritable(false);
596
597
        $this->assertFalse($this->storage->replaceItem('key', 'newvalue'));
598
        $this->assertEquals('value', $this->storage->getItem('key'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
599
    }
600
601
    public function testReplaceItemsReturnsFailedKeys() : void
602
    {
603
        $this->assertTrue($this->storage->setItem('key1', 'value1'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
604
605
        $failedKeys = $this->storage->replaceItems([
606
            'key1' => 'XYZ',
607
            'key2' => 'value2',
608
        ]);
609
610
        $this->assertSame(['key2'], $failedKeys);
0 ignored issues
show
The method assertSame() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
611
        $this->assertSame('XYZ', $this->storage->getItem('key1'));
612
        $this->assertFalse($this->storage->hasItem('key2'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
613
    }
614
615
    public function testRemoveItemReturnsFalseOnMissingItem() : void
616
    {
617
        $this->assertFalse($this->storage->removeItem('missing'));
618
    }
619
620
    public function testRemoveItemsReturnsMissingKeys() : void
621
    {
622
        $this->storage->setItem('key', 'value');
623
        $this->assertSame(['missing'], $this->storage->removeItems(['key', 'missing']));
624
    }
625
626
    public function testCheckAndSetItem() : void
627
    {
628
        $this->assertTrue($this->storage->setItem('key', 'value'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
629
630
        $success  = null;
631
        $casToken = null;
632
        $this->assertEquals('value', $this->storage->getItem('key', $success, $casToken));
633
        $this->assertNotNull($casToken);
634
635
        $this->assertTrue($this->storage->checkAndSetItem($casToken, 'key', 'newValue'));
636
        $this->assertFalse($this->storage->checkAndSetItem($casToken, 'key', 'failedValue'));
637
        $this->assertEquals('newValue', $this->storage->getItem('key'));
638
    }
639
640
    public function testIncrementItem() : void
641
    {
642
        $this->assertTrue($this->storage->setItem('counter', 10));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
643
        $this->assertEquals(15, $this->storage->incrementItem('counter', 5));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
644
        $this->assertEquals(15, $this->storage->getItem('counter'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
645
    }
646
647
    public function testIncrementItemInitialValue() : void
648
    {
649
        $this->assertEquals(5, $this->storage->incrementItem('counter', 5));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
650
        $this->assertEquals(5, $this->storage->getItem('counter'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
651
    }
652
653
    public function testIncrementItemReturnsFalseIfNonWritable() : void
654
    {
655
        $this->storage->setItem('key', 10);
656
        $this->options->setWritable(false);
657
658
        $this->assertFalse($this->storage->incrementItem('key', 5));
659
        $this->assertEquals(10, $this->storage->getItem('key'));
660
    }
661
662
    public function testIncrementItemsReturnsKeyValuePairsOfWrittenItems() : void
663
    {
664
        $this->assertTrue($this->storage->setItem('key1', 10));
665
666
        $result = $this->storage->incrementItems(['key1' => 10, 'key2' => 10]);
667
668
        ksort($result);
669
670
        $this->assertSame(['key1' => 20, 'key2' => 10], $result);
671
    }
672
673
    public function testIncrementItemsReturnsEmptyArrayIfNonWritable() : void
674
    {
675
        $this->storage->setItem('key', 10);
676
        $this->options->setWritable(false);
677
678
        $this->assertSame([], $this->storage->incrementItems(['key' => 5]));
679
        $this->assertEquals(10, $this->storage->getItem('key'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
680
    }
681
682
    public function testDecrementItem() : void
683
    {
684
        $this->assertTrue($this->storage->setItem('counter', 30));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
685
        $this->assertEquals(25, $this->storage->decrementItem('counter', 5));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
686
        $this->assertEquals(25, $this->storage->getItem('counter'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
687
    }
688
689
    public function testDecrementItemInitialValue() : void
690
    {
691
        $this->assertEquals(-5, $this->storage->decrementItem('counter', 5));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
692
        $this->assertEquals(-5, $this->storage->getItem('counter'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
693
    }
694
695
    public function testDecrementItemReturnsFalseIfNonWritable() : void
696
    {
697
        $this->storage->setItem('key', 10);
698
        $this->options->setWritable(false);
699
700
        $this->assertFalse($this->storage->decrementItem('key', 5));
701
        $this->assertEquals(10, $this->storage->getItem('key'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
702
    }
703
704
    public function testDecrementItemsReturnsEmptyArrayIfNonWritable() : void
705
    {
706
        $this->storage->setItem('key', 10);
707
        $this->options->setWritable(false);
708
709
        $this->assertSame([], $this->storage->decrementItems(['key' => 5]));
710
        $this->assertEquals(10, $this->storage->getItem('key'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...ctrineCacheStorageTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
711
    }
712
713
    public function testTouchItemReturnsFalseOnMissingItem() : void
714
    {
715
        $this->assertFalse($this->storage->touchItem('missing'));
716
    }
717
718
    public function testTouchItemReturnsFalseIfNonWritable() : void
719
    {
720
        $this->options->setWritable(false);
721
722
        $this->assertFalse($this->storage->touchItem('key'));
723
    }
724
725
    public function testTouchItemsReturnsGivenKeysIfNonWritable() : void
726
    {
727
        $this->options->setWritable(false);
728
        $this->assertSame(['key'], $this->storage->touchItems(['key']));
729
    }
730
731
    public function testSetItemAndSetItemsCallSaveWithTtl() : void
732
    {
733
        $ttl = rand();
734
735
        $provider = $this->createMock('Doctrine\Common\Cache\ArrayCache');
736
        $provider->expects($this->exactly(4))
737
                 ->method('save')
738
                 ->with($this->anything(), $this->anything(), $ttl);
739
740
        $this->storage = new DoctrineCacheStorage($this->options, $provider);
741
742
        $this->options->setTtl($ttl);
743
        $this->storage->setItem('key', 'value');
744
745
        $items = [
746
            'key1' => 'value1',
747
            'key2' => 'value2',
748
            'key3' => 'value3',
749
        ];
750
        $this->storage->setItems($items);
751
    }
752
}
753