1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* doctrine-manager-builder (https://github.com/juliangut/doctrine-manager-builder) |
4
|
|
|
* Doctrine2 managers builder |
5
|
|
|
* |
6
|
|
|
* @license BSD-3-Clause |
7
|
|
|
* @author Julián Gutiérrez <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Jgut\Doctrine\ManagerBuilder\Tests; |
11
|
|
|
|
12
|
|
|
use Doctrine\MongoDB\Connection; |
13
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
14
|
|
|
use Jgut\Doctrine\ManagerBuilder\ManagerBuilder; |
15
|
|
|
use Jgut\Doctrine\ManagerBuilder\MongoDBBuilder; |
16
|
|
|
use Symfony\Component\Console\Command\Command; |
17
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* MongoDB entity builder tests. |
21
|
|
|
*/ |
22
|
|
|
class MongoDBBuilderTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var MongoDBBuilder |
26
|
|
|
*/ |
27
|
|
|
protected $builder; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function setUp() |
33
|
|
|
{ |
34
|
|
|
$this->builder = new MongoDBBuilder([], 'test'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @expectedException \InvalidArgumentException |
39
|
|
|
*/ |
40
|
|
|
public function testManagerNoConnection() |
41
|
|
|
{ |
42
|
|
|
$this->builder->setOption('connection', null); |
43
|
|
|
$this->builder->setOption( |
44
|
|
|
'metadata_mapping', |
45
|
|
|
[ |
46
|
|
|
['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__, 'namespace' => 'annotation'], |
47
|
|
|
['type' => ManagerBuilder::METADATA_MAPPING_XML, 'path' => __DIR__, 'namespace' => 'xml'], |
48
|
|
|
['type' => ManagerBuilder::METADATA_MAPPING_YAML, 'path' => __DIR__, 'namespace' => 'yaml'], |
49
|
|
|
['type' => ManagerBuilder::METADATA_MAPPING_PHP, 'path' => __DIR__, 'namespace' => 'php'], |
50
|
|
|
] |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$this->builder->getManager(true, true); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @expectedException \RuntimeException |
58
|
|
|
* @expectedExceptionMessage Cannot use different EventManager instances for DocumentManager and Connection. |
59
|
|
|
*/ |
60
|
|
|
public function testManageWrongConnection() |
61
|
|
|
{ |
62
|
|
|
$this->builder->setOption('connection', new Connection('localhost')); |
63
|
|
|
$this->builder->setOption( |
64
|
|
|
'metadata_mapping', |
65
|
|
|
[['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]] |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$this->builder->getManager(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testManager() |
72
|
|
|
{ |
73
|
|
|
$connection = new Connection('localhost', [], null, $this->builder->getEventManager()); |
74
|
|
|
|
75
|
|
|
$this->builder->setOption('connection', $connection); |
76
|
|
|
$this->builder->setOption( |
77
|
|
|
'metadata_mapping', |
78
|
|
|
[['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]] |
79
|
|
|
); |
80
|
|
|
$this->builder->setOption('default_database', 'ddbb'); |
81
|
|
|
$this->builder->setOption('logger_callable', 'class_exists'); |
82
|
|
|
|
83
|
|
|
static::assertInstanceOf(DocumentManager::class, $this->builder->getManager(true)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testConsoleCommands() |
87
|
|
|
{ |
88
|
|
|
$this->builder->setOption('connection', ['server' => 'localhost']); |
89
|
|
|
$this->builder->setOption( |
90
|
|
|
'metadata_mapping', |
91
|
|
|
[['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]] |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$commands = $this->builder->getConsoleCommands(); |
95
|
|
|
|
96
|
|
|
return array_walk( |
97
|
|
|
$commands, |
98
|
|
|
function ($command) { |
99
|
|
|
static::assertInstanceOf(Command::class, $command); |
100
|
|
|
} |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testConsoleHelperSet() |
105
|
|
|
{ |
106
|
|
|
$this->builder->setOption('connection', ['server' => 'localhost']); |
107
|
|
|
$this->builder->setOption( |
108
|
|
|
'metadata_mapping', |
109
|
|
|
[['type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION, 'path' => __DIR__]] |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$helperSet = $this->builder->getConsoleHelperSet(); |
113
|
|
|
|
114
|
|
|
static::assertInstanceOf(HelperSet::class, $helperSet); |
115
|
|
|
static::assertTrue($helperSet->has('documentManager')); |
116
|
|
|
static::assertTrue($helperSet->has('dm')); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|