Completed
Push — master ( e401e5...bd7189 )
by Julien
01:48
created

ReferenceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
nc 1
cc 1
eloc 2
nop 0
1
<?php
2
3
namespace Fwk\Di;
4
5
/**
6
 */
7
class ReferenceTest extends \PHPUnit_Framework_TestCase {
8
9
    /**
10
     * @var Reference
11
     */
12
    protected $object;
13
14
    /**
15
     */
16
    protected function setUp() {
17
        $this->object = new Reference("testRef");
18
    }
19
20
    protected function getContainer() {
21
        $container = new Container();
22
        $container->set('test.param', 'parameterValue');
23
        $container->set('callable', function($c) { return 'callValue'; });
24
        $container->set('shared', function($c) { $a = new \stdClass(); $a->mt = microtime(true); return $a; }, true);
0 ignored issues
show
Unused Code introduced by
The call to Container::set() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
25
        
26
        return $container;
27
    }
28
    
29
    /**
30
     */
31
    public function testGetterAndSetter() {
32
        $this->assertEquals("testRef", $this->object->getName());
33
        $this->object->setName("testRefName");
34
        $this->assertEquals("testRefName", $this->object->getName());
35
    }
36
37
    /**
38
     */
39
    public function test__toString(){
0 ignored issues
show
Coding Style introduced by
function test__toString() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
40
        $this->assertEquals("testRef", (string)$this->object);
41
    }
42
    
43
    public function testBasicInvocation()
44
    {
45
        $this->object->setName('test.param');
46
        $this->assertEquals('parameterValue', $this->object->invoke($this->getContainer()));
47
    }
48
    
49
    public function testInvocationError()
50
    {
51
        $this->setExpectedException('Fwk\Di\Exceptions\InvalidReferenceException');
52
        $this->object->invoke($this->getContainer());
53
    }
54
}
55