Passed
Push — master ( 11230f...5f5cdb )
by Jakub
12:32
created

ContainerSuiteFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
ccs 4
cts 5
cp 0.8
cc 2
nc 2
nop 1
crap 2.032
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MyTester\Bridges\NetteDI;
6
7
use MyTester\InvalidTestCaseException;
8
use MyTester\TestCase;
9
use Nette\DI\Container;
10
11
/**
12
 * @author Jakub Konečný
13
 * @internal
14
 */
15
final class ContainerSuiteFactory implements \MyTester\ITestSuiteFactory
16
{
17
    private Container $container;
18
19 1
    public function __construct(Container $container)
20
    {
21 1
        $this->container = $container;
22
    }
23
24
  /**
25
   * @param class-string $className
26
   */
27 1
    public function create(string $className): TestCase
28
    {
29 1
        $suit = $this->container->getByType($className);
30 1
        if (!$suit instanceof TestCase) {
31
            throw new InvalidTestCaseException("$className is not a descendant of " . TestCase::class . ".");
32
        }
33 1
        return $suit;
34
    }
35
}
36