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

WeakrefObjectStorageTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testObjectStorage() 0 9 1
A testDanglingPointers() 0 9 2
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