1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spiral\Tests\Snapshotter; |
4
|
|
|
|
5
|
|
|
use Spiral\Debug\Configs\SnapshotConfig; |
6
|
|
|
use Spiral\Snapshotter\Bootloaders\FileHandlerBootloader; |
7
|
|
|
use Spiral\Snapshotter\DelegateSnapshot; |
8
|
|
|
use Spiral\Tests\BaseTest; |
9
|
|
|
|
10
|
|
|
class FileHandlerTest extends BaseTest |
11
|
|
|
{ |
12
|
|
|
public function testFileRender() |
13
|
|
|
{ |
14
|
|
|
$this->app->getBootloader()->bootload([FileHandlerBootloader::class]); |
15
|
|
|
|
16
|
|
|
$snapshot = $this->makeSnapshot('File error', 123); |
17
|
|
|
/** @var DelegateSnapshot $delegate */ |
18
|
|
|
$delegate = $this->factory->make(DelegateSnapshot::class, [ |
|
|
|
|
19
|
|
|
'exception' => $snapshot->getException() |
20
|
|
|
]); |
21
|
|
|
|
22
|
|
|
$this->assertEmpty($this->files->getFiles(directory('runtime') . 'logs/')); |
23
|
|
|
$this->assertEmpty($this->files->getFiles(directory('runtime') . 'snapshots/')); |
24
|
|
|
|
25
|
|
|
$delegate->report(); |
26
|
|
|
|
27
|
|
|
$this->assertNotEmpty($this->files->getFiles(directory('runtime') . 'logs/')); |
28
|
|
|
$this->assertNotEmpty($this->files->getFiles(directory('runtime') . 'snapshots/')); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testRotation() |
32
|
|
|
{ |
33
|
|
|
/** @var SnapshotConfig $config */ |
34
|
|
|
$config = $this->container->get(SnapshotConfig::class); |
35
|
|
|
|
36
|
|
|
$i = 0; |
37
|
|
|
$max = $config->maxSnapshots(); |
38
|
|
|
while ($i <= $max + 2) { |
39
|
|
|
//Create snapshots more than rotation allows |
40
|
|
|
$snapshot = $this->makeSnapshot('Message i=' . $i, 123); |
41
|
|
|
$this->handleFileSnapshot($snapshot); |
42
|
|
|
|
43
|
|
|
usleep(500000); |
44
|
|
|
$i++; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$this->assertNotEmpty($this->files->getFiles(directory('runtime') . 'snapshots/')); |
48
|
|
|
$this->assertCount($max, $this->files->getFiles(directory('runtime') . 'snapshots/')); |
49
|
|
|
} |
50
|
|
|
} |
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@property
annotation 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.