FileHandlerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 8
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFileRender() 0 18 1
A testRotation() 0 19 2
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, [
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...
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
}