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

Factories   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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