ProophTestCase   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A givenContainerWithLoadedBundlesWithGivenConfig() 0 8 1
A whenBootKernelWithConfig() 0 6 1
A whenGetFromContainer() 0 4 1
A thenIsInstanceOfGivenClass() 0 4 1
A thenPass() 0 4 1
A willThrowException() 0 4 1
A bootKernelWithBundlesAndGivenConfigFile() 0 16 1
A bootKernelWith() 0 11 1
1
<?php declare(strict_types = 1);
2
3
namespace TomCizek\SymfonyProoph\Tests\Configurators;
4
5
use PHPUnit\Framework\TestCase;
6
use Prooph\InteropBundle\ProophInteropBundle;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use TomCizek\SymfonyInteropContainer\Tests\Configurators\ConfigFile;
9
use TomCizek\SymfonyProoph\ProophBundle;
10
use TomCizek\SymfonyProoph\Tests\TestKernel;
11
12
abstract class ProophTestCase extends TestCase
13
{
14
	const FIXTURE_CONGIGS_DIR = __DIR__ . '/fixtures/';
15
16
	/** @var ContainerInterface */
17
	protected $container;
18
19
	protected function givenContainerWithLoadedBundlesWithGivenConfig(
20
		string $configFile,
21
		string $configType = 'yml'
22
	): void {
23
		$kernel = $this->bootKernelWithBundlesAndGivenConfigFile($configFile, $configType);
24
25
		$this->container = $kernel->getContainer();
26
	}
27
28
	public function whenBootKernelWithConfig(
29
		string $configFile,
30
		string $configType = 'yml'
31
	): void {
32
		$this->bootKernelWithBundlesAndGivenConfigFile($configFile, $configType);
33
	}
34
35
	protected function whenGetFromContainer(string $serviceId)
36
	{
37
		return $this->container->get($serviceId);
38
	}
39
40
	protected function thenIsInstanceOfGivenClass($expected, $actual): void
41
	{
42
		self::assertInstanceOf($expected, $actual);
43
	}
44
45
	protected function thenPass(): void
46
	{
47
		self::assertTrue(true);
48
	}
49
50
	protected function willThrowException(string $exceptionClassName)
51
	{
52
		$this->expectException($exceptionClassName);
53
	}
54
55
	protected function bootKernelWithBundlesAndGivenConfigFile(
56
		string $configFile,
57
		string $configType = 'yml'
58
	): TestKernel {
59
		$kernel = $this->bootKernelWith(
60
			[
61
				ProophInteropBundle::class,
62
				ProophBundle::class,
63
			],
64
			[
65
				ConfigFile::record(self::FIXTURE_CONGIGS_DIR . $configFile, $configType),
66
			]
67
		);
68
69
		return $kernel;
70
	}
71
72
	/**
73
	 * @param string[]     $bundles
74
	 * @param ConfigFile[] $configFiles
75
	 *
76
	 * @return TestKernel
77
	 */
78
	protected function bootKernelWith(array $bundles = [], array $configFiles = []): TestKernel
79
	{
80
		$randomEnvironment = bin2hex(random_bytes(10));
81
		$kernel = new TestKernel($randomEnvironment, true);
82
83
		$kernel->addBundleClasses($bundles);
84
		$kernel->addConfigFiles($configFiles);
85
		$kernel->boot();
86
87
		return $kernel;
88
	}
89
}
90