Factories   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 1
b 0
f 0
dl 0
loc 39
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _tearDownFactories() 0 3 1
A _setUpFactories() 0 24 3
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