-
-
Notifications
You must be signed in to change notification settings - Fork 471
Expand file tree
/
Copy pathTelemetryStorageTest.php
More file actions
78 lines (62 loc) · 2.13 KB
/
Copy pathTelemetryStorageTest.php
File metadata and controls
78 lines (62 loc) · 2.13 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace Sentry\Tests\Util;
use PHPUnit\Framework\TestCase;
use Sentry\Util\TelemetryStorage;
final class TelemetryStorageTest extends TestCase
{
public function testUnboundedPushAndToArray(): void
{
$storage = TelemetryStorage::unbounded();
$storage->push('foo');
$storage->push('bar');
$result = $storage->toArray();
$this->assertSame(2, $storage->count());
$this->assertEquals(['foo', 'bar'], $result);
}
public function testUnboundedDrainClearsStorage(): void
{
$storage = TelemetryStorage::unbounded();
$storage->push('foo');
$storage->push('bar');
$this->assertSame(2, $storage->count());
$result = $storage->drain();
$this->assertTrue($storage->isEmpty());
$this->assertEquals(['foo', 'bar'], $result);
}
public function testUnboundedIsEmpty(): void
{
$storage = TelemetryStorage::unbounded();
$this->assertTrue($storage->isEmpty());
$storage->push('foo');
$this->assertFalse($storage->isEmpty());
}
public function testBoundedCapacityOverwritesOldestItems(): void
{
$storage = TelemetryStorage::bounded(2);
$storage->push('foo');
$storage->push('bar');
$storage->push('baz');
$this->assertSame(2, $storage->count());
$this->assertEquals(['bar', 'baz'], $storage->toArray());
}
public function testBoundedDrainReturnsLogicalOrderAndClearsStorage(): void
{
$storage = TelemetryStorage::bounded(2);
$storage->push('foo');
$storage->push('bar');
$storage->push('baz');
$this->assertSame(2, $storage->count());
$result = $storage->drain();
$this->assertTrue($storage->isEmpty());
$this->assertEquals(['bar', 'baz'], $result);
}
public function testBoundedCapacityOneKeepsLatestItem(): void
{
$storage = TelemetryStorage::bounded(1);
$storage->push('foo');
$storage->push('bar');
$this->assertCount(1, $storage);
$this->assertEquals(['bar'], $storage->toArray());
}
}