Failed Conditions
Pull Request — 2.6 (#7778)
by Luís
07:03
created

corruptedDataDoesNotLeakIntoApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Cache;
4
5
use Doctrine\Tests\Mocks\CacheEntryMock;
6
use Doctrine\Tests\Mocks\CacheKeyMock;
7
use Doctrine\ORM\Cache\Region\DefaultMultiGetRegion;
8
use Doctrine\ORM\Cache\CollectionCacheEntry;
9
10
/**
11
 * @author  Asmir Mustafic <[email protected]>
12
 */
13
class MultiGetRegionTest extends AbstractRegionTest
14
{
15
    protected function createRegion()
16
    {
17
        return new DefaultMultiGetRegion('default.region.test', $this->cache);
18
    }
19
20
    public function testGetMulti()
21
    {
22
        $key1 = new CacheKeyMock('key.1');
23
        $value1 = new CacheEntryMock(['id' => 1, 'name' => 'bar']);
24
25
        $key2 = new CacheKeyMock('key.2');
26
        $value2 = new CacheEntryMock(['id' => 2, 'name' => 'bar']);
27
28
        $this->assertFalse($this->region->contains($key1));
29
        $this->assertFalse($this->region->contains($key2));
30
31
        $this->region->put($key1, $value1);
32
        $this->region->put($key2, $value2);
33
34
        $this->assertTrue($this->region->contains($key1));
35
        $this->assertTrue($this->region->contains($key2));
36
37
        $actual = $this->region->getMultiple(new CollectionCacheEntry([$key1, $key2]));
38
39
        $this->assertEquals($value1, $actual[0]);
40
        $this->assertEquals($value2, $actual[1]);
41
    }
42
43
    /**
44
     * @test
45
     * @group GH7266
46
     */
47
    public function corruptedDataDoesNotLeakIntoApplication() : void
48
    {
49
        $key1 = new CacheKeyMock('key.1');
50
        $this->cache->save($this->region->getName() . '_' . $key1->hash, 'a-very-invalid-value');
51
52
        self::assertTrue($this->region->contains($key1));
53
        self::assertNull($this->region->getMultiple(new CollectionCacheEntry([$key1])));
54
    }
55
}
56