Passed
Pull Request — master (#208)
by David
08:37
created

testDanglingPointers()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 3
nop 0
1
<?php
2
3
namespace TheCodingMachine\TDBM;
4
5
use PHPUnit\Framework\TestCase;
6
7
class WeakreferenceObjectStorageTest 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