Completed
Pull Request — master (#3)
by Valentin
14:15
created

FileHandlerTest::testFileRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
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, [
0 ignored issues
show
Documentation introduced by
The property factory does not exist on object<Spiral\Tests\Snapshotter\FileHandlerTest>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
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
}