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

JobManagerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 57 3
1
<?php
2
3
namespace Dtc\QueueBundle\Tests\ODM;
4
5
use Doctrine\Common\Annotations\AnnotationRegistry;
6
use Dtc\QueueBundle\Doctrine\RemoveListener;
7
use Dtc\QueueBundle\Tests\Doctrine\BaseJobManagerTest;
8
use Dtc\QueueBundle\Tests\FibonacciWorker;
9
use Dtc\QueueBundle\ODM\JobManager;
10
use Doctrine\MongoDB\Connection;
11
use Doctrine\ODM\MongoDB\Configuration;
12
use Doctrine\ODM\MongoDB\DocumentManager;
13
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
14
use Symfony\Component\DependencyInjection\Container;
15
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
16
17
/**
18
 * @author David
19
 *
20
 * This test requires local mongodb running
21
 */
22
class JobManagerTest extends BaseJobManagerTest
23
{
24
    public static $dm;
25
26
    public static function setUpBeforeClass()
27
    {
28
        if (!is_dir('/tmp/dtcqueuetest/generate/proxies')) {
29
            mkdir('/tmp/dtcqueuetest/generate/proxies', 0777, true);
30
        }
31
32
        if (!is_dir('/tmp/dtcqueuetest/generate/hydrators')) {
33
            mkdir('/tmp/dtcqueuetest/generate/hydrators', 0777, true);
34
        }
35
        AnnotationDriver::registerAnnotationClasses();
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\ODM\MongoDB\Map...sterAnnotationClasses() has been deprecated with message: method was deprecated in 1.2 and will be removed in 2.0. Register class loader through AnnotationRegistry::registerLoader instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
36
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/Grid.php');
37
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/ShowAction.php');
38
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/DeleteAction.php');
39
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/Column.php');
40
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/Action.php');
41
42
        // Set up database delete here??
43
        $config = new Configuration();
44
        $config->setProxyDir('/tmp/dtcqueuetest/generate/proxies');
45
        $config->setProxyNamespace('Proxies');
46
47
        $config->setHydratorDir('/tmp/dtcqueuetest/generate/hydrators');
48
        $config->setHydratorNamespace('Hydrators');
49
50
        $classPath = __DIR__.'../../Document';
51
        $config->setMetadataDriverImpl(AnnotationDriver::create($classPath));
52
53
        self::$dm = DocumentManager::create(new Connection(getenv('MONGODB_HOST')), $config);
54
55
        $documentName = 'Dtc\QueueBundle\Document\Job';
56
        $archiveDocumentName = 'Dtc\QueueBundle\Document\JobArchive';
57
        $runClass = 'Dtc\QueueBundle\Document\Run';
58
        $runArchiveClass = 'Dtc\QueueBundle\Document\RunArchive';
59
        $sm = self::$dm->getSchemaManager();
60
61
        $sm->dropDocumentCollection($documentName);
62
        $sm->dropDocumentCollection($runClass);
63
        $sm->dropDocumentCollection($archiveDocumentName);
64
        $sm->dropDocumentCollection($runArchiveClass);
65
        $sm->createDocumentCollection($documentName);
66
        $sm->createDocumentCollection($archiveDocumentName);
67
        $sm->updateDocumentIndexes($documentName);
68
        $sm->updateDocumentIndexes($archiveDocumentName);
69
70
        self::$jobManager = new JobManager(self::$dm, $documentName, $archiveDocumentName, $runClass, $runArchiveClass);
71
        self::$worker = new FibonacciWorker();
72
        self::$worker->setJobClass($documentName);
73
74
        $parameters = new ParameterBag();
75
76
        $container = new Container($parameters);
77
        $container->set('dtc_queue.job_manager', self::$jobManager);
78
79
        self::$dm->getEventManager()->addEventListener('preRemove', new RemoveListener($container));
80
81
        parent::setUpBeforeClass();
82
    }
83
}
84