|
8 | 8 | use Doctrine\Common\EventManager;
|
9 | 9 | use Doctrine\ODM\MongoDB\Aggregation\Builder as AggregationBuilder;
|
10 | 10 | use Doctrine\ODM\MongoDB\Configuration;
|
| 11 | +use Doctrine\ODM\MongoDB\DocumentManager; |
11 | 12 | use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
|
12 | 13 | use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
|
13 | 14 | use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory;
|
|
36 | 37 | use PHPUnit\Framework\Attributes\DataProvider;
|
37 | 38 | use RuntimeException;
|
38 | 39 | use stdClass;
|
| 40 | +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
39 | 41 |
|
40 | 42 | class DocumentManagerTest extends BaseTestCase
|
41 | 43 | {
|
@@ -261,6 +263,31 @@ public function testGetClassNameForAssociationReturnsTargetDocumentWithNullData(
|
261 | 263 | $mapping = ClassMetadataTestUtil::getFieldMapping(['targetDocument' => User::class]);
|
262 | 264 | self::assertEquals(User::class, $this->dm->getClassNameForAssociation($mapping, null));
|
263 | 265 | }
|
| 266 | + |
| 267 | + public function testCreateWithEventManager(): void |
| 268 | + { |
| 269 | + $config = static::getConfiguration(); |
| 270 | + $client = new Client(self::getUri()); |
| 271 | + |
| 272 | + $eventManager = new EventManager(); |
| 273 | + $dm = DocumentManager::create($client, $config, $eventManager); |
| 274 | + self::assertSame($eventManager, $dm->getEventManager()); |
| 275 | + self::assertInstanceOf(EventDispatcherInterface::class, $dm->getEventDispatcher()); |
| 276 | + } |
| 277 | + |
| 278 | + public function testCreateWithEventDispatcher(): void |
| 279 | + { |
| 280 | + $config = static::getConfiguration(); |
| 281 | + $client = new Client(self::getUri()); |
| 282 | + |
| 283 | + $eventDispatcher = $this->createMock(EventDispatcherInterface::class); |
| 284 | + $dm = DocumentManager::create($client, $config, $eventDispatcher); |
| 285 | + self::assertSame($eventDispatcher, $dm->getEventDispatcher()); |
| 286 | + |
| 287 | + self::expectException(\LogicException::class); |
| 288 | + self::expectExceptionMessage('Use getEventDispatcher() instead of getEventManager()'); |
| 289 | + $dm->getEventManager(); |
| 290 | + } |
264 | 291 | }
|
265 | 292 |
|
266 | 293 | #[ODM\Document]
|
|
0 commit comments