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

DoctrineORMContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A purgeDatabase() 0 9 2
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