CommonTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 43
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddingMethod() 0 15 1
A testConstruct() 0 13 1
A testSetter() 0 9 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: horat1us
5
 * Date: 5/8/17
6
 * Time: 5:23 PM
7
 */
8
9
namespace Horat1us\MethodInjection\Tests;
10
11
12
use Horat1us\MethodInjection\DynamicObject;
13
14
class CommonTest extends \PHPUnit_Framework_TestCase
15
{
16
17
    public function testAddingMethod()
18
    {
19
        $object = new DynamicObject();
20
        $expected = mt_rand();
21
        $method = function () use ($expected) {
22
            return $expected;
23
        };
24
        $object->injectMethod('test', $method);
25
        $res = $object->{'test'}();
26
        $this->assertEquals($expected, $res);
27
28
        $object->{'js'} = $method;
29
        $res = $object->{'js'}();
30
        $this->assertEquals($expected, $res);
31
    }
32
33
    public function testConstruct()
34
    {
35
        $object = new DynamicObject([
36
            'true' => function () {
37
                return true;
38
            },
39
            'false' => function () {
40
                return false;
41
            }
42
        ]);
43
        $this->assertTrue($object->{'true'}());
44
        $this->assertFalse($object->{'false'}());
45
    }
46
47
    public function testSetter()
48
    {
49
        $object = new DynamicObject();
50
        $this->assertTrue($object->__set('test', function() {
51
        }));
52
        $this->assertInstanceOf(\Closure::class, $object->{'test'});
53
        $this->assertFalse($object->__set('test', 2));
54
        $this->assertEquals(2, $object->{'test'});
55
    }
56
}