-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathNativeWeakrefObjectStorageTest.php
More file actions
38 lines (33 loc) · 1.16 KB
/
NativeWeakrefObjectStorageTest.php
File metadata and controls
38 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace TheCodingMachine\TDBM;
use PHPUnit\Framework\TestCase;
class NativeWeakrefObjectStorageTest extends TestCase
{
public function testObjectStorage(): void
{
if (!\class_exists(\WeakReference::class)) {
$this->markTestSkipped('PHP 7.4+ only');
return;
}
$objectStorage = new NativeWeakrefObjectStorage();
$this->assertNull($objectStorage->get('foo', 42));
$dbRow = $this->createMock(DbRow::class);
$objectStorage->set('foo', 42, $dbRow);
$this->assertSame($dbRow, $objectStorage->get('foo', 42));
$objectStorage->remove('foo', 42);
$this->assertNull($objectStorage->get('foo', 42));
}
public function testDanglingPointers(): void
{
if (!\class_exists(\WeakReference::class)) {
$this->markTestSkipped('PHP 7.4+ only');
return;
}
$objectStorage = new NativeWeakrefObjectStorage();
$dbRow = $this->createMock(DbRow::class);
for ($i = 0; $i < 10001; $i++) {
$objectStorage->set('foo', $i, clone $dbRow);
}
$this->assertNull($objectStorage->get('foo', 42));
}
}