Completed
Push — master ( a5dee7...adf519 )
by Changwan
04:02
created

TestingKernel   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 17 3
1
<?php
2
namespace Wandu\Foundation\Kernels;
3
4
use PHPUnit_Framework_Test;
5
use Wandu\DI\ContainerInterface;
6
use Wandu\DI\Exception\CannotInjectException;
7
use Wandu\Foundation\Contracts\DefinitionInterface;
8
9
class TestingKernel extends KernelAbstract
10
{
11
    /** @var \PHPUnit_Framework_Test */
12
    protected $test;
13
14
    public function __construct(DefinitionInterface $definition, PHPUnit_Framework_Test $test)
15
    {
16
        parent::__construct($definition);
17
        $this->test = $test;
18
    }
19
    
20
    public function execute(ContainerInterface $app)
21
    {
22
        $this->useErrorHandling();
23
        try {
24
            $app->inject($this->test);
25
        } catch (CannotInjectException $exception) {
26
            $propertyName = $exception->getProperty();
27
            $className = $exception->getClass();
28
            if (class_exists($className)) {
29
                $app->inject($this->test, [
30
                    $propertyName => $app->create($className)
31
                ]);
32
            } else {
33
                throw $exception;
34
            }
35
        }
36
    }
37
}
38