|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spiral\Tests\Snapshotter; |
|
4
|
|
|
|
|
5
|
|
|
use Spiral\Debug\Configs\SnapshotConfig; |
|
6
|
|
|
use Spiral\Snapshotter\AggregationHandler; |
|
7
|
|
|
use Spiral\Snapshotter\AggregationHandler\Database\IncidentRecord; |
|
8
|
|
|
use Spiral\Snapshotter\AggregationHandler\Database\SnapshotRecord; |
|
9
|
|
|
use Spiral\Snapshotter\Bootloaders\FileSnapshotterBootloader; |
|
10
|
|
|
use Spiral\Snapshotter\DelegateSnapshot; |
|
11
|
|
|
use Spiral\Tests\BaseTest; |
|
12
|
|
|
|
|
13
|
|
|
class FileHandlerTest extends BaseTest |
|
14
|
|
|
{ |
|
15
|
|
|
public function testFileRender() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->app->getBootloader()->bootload([FileSnapshotterBootloader::class]); |
|
18
|
|
|
|
|
19
|
|
|
$snapshot = $this->makeSnapshot('File error', 123); |
|
20
|
|
|
/** @var DelegateSnapshot $delegate */ |
|
21
|
|
|
$delegate = $this->factory->make(DelegateSnapshot::class, [ |
|
|
|
|
|
|
22
|
|
|
'exception' => $snapshot->getException() |
|
23
|
|
|
]); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertEmpty($this->files->getFiles(directory('runtime') . 'logs/')); |
|
26
|
|
|
$this->assertEmpty($this->files->getFiles(directory('runtime') . 'snapshots/')); |
|
27
|
|
|
|
|
28
|
|
|
$delegate->report(); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertNotEmpty($this->files->getFiles(directory('runtime') . 'logs/')); |
|
31
|
|
|
$this->assertNotEmpty($this->files->getFiles(directory('runtime') . 'snapshots/')); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testRotation() |
|
35
|
|
|
{ |
|
36
|
|
|
/** @var SnapshotConfig $config */ |
|
37
|
|
|
$config = $this->container->get(SnapshotConfig::class); |
|
38
|
|
|
|
|
39
|
|
|
$i = 0; |
|
40
|
|
|
$max = $config->maxSnapshots(); |
|
41
|
|
|
while ($i <= $max + 2) { |
|
42
|
|
|
//Create snapshots more than rotation allows |
|
43
|
|
|
$snapshot = $this->makeSnapshot('Message i=' . $i, 123); |
|
44
|
|
|
$this->handleFileSnapshot($snapshot); |
|
45
|
|
|
|
|
46
|
|
|
usleep(500000); |
|
47
|
|
|
$i++; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->assertNotEmpty($this->files->getFiles(directory('runtime') . 'snapshots/')); |
|
51
|
|
|
$this->assertCount($max, $this->files->getFiles(directory('runtime') . 'snapshots/')); |
|
52
|
|
|
} |
|
53
|
|
|
} |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.