Passed
Push — master ( b80d77...ea8430 )
by Kevin
14:18 queued 12:14
created

Factories::_setUpFactories()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 9.8666
cc 4
nc 3
nop 0
crap 4
1
<?php
2
3
namespace Zenstruck\Foundry\Test;
4
5
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6
use Zenstruck\Foundry\Factory;
7
8
/**
9
 * @mixin KernelTestCase
10
 *
11
 * @author Kevin Bond <[email protected]>
12
 */
13
trait Factories
14
{
15
    /**
16
     * @internal
17
     * @before
18
     */
19 731
    public static function _setUpFactories(): void
20
    {
21 731
        if (!\is_subclass_of(static::class, KernelTestCase::class)) {
22 264
            TestState::bootFoundry();
23
24 264
            return;
25
        }
26
27 467
        if (!static::$booted) {
28 467
            static::bootKernel();
29
        }
30
31 467
        TestState::bootFromContainer(static::$kernel->getContainer());
32 467
        Factory::configuration()->setManagerRegistry(
33
            new LazyManagerRegistry(static function() {
34 214
                if (!static::$booted) {
35 214
                    static::bootKernel();
36
                }
37
38 214
                return static::$kernel->getContainer()->get('doctrine');
39 467
            })
40
        );
41
42 467
        self::ensureKernelShutdown();
43 467
    }
44
45
    /**
46
     * @internal
47
     * @after
48
     */
49 731
    public static function _tearDownFactories(): void
50
    {
51 731
        TestState::shutdownFoundry();
52 731
    }
53
}
54