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
|
|
|
|