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); |
|
|
|
|
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
|
|
|
|
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:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.