AbstractContainerAwareTestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getServiceByType() 0 5 1
A getContainer() 0 12 2
A getTestDirectory() 0 5 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Zenify\ModularLatteFilters\Tests\PHPUnit;
6
7
use Nette\Database\Context;
8
use Nette\DI\Container;
9
use PHPUnit\Framework\TestCase;
10
use ReflectionClass;
11
use Zenify\ModularLatteFilters\Tests\ContainerFactory;
12
13
14
abstract class AbstractContainerAwareTestCase extends TestCase
15
{
16
17
	/**
18
	 * @var Container[]
19
	 */
20
	private static $containers = [];
21
22
23
	/**
24
	 * @return object
25
	 */
26
	protected function getServiceByType(string $class)
27
	{
28
		return $this->getContainer()
29
			->getByType($class);
30
	}
31
32
33
	private function getContainer(): Container
34
	{
35
		if (isset(self::$containers[$this->getTestDirectory()])) {
36
			return self::$containers[$this->getTestDirectory()];
37
		}
38
39
		$container = (new ContainerFactory)->createWithConfig($this->getTestDirectory() . '/config/config.neon');
40
41
		self::$containers[$this->getTestDirectory()] = $container;
42
43
		return $container;
44
	}
45
46
47
	private function getTestDirectory(): string
48
	{
49
		$testFilename = (new ReflectionClass($this))->getFileName();
50
		return dirname($testFilename);
51
	}
52
53
}
54