Completed
Push — master ( 902cca...dde4bb )
by Paweł
138:22 queued 138:06
created

HookContext::purgeDatabase()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 18
rs 9.4286
c 3
b 0
f 0
cc 3
eloc 10
nc 4
nop 1
1
<?php
2
/*
3
 * This file is part of the Sylius package.
4
 *
5
 * (c) Paweł Jędrzejewski
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Sylius\Bundle\CoreBundle\Behat;
12
13
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
14
use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySqlDriver;
15
use Sylius\Bundle\ResourceBundle\Behat\DefaultContext;
16
17
/**
18
 * @author Gonzalo Vilaseca <[email protected]>
19
 */
20
class HookContext extends DefaultContext
21
{
22
    /**
23
     * @BeforeScenario
24
     */
25
    public function purgeDatabase(BeforeScenarioScope $scope)
0 ignored issues
show
Unused Code introduced by
The parameter $scope is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        $entityManager = $this->getService('doctrine.orm.entity_manager');
28
        $entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
29
30
        $isMySqlDriver = $entityManager->getConnection()->getDriver() instanceof PDOMySqlDriver;
31
        if ($isMySqlDriver) {
32
            $entityManager->getConnection()->executeUpdate("SET foreign_key_checks = 0;");
33
        }
34
35
        $this->getSharedService('sylius.purger.orm_purger')->purge();
36
37
        if ($isMySqlDriver) {
38
            $entityManager->getConnection()->executeUpdate("SET foreign_key_checks = 1;");
39
        }
40
41
        $entityManager->clear();
42
    }
43
}
44