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

WeakrefObjectStorageTest::testObjectStorage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
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
        if (!\class_exists(\WeakRef::class)) {
0 ignored issues
show
Bug introduced by
The type WeakRef was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
            $this->markTestSkipped('No weakref extension detected');
12
            return;
13
        }
14
        $objectStorage = new WeakrefObjectStorage();
15
        $this->assertNull($objectStorage->get('foo', 42));
16
        $dbRow = $this->createMock(DbRow::class);
17
        $objectStorage->set('foo', 42, $dbRow);
18
        $this->assertSame($dbRow, $objectStorage->get('foo', 42));
19
        $objectStorage->remove('foo', 42);
20
        $this->assertNull($objectStorage->get('foo', 42));
21
    }
22
23
    public function testDanglingPointers()
24
    {
25
        if (!\class_exists(\WeakRef::class)) {
26
            $this->markTestSkipped('No weakref extension detected');
27
            return;
28
        }
29
        $objectStorage = new WeakrefObjectStorage();
30
        $dbRow = $this->createMock(DbRow::class);
31
32
        for ($i=0; $i<10001; $i++) {
33
            $objectStorage->set('foo', $i, clone $dbRow);
34
        }
35
        $this->assertNull($objectStorage->get('foo', 42));
36
    }
37
}
38