CompositumTest::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace KochTest\Logger;
4
5
use Koch\Logger\Compositum;
6
use org\bovigo\vfs\vfsStream;
7
use org\bovigo\vfs\vfsStreamDirectory;
8
use org\bovigo\vfs\vfsStreamWrapper;
9
10
class CompositumTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Compositum
14
     */
15
    protected $object;
16
17
    public function setUp()
18
    {
19
        $this->object = new Compositum();
20
    }
21
22
    public function tearDown()
23
    {
24
        unset($this->object);
25
    }
26
27
    /**
28
     * @covers Koch\Logger\Compositum::Log
29
     */
30
    public function testLog()
31
    {
32
        // create a virtual error log file
33
        vfsStreamWrapper::register();
34
        $this->configFile = vfsStream::url('root/errorlog.txt');
0 ignored issues
show
Bug introduced by
The property configFile does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
        $this->file       = vfsStream::newFile('errorlog.txt', 0777)->withContent('someContent');
0 ignored issues
show
Bug introduced by
The property file does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
        $this->root       = new vfsStreamDirectory('root');
0 ignored issues
show
Bug introduced by
The property root does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
        $this->root->addChild($this->file);
38
        vfsStreamWrapper::setRoot($this->root);
39
40
        // add file logger and add virtual log file
41
        $logger = new \Koch\Logger\Adapter\File();
42
        $logger->setErrorLogFilename($this->configFile);
43
        $this->object->addLogger($logger);
0 ignored issues
show
Documentation introduced by
$logger is of type object<Koch\Logger\Adapter\File>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
45
        // setup message to log
46
        $message = 'TestMessage';
47
        $context = ['Context Info'];
48
        $level   = 'ERROR';
49
50
        $this->assertTrue($this->object->log($level, $message, $context));
51
    }
52
53
    /**
54
     * @covers Koch\Logger\Compositum::addLogger
55
     * @covers Koch\Logger\Compositum::removeLogger
56
     */
57
    public function testAddLogger()
58
    {
59
        // add
60
        $firebug = new \Koch\Logger\Adapter\Firebug();
61
        $this->object->addLogger($firebug);
0 ignored issues
show
Documentation introduced by
$firebug is of type object<Koch\Logger\Adapter\Firebug>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
        $this->assertEquals($firebug, $this->object->loggers[0]);
63
64
        // remove
65
        $this->object->removeLogger('firebug');
66
        $this->assertEquals([], $this->object->loggers);
67
    }
68
}
69