Test Failed
Branch v0.2 (3f77aa)
by Freddie
07:42 queued 01:11
created

FunctionalTest::getContainer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Simplex\Quickstart\Shared\Testing;
4
5
use DI\Container;
6
use Helmich\JsonAssert\JsonAssertions;
7
use Helmich\Psr7Assert\Psr7Assertions;
8
use Mockery as m;
9
use PHPUnit\Framework\TestCase;
10
use Simplex\Bootstrap;
11
12
class FunctionalTest extends TestCase
13
{
14
    use HttpRequestCapabilities;
15
    use JsonAssertions;
16
    use Psr7Assertions;
17
18
    const CONFIG_DIRECTORY_PATH = __DIR__ . '/../../../config';
19
20
    protected $reloadDb = true;
21
22
    /** @var Container */
23
    private static $container;
24
25
    protected function setUp()
26
    {
27
        if ($this->reloadDb) {
28
            $loader = $this->getContainer()->get(FixtureLoader::class);
29
            $loader->load();
30
        }
31
32
        parent::setUp();
33
    }
34
35
    protected function tearDown()
36
    {
37
        m::close();
38
39
        $this->reloadDb = true;
40
41
        parent::tearDown();
42
    }
43
44
    public function getFromContainer(string $id)
45
    {
46
        return $this->getContainer()->get($id);
47
    }
48
49
    public function getContainer(): Container
50
    {
51
        if (!isset(self::$container)) {
52
            Bootstrap::init(self::CONFIG_DIRECTORY_PATH);
53
            self::$container = Bootstrap::getContainer();
54
        }
55
56
        return self::$container;
57
    }
58
59
    public function setInContainer($name, $value): void
60
    {
61
        $this->getContainer()->set($name, $value);
62
    }
63
}
64