Passed
Pull Request — master (#1312)
by Michael
07:24
created

FileStorageTest::testFetch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xmf\Test\Key;
6
7
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
use Xmf\Key\FileStorage;
10
11
class FileStorageTest extends TestCase
12
{
13
    /**
14
     * @var FileStorage
15
     */
16
    protected $object;
17
    /**
18
     * @var string
19
     */
20
    protected $testKey = 'x-unit-test-key-file';
21
22
    /**
23
     * Sets up the fixture, for example, opens a network connection.
24
     * This method is called before a test is executed.
25
     */
26
    protected function setUp(): void
27
    {
28
        //$this->markTestIncomplete('FileStorage testing incomplete');
29
        $this->object = new FileStorage('/tmp', 'fubar');
30
    }
31
32
    /**
33
     * Tears down the fixture, for example, closes a network connection.
34
     * This method is called after a test is executed.
35
     */
36
    protected function tearDown(): void
37
    {
38
        @$this->object->delete($this->testKey);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for delete(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

38
        /** @scrutinizer ignore-unhandled */ @$this->object->delete($this->testKey);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
39
    }
40
41
    public function testSave()
42
    {
43
        $name = $this->testKey;
44
        $data = 'data';
45
        $this->object->save($name, $data);
46
        $this->assertEquals($data, $this->object->fetch($name));
47
    }
48
49
    public function testFetch()
50
    {
51
        $name = $this->testKey;
52
        $data = 'data';
53
        $this->assertFalse(@$this->object->fetch($name));
54
        $this->object->save($name, $data);
55
        $this->assertEquals($this->object->fetch($name), $data);
56
    }
57
58
    public function testExists()
59
    {
60
        $name = $this->testKey;
61
        $data = 'data';
62
        $this->assertFalse($this->object->exists($name));
63
        $this->object->save($name, $data);
64
        $this->assertTrue($this->object->exists($name));
65
    }
66
67
    public function testDelete()
68
    {
69
        $name = $this->testKey;
70
        $data = 'data';
71
        $this->object->save($name, $data);
72
        $this->assertTrue($this->object->exists($name));
73
        $this->assertTrue($this->object->delete($name));
74
        $this->assertFalse(@$this->object->delete($name));
75
        $this->assertFalse($this->object->exists($name));
76
    }
77
}
78