Passed
Pull Request — master (#82)
by David
02:28
created

WeakrefObjectStorageTest::testDanglingPointers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace TheCodingMachine\TDBM;
4
5
6
class WeakrefObjectStorageTest extends \PHPUnit_Framework_TestCase
7
{
8
    public function testObjectStorage()
9
    {
10
        $objectStorage = new WeakrefObjectStorage();
11
        $this->assertNull($objectStorage->get('foo', 42));
12
        $dbRow = $this->createMock(DbRow::class);
13
        $objectStorage->set('foo', 42, $dbRow);
14
        $this->assertSame($dbRow, $objectStorage->get('foo', 42));
15
        $objectStorage->remove('foo', 42);
16
        $this->assertNull($objectStorage->get('foo', 42));
17
    }
18
19
    public function testDanglingPointers()
20
    {
21
        $objectStorage = new WeakrefObjectStorage();
22
        $dbRow = $this->createMock(DbRow::class);
23
24
        for ($i=0; $i<10001; $i++) {
25
            $objectStorage->set('foo', $i, clone $dbRow);
26
        }
27
        $this->assertNull($objectStorage->get('foo', 42));
28
    }
29
}
30