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

TestingKernel::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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