Completed
Push — master ( 203a9c...2f9634 )
by Matthew
05:23 queued 25s
created

JobManagerTest::createObjectManager()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 29
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 23
nc 4
nop 0
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\Doctrine\BaseJobManagerTest;
10
use Dtc\QueueBundle\ORM\JobManager;
11
use Doctrine\ORM\EntityManager;
12
13
/**
14
 * @author David
15
 *
16
 * This test requires local mongodb running
17
 */
18
class JobManagerTest extends BaseJobManagerTest
19
{
20
    public static function createObjectManager()
21
    {
22
        if (!is_dir('/tmp/dtcqueuetest/generate/proxies')) {
23
            mkdir('/tmp/dtcqueuetest/generate/proxies', 0777, true);
24
        }
25
26
        $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__.'/../..'), true, null, null, false);
27
28
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/Grid.php');
29
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/ShowAction.php');
30
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/DeleteAction.php');
31
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/Column.php');
32
        AnnotationRegistry::registerFile(__DIR__.'/../../vendor/mmucklo/grid-bundle/Annotation/Action.php');
33
34
        $namingStrategy = new UnderscoreNamingStrategy();
35
        $config->setNamingStrategy($namingStrategy);
36
        $host = getenv('MYSQL_HOST');
37
        $user = getenv('MYSQL_USER');
38
        $port = getenv('MYSQL_PORT') ?: 3306;
39
        $password = getenv('MYSQL_PASSWORD');
40
        $db = getenv('MYSQL_DATABASE');
41
        $params = ['host' => $host,
42
            'port' => $port,
43
            'user' => $user,
44
            'driver' => 'mysqli',
45
            'password' => $password,
46
            'dbname' => $db, ];
47
        self::$objectManager = EntityManager::create($params, $config);
48
    }
49
50
    public static function setUpBeforeClass()
51
    {
52
        self::createObjectManager();
53
        $entityName = 'Dtc\QueueBundle\Entity\Job';
54
        $archiveEntityName = 'Dtc\QueueBundle\Entity\JobArchive';
55
        $runClass = 'Dtc\QueueBundle\Entity\Run';
56
        $runArchiveClass = 'Dtc\QueueBundle\Entity\RunArchive';
57
58
        $tool = new SchemaTool(self::$objectManager);
0 ignored issues
show
Bug introduced by
It seems like self::$objectManager can also be of type object<Doctrine\ODM\MongoDB\DocumentManager>; however, Doctrine\ORM\Tools\SchemaTool::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
59
        $metadataEntity = [self::$objectManager->getClassMetadata($entityName)];
60
        $tool->dropSchema($metadataEntity);
61
        $tool->createSchema($metadataEntity);
62
63
        $metadataEntityArchive = [self::$objectManager->getClassMetadata($archiveEntityName)];
64
        $tool->dropSchema($metadataEntityArchive);
65
        $tool->createSchema($metadataEntityArchive);
66
67
        $metadataEntityRun = [self::$objectManager->getClassMetadata($runClass)];
68
        $tool->dropSchema($metadataEntityRun);
69
        $tool->createSchema($metadataEntityRun);
70
71
        $metadataEntityRunArchive = [self::$objectManager->getClassMetadata($runArchiveClass)];
72
        $tool->dropSchema($metadataEntityRunArchive);
73
        $tool->createSchema($metadataEntityRunArchive);
74
75
        self::$objectName = $entityName;
76
        self::$archiveObjectName = $archiveEntityName;
77
        self::$runClass = $runClass;
78
        self::$runArchiveClass = $runArchiveClass;
79
        self::$jobManagerClass = JobManager::class;
80
        parent::setUpBeforeClass();
81
    }
82
}
83