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

CallableDefinitionTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
cbo 3
dl 0
loc 50
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A getContainer() 0 8 1
A testSimpleInvocation() 0 6 1
A testSimpleInvocationError() 0 7 1
A testInvokeWithErroneousArguments() 0 6 1
1
<?php
2
3
namespace Fwk\Di\Definitions;
4
use Fwk\Di\Container;
5
use Fwk\Di\Reference;
6
7
/**
8
 * Test class for CallableDefinition.
9
 * Generated by PHPUnit on 2013-06-28 at 00:09:38.
10
 */
11
class CallableDefinitionTest extends \PHPUnit_Framework_TestCase {
12
13
    /**
14
     * @var CallableDefinition
15
     */
16
    protected $object;
17
18
    public $testPoint = false;
19
    
20
    public function setUp()
21
    {
22
        $me = $this;
23
        $this->object = new CallableDefinition(function() use ($me) { 
24
            $me->testPoint = true; 
25
        });
26
    }
27
    
28
    protected function getContainer()
29
    {
30
        $container = new Container();
31
        $container['className'] = '\stdClass';
32
        $container->set('temp.dir', function($c) { return sys_get_temp_dir(); });
33
        
34
        return $container;
35
    }
36
    
37
    public function testSimpleInvocation()
38
    {
39
        $this->assertFalse($this->testPoint);
40
        $this->object->invoke($this->getContainer());
41
        $this->assertTrue($this->testPoint);
42
    }
43
    
44
    public function testSimpleInvocationError()
45
    {
46
        \PHPUnit_Framework_Error_Notice::$enabled = FALSE;
47
        $this->object->setCallable(array('SimplyNot', 'callable'));
48
        $this->setExpectedException('\Fwk\Di\Exceptions\InvalidCallableDefinitionException');
49
        $this->object->invoke($this->getContainer());
50
    }
51
    
52
    /**
53
     */
54
    public function testInvokeWithErroneousArguments() {
55
        $this->object->setCallable('date_default_timezone_set');
56
        $this->object->addArgument(new Reference('invalid_ref'));
57
        $this->setExpectedException('Fwk\Di\Exceptions\InvalidCallableDefinitionException');
58
        $it = $this->object->invoke($this->getContainer());
0 ignored issues
show
Unused Code introduced by
$it is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
59
    }
60
}