Test Setup Failed
Push — master ( 298fd3...56daff )
by Matthew
17:14
created

JobManagerTest::setUpBeforeClass()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 56
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 9.7251
c 0
b 0
f 0
cc 3
eloc 44
nc 4
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Dtc\QueueBundle\Tests\ORM;
4
5
use Doctrine\Common\Annotations\AnnotationRegistry;
6
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
7
use Doctrine\ORM\Tools\SchemaTool;
8
use Doctrine\ORM\Tools\Setup;
9
use Dtc\QueueBundle\Tests\Model\BaseJobManagerTest;
10
use Dtc\QueueBundle\Tests\FibonacciWorker;
11
use Dtc\QueueBundle\ORM\JobManager;
12
use Doctrine\ORM\EntityManager;
13
14
/**
15
 * @author David
16
 *
17
 * This test requires local mongodb running
18
 */
19
class JobManagerTest extends BaseJobManagerTest
20
{
21
    public static $entityManager;
22
23
    public static function setUpBeforeClass()
24
    {
25
        if (!is_dir('/tmp/dtcqueuetest/generate/proxies')) {
26
            mkdir('/tmp/dtcqueuetest/generate/proxies', 0777, true);
27
        }
28
29
        $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__.'/../..'), true, null, null, false);
30
31
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/Grid.php');
32
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/ShowAction.php');
33
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/DeleteAction.php');
34
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/Column.php');
35
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/Action.php');
36
37
        $namingStrategy = new UnderscoreNamingStrategy();
38
        $config->setNamingStrategy($namingStrategy);
39
        $host = getenv('MYSQL_HOST');
40
        $user = getenv('MYSQL_USER');
41
        $port = getenv('MYSQL_PORT') ?: 3306;
42
        $password = getenv('MYSQL_PASSWORD');
43
        $db = getenv('MYSQL_DATABASE');
44
        $params = ['host' => $host,
45
                    'port' => $port,
46
                    'user' => $user,
47
                    'driver' => 'mysqli',
48
                    'password' => $password,
49
                    'dbname' => $db, ];
50
        self::$entityManager = EntityManager::create($params, $config);
51
52
        $entityName = 'Dtc\QueueBundle\Entity\Job';
53
        $archiveEntityName = 'Dtc\QueueBundle\Entity\JobArchive';
54
        $runClass = 'Dtc\QueueBundle\Entity\Run';
55
        $runArchiveClass = 'Dtc\QueueBundle\Entity\RunArchive';
56
57
        $tool = new SchemaTool(self::$entityManager);
58
        $metadataEntity = [self::$entityManager->getClassMetadata($entityName)];
59
        $tool->dropSchema($metadataEntity);
60
        $tool->createSchema($metadataEntity);
61
62
        $metadataEntityArchive = [self::$entityManager->getClassMetadata($archiveEntityName)];
63
        $tool->dropSchema($metadataEntityArchive);
64
        $tool->createSchema($metadataEntityArchive);
65
66
        $metadataEntityRun = [self::$entityManager->getClassMetadata($runClass)];
67
        $tool->dropSchema($metadataEntityRun);
68
        $tool->createSchema($metadataEntityRun);
69
70
        $metadataEntityRunArchive = [self::$entityManager->getClassMetadata($runArchiveClass)];
71
        $tool->dropSchema($metadataEntityRunArchive);
72
        $tool->createSchema($metadataEntityRunArchive);
73
74
        self::$jobManager = new JobManager(self::$entityManager, $entityName, $archiveEntityName, $runClass, $runArchiveClass);
75
        self::$worker = new FibonacciWorker();
76
        self::$worker->setJobClass($entityName);
77
        parent::setUpBeforeClass();
78
    }
79
}
80