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

ReferenceTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
cbo 2
dl 0
loc 48
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A test__toString() 0 3 1
A getContainer() 0 8 1
A testGetterAndSetter() 0 5 1
A testBasicInvocation() 0 5 1
A testInvocationError() 0 5 1
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