IntegrationTest::createKernel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Tactician\Bundle\Tests\Integration;
6
7
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
8
use Symfony\Component\Filesystem\Filesystem;
9
use Symfony\Component\HttpKernel\Kernel;
10
use Symfony\Component\Yaml\Yaml;
11
12
abstract class IntegrationTest extends KernelTestCase
13
{
14
    /**
15
     * @var Kernel
16
     */
17
    protected static $kernel;
18
19
    /**
20
     * @var Filesystem
21
     */
22
    private $filesystem;
23
24
    protected static function createKernel(array $options = array())
25
    {
26
        require_once __DIR__.'/../testapp/AppKernel.php';
27
28
        return new \AppKernel('test', true);
29
    }
30
31
    protected function setUp(): void
32
    {
33
        static::$kernel = static::createKernel();
34
        $this->filesystem = new Filesystem();
35
36
        $cacheDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'tactician-bundle'.DIRECTORY_SEPARATOR.uniqid("tactician-bundle", true);
37
38
        $this->filesystem->mkdir($cacheDir);
39
        static::$kernel->defineCacheDir($cacheDir);
40
    }
41
42
    protected function tearDown(): void
43
    {
44
        $this->filesystem->remove(
45
            static::$kernel->getCacheDir()
46
        );
47
    }
48
49
    protected function givenConfig($namespace, $config)
50
    {
51
        static::$kernel->loadConfig($namespace, Yaml::parse((string) $config));
52
    }
53
54
    protected function registerService($serviceId, $className, array $tags)
55
    {
56
        static::$kernel->addServiceToRegister($serviceId, $className, $tags);
57
    }
58
59
    protected function handleCommand($busId, $commandClass, array $args = [])
60
    {
61
        $class = new \ReflectionClass($commandClass);
62
        $command = $class->newInstanceArgs($args);
63
64
        static::$kernel->boot();
65
        static::$kernel->getContainer()->get('tactician.commandbus.'.$busId)->handle($command);
66
    }
67
}
68