Passed
Push — master ( 829500...1175ab )
by Kevin
08:08
created

Factories::_tearDownFactories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Zenstruck\Foundry\Test;
4
5
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6
use Zenstruck\Foundry\Factory;
7
use Zenstruck\Foundry\PersistenceManager;
8
use Zenstruck\Foundry\StoryManager;
9
10
/**
11
 * @mixin KernelTestCase
12
 *
13
 * @author Kevin Bond <[email protected]>
14
 */
15
trait Factories
16
{
17
    /**
18
     * @internal
19
     * @before
20
     */
21 38
    public static function _setUpFactories(): void
22
    {
23 38
        if (!\is_subclass_of(static::class, KernelTestCase::class)) {
24
            throw new \RuntimeException(\sprintf('The "%s" trait can only be used on TestCases that extend "%s".', __TRAIT__, KernelTestCase::class));
25
        }
26
27
        PersistenceManager::register(new LazyManagerRegistry(static function() {
28
            if (!static::$booted) {
29
                static::bootKernel();
30
            }
31
32
            return static::$kernel->getContainer()->get('doctrine');
33 38
        }));
34 38
    }
35
36
    /**
37
     * @internal
38
     * @after
39
     */
40 38
    public static function _tearDownFactories(): void
41
    {
42 38
        Factory::faker()->unique(true); // reset unique
43 38
        StoryManager::reset();
44 38
    }
45
}
46