7
7
use MySQLReplication \BinLog \BinLogServerInfo ;
8
8
use MySQLReplication \Definitions \ConstEventType ;
9
9
use MySQLReplication \Event \DTO \DeleteRowsDTO ;
10
+ use MySQLReplication \Event \DTO \FormatDescriptionEventDTO ;
10
11
use MySQLReplication \Event \DTO \QueryDTO ;
11
12
use MySQLReplication \Event \DTO \RotateDTO ;
12
13
use MySQLReplication \Event \DTO \TableMapDTO ;
13
14
use MySQLReplication \Event \DTO \UpdateRowsDTO ;
14
15
use MySQLReplication \Event \DTO \WriteRowsDTO ;
15
16
use MySQLReplication \Event \DTO \XidDTO ;
17
+ use MySQLReplication \MySQLReplicationFactory ;
18
+ use Symfony \Component \EventDispatcher \EventDispatcher ;
19
+ use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
16
20
17
21
class BasicTest extends BaseTest
18
22
{
@@ -352,4 +356,50 @@ public function shouldRoteLog(): void
352
356
$ this ->getEvent ()->getEventInfo ()->getBinLogCurrent ()->getBinFileName ()
353
357
);
354
358
}
359
+
360
+ /**
361
+ * @test
362
+ */
363
+ public function shouldUseProvidedEventDispatcher (): void
364
+ {
365
+ $ this ->disconnect ();
366
+
367
+ $ testEventSubscribers = new TestEventSubscribers ($ this );
368
+
369
+ $ eventDispatcher = new EventDispatcher ();
370
+ $ eventDispatcher ->addSubscriber ($ testEventSubscribers );
371
+
372
+ $ this ->connectWithProvidedEventDispatcher ($ eventDispatcher );
373
+
374
+ $ this ->connection ->exec (
375
+ $ createExpected = 'CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id)) '
376
+ );
377
+
378
+ /** @var QueryDTO $event */
379
+ $ event = $ this ->getEvent ();
380
+ self ::assertInstanceOf (QueryDTO::class, $ event );
381
+ self ::assertEquals ($ createExpected , $ event ->getQuery ());
382
+ }
383
+
384
+ private function connectWithProvidedEventDispatcher (EventDispatcherInterface $ eventDispatcher ): void
385
+ {
386
+ $ this ->mySQLReplicationFactory = new MySQLReplicationFactory (
387
+ $ this ->configBuilder ->build (),
388
+ null ,
389
+ null ,
390
+ $ eventDispatcher
391
+ );
392
+
393
+ $ this ->connection = $ this ->mySQLReplicationFactory ->getDbConnection ();
394
+
395
+ $ this ->connection ->exec ('SET SESSION time_zone = "UTC" ' );
396
+ $ this ->connection ->exec ('DROP DATABASE IF EXISTS ' . $ this ->database );
397
+ $ this ->connection ->exec ('CREATE DATABASE ' . $ this ->database );
398
+ $ this ->connection ->exec ('USE ' . $ this ->database );
399
+ $ this ->connection ->exec ('SET SESSION sql_mode = \'\'; ' );
400
+
401
+ self ::assertInstanceOf (FormatDescriptionEventDTO::class, $ this ->getEvent ());
402
+ self ::assertInstanceOf (QueryDTO::class, $ this ->getEvent ());
403
+ self ::assertInstanceOf (QueryDTO::class, $ this ->getEvent ());
404
+ }
355
405
}
0 commit comments