Completed
Push — master ( 61044a...94728c )
by Rafał
24:26 queued 10:49
created

DoctrineORMContext::purgeDatabase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Behat\Contexts\Hook;
6
7
use Behat\Behat\Context\Context;
8
use Behat\Behat\Hook\Scope\BeforeFeatureScope;
9
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
10
use Doctrine\ORM\EntityManagerInterface;
11
12
final class DoctrineORMContext implements Context
13
{
14
    public static $entityManager;
15
16
    public function __construct(EntityManagerInterface $entityManager)
17
    {
18
        self::$entityManager = $entityManager;
19
    }
20
21
    /**
22
     * @BeforeFeature
23
     */
24
    public static function purgeDatabase(BeforeFeatureScope $scope): void
25
    {
26
        if (\in_array('disable-fixtures', $scope->getFeature()->getTags(), true)) {
27
            self::$entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
28
            $purger = new ORMPurger(self::$entityManager);
29
            $purger->purge();
30
            self::$entityManager->clear();
31
        }
32
    }
33
}
34