Passed
Push — master ( 27db62...76242e )
by David
03:48 queued 51s
created

testObjectStorage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 13
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace TheCodingMachine\TDBM;
4
5
use PHPUnit\Framework\TestCase;
6
7
class NativeWeakrefObjectStorageTest extends TestCase
8
{
9
    public function testObjectStorage(): void
10
    {
11
        if (!\class_exists(\WeakReference::class)) {
0 ignored issues
show
Bug introduced by
The type WeakReference 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...
12
            $this->markTestSkipped('PHP 7.4+ only');
13
            return;
14
        }
15
        $objectStorage = new NativeWeakrefObjectStorage();
16
        $this->assertNull($objectStorage->get('foo', 42));
17
        $dbRow = $this->createMock(DbRow::class);
18
        $objectStorage->set('foo', 42, $dbRow);
19
        $this->assertSame($dbRow, $objectStorage->get('foo', 42));
20
        $objectStorage->remove('foo', 42);
21
        $this->assertNull($objectStorage->get('foo', 42));
22
    }
23
24
    public function testDanglingPointers(): void
25
    {
26
        if (!\class_exists(\WeakReference::class)) {
27
            $this->markTestSkipped('PHP 7.4+ only');
28
            return;
29
        }
30
        $objectStorage = new NativeWeakrefObjectStorage();
31
        $dbRow = $this->createMock(DbRow::class);
32
33
        for ($i=0; $i<10001; $i++) {
34
            $objectStorage->set('foo', $i, clone $dbRow);
35
        }
36
        $this->assertNull($objectStorage->get('foo', 42));
37
    }
38
}
39