Factories::_tearDownFactories()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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 964
    public static function _setUpFactories(): void
20
    {
21 964
        if (!\is_subclass_of(static::class, KernelTestCase::class)) {
22 330
            TestState::bootFoundry();
23
24 330
            return;
25
        }
26
27 634
        $kernel = static::createKernel();
28 634
        $kernel->boot();
29
30 634
        TestState::bootFromContainer($kernel->getContainer());
31 634
        Factory::configuration()->setManagerRegistry(
32
            new LazyManagerRegistry(static function() {
33 588
                if (!static::$booted) {
34 588
                    static::bootKernel();
35
                }
36
37 588
                return TestState::initializeChainManagerRegistry(static::$kernel->getContainer());
38 634
            }
39
            )
40
        );
41 634
42 634
        $kernel->shutdown();
43
    }
44
45
    /**
46
     * @internal
47
     * @after
48 964
     */
49
    public static function _tearDownFactories(): void
50 964
    {
51 964
        TestState::shutdownFoundry();
52
    }
53
}
54