RegistryTest::setUp()   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\Registry;
4
5
use Koch\Registry\Registry;
6
7
class RegistryTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var Registry
11
     */
12
    protected $object;
13
14
    /**
15
     * Sets up the fixture, for example, opens a network connection.
16
     * This method is called before a test is executed.
17
     */
18
    protected function setUp()
19
    {
20
        $this->object = new Registry();
21
    }
22
23
    /**
24
     * Tears down the fixture, for example, closes a network connection.
25
     * This method is called after a test is executed.
26
     */
27
    protected function tearDown()
28
    {
29
        unset($this->object);
30
    }
31
32
    /**
33
     * @covers Koch\Registry\Registry::set
34
     */
35
    public function testSet()
36
    {
37
        // set object to registry
38
        $a = new \stdClass();
39
        $this->object->set('A', $a);
0 ignored issues
show
Documentation introduced by
$a is of type object<stdClass>, but the function expects a object<Koch\Registry\type>.

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...
40
41
        $this->assertTrue($this->object->has('A'));
42
43
        // set classname to registry
44
        $this->object->set('B', 'B');
0 ignored issues
show
Documentation introduced by
'B' is of type string, but the function expects a object<Koch\Registry\type>.

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...
45
        $this->assertTrue($this->object->has('B'));
46
47
        // set closure (as a resolver) to registry
48
        $closure = function () {
49
            return new \stdClass();
50
        };
51
        $this->object->set('C', $closure);
0 ignored issues
show
Documentation introduced by
$closure is of type object<Closure>, but the function expects a object<Koch\Registry\type>.

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...
52
53
        $this->assertTrue($this->object->has('C'));
54
    }
55
56
    /**
57
     * @covers Koch\Registry\Registry::has
58
     */
59
    public function testHas()
60
    {
61
        // set object to registry
62
        $a = new \stdClass();
63
        $this->object->set('A', $a);
0 ignored issues
show
Documentation introduced by
$a is of type object<stdClass>, but the function expects a object<Koch\Registry\type>.

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...
64
65
        $this->assertTrue($this->object->has('A'));
66
    }
67
68
    /**
69
     * @covers Koch\Registry\Registry::get
70
     * @expectedException InvalidArgumentException
71
     * @expectedExceptionMessage No resolver found for "AB". Register a resolver.
72
     */
73
    public function testGetThrowsException()
74
    {
75
        // throws exception on trying to fetch non existing class from registry
76
        $this->object->get('AB');
77
    }
78
79
    /**
80
     * @covers Koch\Registry\Registry::get
81
     */
82
    public function testGet()
83
    {
84
        // set object to registry
85
        $a = new \stdClass();
86
        $this->object->set('A', $a);
0 ignored issues
show
Documentation introduced by
$a is of type object<stdClass>, but the function expects a object<Koch\Registry\type>.

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...
87
88
        $resultA = $this->object->get('A');
89
90
        $this->assertInstanceOf('StdClass', $resultA);
91
92
        // set classname to registry
93
        $this->object->set('B', 'KochTest\Registry\B');
0 ignored issues
show
Documentation introduced by
'KochTest\\Registry\\B' is of type string, but the function expects a object<Koch\Registry\type>.

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...
94
95
        $resultB = $this->object->get('B');
96
97
        $this->assertInstanceOf('KochTest\Registry\B', $resultB);
98
99
        // set closure (as a resolver) to registry
100
        $closure = function () {
101
            return new \stdClass();
102
        };
103
        $this->object->set('C', $closure);
0 ignored issues
show
Documentation introduced by
$closure is of type object<Closure>, but the function expects a object<Koch\Registry\type>.

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...
104
105
        $resultC = $this->object->get('C');
106
107
        $this->assertInstanceOf('StdClass', $resultC);
108
    }
109
}
110
111
class B
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
112
{
113
    // nothing
114
}
115