55namespace Prooph \EventStoreBenchmarks ;
66
77use ArangoDb \Connection ;
8+ use MongoDB \Client ;
89use PDO ;
910use Prooph \Common \Messaging \FQCNMessageFactory ;
10- use Prooph \EventStore \ArangoDb \EventStore as ArangoDbEventStore ;
11- use Prooph \EventStore \ArangoDb \Projection \ProjectionManager as ArangoDbProjectionManager ;
1211use Prooph \EventStore \ArangoDb \Type \DeleteCollection ;
1312use Prooph \EventStore \EventStore ;
13+ use Prooph \EventStore \MongoDb \MongoDbEventStore ;
14+ use Prooph \EventStore \MongoDb \Projection \MongoDbProjectionManager ;
1415use Prooph \EventStore \Pdo \MariaDbEventStore ;
1516use Prooph \EventStore \Pdo \MySqlEventStore ;
1617use Prooph \EventStore \Pdo \PostgresEventStore ;
@@ -32,6 +33,7 @@ function testDatabases(): array
3233 'mariadb ' => \getenv ('MARIADB_DB ' ),
3334 'postgres ' => \getenv ('POSTGRES_DB ' ),
3435 'arangodb ' => \getenv ('ARANGODB_DB ' ),
36+ 'mongodb ' => \getenv ('MONGODB_DB ' ),
3537 ];
3638}
3739
@@ -69,6 +71,10 @@ function createStreamStrategy(string $driver)
6971 case 'arangodb ' :
7072 $ class = 'Prooph\EventStore\ArangoDb\PersistenceStrategy \\' . \getenv ('STREAM_STRATEGY ' ) . 'StreamStrategy ' ;
7173
74+ return new $ class ();
75+ case 'mongodb ' :
76+ $ class = 'Prooph\EventStore\MongoDb\PersistenceStrategy\MongoDb ' . \getenv ('STREAM_STRATEGY ' ) . 'StreamStrategy ' ;
77+
7278 return new $ class ();
7379 default :
7480 throw new \RuntimeException (\sprintf ('Driver "%s" not supported ' , $ driver ));
@@ -116,6 +122,14 @@ function createConnection(string $driver)
116122 $ connection ->connect ();
117123
118124 return $ connection ;
125+ case 'mongodb ' :
126+ return new Client (
127+ \getenv ('MONGODB_HOST ' ),
128+ [],
129+ ['typeMap ' => ['root ' => 'array ' , 'document ' => 'array ' , 'array ' => 'array ' ]]
130+ );
131+ default :
132+ throw new \RuntimeException (\sprintf ('Driver "%s" not supported ' , $ driver ));
119133 }
120134}
121135
@@ -151,6 +165,10 @@ function createDatabase($connection, string $driver, string $dbName): void
151165 execute ($ connection , null , ...eventStreamsBatch ());
152166 execute ($ connection , null , ...projectionsBatch ());
153167 break ;
168+ case 'mongodb ' :
169+ \Prooph \EventStore \MongoDb \MongoDbHelper::createProjectionCollection ($ connection , $ dbName , 'projections ' );
170+ \Prooph \EventStore \MongoDb \MongoDbHelper::createEventStreamsCollection ($ connection , $ dbName , 'event_streams ' );
171+ break ;
154172 default :
155173 throw new \RuntimeException (\sprintf ('Driver "%s" not supported ' , $ driver ));
156174 }
@@ -159,7 +177,7 @@ function createDatabase($connection, string $driver, string $dbName): void
159177 \sleep (1 );
160178}
161179
162- function destroyDatabase ($ connection , string $ driver, string $ dbName ): void
180+ function destroyDatabase ($ connection , string $ driver ): void
163181{
164182 switch (\strtolower ($ driver )) {
165183 case 'mysql ' :
@@ -188,6 +206,9 @@ function destroyDatabase($connection, string $driver, string $dbName): void
188206 );
189207 }
190208 break ;
209+ case 'mongodb ' :
210+ $ connection ->dropDatabase (\getenv ('MONGODB_DB ' ));
211+ break ;
191212 default :
192213 throw new \RuntimeException (\sprintf ('Driver "%s" not supported ' , $ driver ));
193214 }
@@ -220,6 +241,15 @@ function createEventStore(string $driver, $connection): EventStore
220241 $ connection ,
221242 createStreamStrategy ($ driver )
222243 );
244+ case 'mongodb ' :
245+ return new MongoDbEventStore (
246+ new FQCNMessageFactory (),
247+ $ connection ,
248+ \getenv ('MONGODB_DB ' ),
249+ createStreamStrategy ($ driver )
250+ );
251+ default :
252+ throw new \RuntimeException (\sprintf ('Driver "%s" not supported ' , $ driver ));
223253 }
224254}
225255
@@ -246,6 +276,16 @@ function createProjectionManager(EventStore $eventStore, string $driver, $connec
246276 $ eventStore ,
247277 $ connection
248278 );
279+ case 'mongodb ' :
280+ return new MongoDbProjectionManager (
281+ $ eventStore ,
282+ $ connection ,
283+ createStreamStrategy ($ driver ),
284+ new FQCNMessageFactory (),
285+ \getenv ('MONGODB_DB ' )
286+ );
287+ default :
288+ throw new \RuntimeException (\sprintf ('Driver "%s" not supported ' , $ driver ));
249289 }
250290}
251291
0 commit comments