@@ -119,6 +119,60 @@ public function testThrowIfEmptyDsnGiven()
119119 $ processor ->process ($ tb ->buildTree (), [['dsn ' => '' ]]);
120120 }
121121
122+ public function testThrowIfFactoryClassAndFactoryServiceSetAtTheSameTime ()
123+ {
124+ $ transport = new TransportFactory ('default ' );
125+ $ tb = new TreeBuilder ();
126+ $ rootNode = $ tb ->root ('foo ' );
127+
128+ $ transport ->addConfiguration ($ rootNode );
129+ $ processor = new Processor ();
130+
131+ $ this ->expectException (\LogicException::class);
132+ $ this ->expectExceptionMessage ('Both options factory_class and factory_service are set. Please choose one. ' );
133+ $ processor ->process ($ tb ->buildTree (), [[
134+ 'dsn ' => 'foo: ' ,
135+ 'factory_class ' => 'aFactoryClass ' ,
136+ 'factory_service ' => 'aFactoryService ' ,
137+ ]]);
138+ }
139+
140+ public function testShouldAllowSetFactoryClass ()
141+ {
142+ $ transport = new TransportFactory ('default ' );
143+ $ tb = new TreeBuilder ();
144+ $ rootNode = $ tb ->root ('foo ' );
145+
146+ $ transport ->addConfiguration ($ rootNode );
147+ $ processor = new Processor ();
148+
149+ $ config = $ processor ->process ($ tb ->buildTree (), [[
150+ 'dsn ' => 'foo: ' ,
151+ 'factory_class ' => 'theFactoryClass ' ,
152+ ]]);
153+
154+ $ this ->assertArrayHasKey ('factory_class ' , $ config );
155+ $ this ->assertSame ('theFactoryClass ' , $ config ['factory_class ' ]);
156+ }
157+
158+ public function testShouldAllowSetFactoryService ()
159+ {
160+ $ transport = new TransportFactory ('default ' );
161+ $ tb = new TreeBuilder ();
162+ $ rootNode = $ tb ->root ('foo ' );
163+
164+ $ transport ->addConfiguration ($ rootNode );
165+ $ processor = new Processor ();
166+
167+ $ config = $ processor ->process ($ tb ->buildTree (), [[
168+ 'dsn ' => 'foo: ' ,
169+ 'factory_service ' => 'theFactoryService ' ,
170+ ]]);
171+
172+ $ this ->assertArrayHasKey ('factory_service ' , $ config );
173+ $ this ->assertSame ('theFactoryService ' , $ config ['factory_service ' ]);
174+ }
175+
122176 public function testThrowIfExtraOptionGiven ()
123177 {
124178 $ transport = new TransportFactory ('default ' );
@@ -164,6 +218,70 @@ public function testShouldCreateConnectionFactoryFromDSN()
164218 );
165219 }
166220
221+ public function testShouldCreateConnectionFactoryUsingCustomFactortyClass ()
222+ {
223+ $ container = new ContainerBuilder ();
224+
225+ $ transport = new TransportFactory ('default ' );
226+
227+ $ serviceId = $ transport ->createConnectionFactory ($ container , ['dsn ' => 'foo: ' , 'factory_class ' => 'theFactoryClass ' ]);
228+
229+ $ this ->assertEquals ('enqueue.transport.default.connection_factory ' , $ serviceId );
230+
231+ $ this ->assertTrue ($ container ->hasDefinition ('enqueue.transport.default.connection_factory_factory ' ));
232+ $ this ->assertSame (
233+ 'theFactoryClass ' ,
234+ $ container ->getDefinition ('enqueue.transport.default.connection_factory_factory ' )->getClass ()
235+ );
236+
237+ $ this ->assertTrue ($ container ->hasDefinition ('enqueue.transport.default.connection_factory ' ));
238+
239+ $ this ->assertNotEmpty ($ container ->getDefinition ('enqueue.transport.default.connection_factory ' )->getFactory ());
240+ $ this ->assertEquals (
241+ [new Reference ('enqueue.transport.default.connection_factory_factory ' ), 'create ' ],
242+ $ container ->getDefinition ('enqueue.transport.default.connection_factory ' )->getFactory ())
243+ ;
244+ $ this ->assertSame (
245+ [['dsn ' => 'foo: ' ]],
246+ $ container ->getDefinition ('enqueue.transport.default.connection_factory ' )->getArguments ())
247+ ;
248+
249+ $ this ->assertTrue ($ container ->hasAlias ('enqueue.transport.connection_factory ' ));
250+ $ this ->assertEquals (
251+ 'enqueue.transport.default.connection_factory ' ,
252+ (string ) $ container ->getAlias ('enqueue.transport.connection_factory ' )
253+ );
254+ }
255+
256+ public function testShouldCreateConnectionFactoryUsingCustomFactortyService ()
257+ {
258+ $ container = new ContainerBuilder ();
259+
260+ $ transport = new TransportFactory ('default ' );
261+
262+ $ serviceId = $ transport ->createConnectionFactory ($ container , ['dsn ' => 'foo: ' , 'factory_service ' => 'theFactoryService ' ]);
263+
264+ $ this ->assertEquals ('enqueue.transport.default.connection_factory ' , $ serviceId );
265+
266+ $ this ->assertTrue ($ container ->hasDefinition ('enqueue.transport.default.connection_factory ' ));
267+
268+ $ this ->assertNotEmpty ($ container ->getDefinition ('enqueue.transport.default.connection_factory ' )->getFactory ());
269+ $ this ->assertEquals (
270+ [new Reference ('theFactoryService ' ), 'create ' ],
271+ $ container ->getDefinition ('enqueue.transport.default.connection_factory ' )->getFactory ())
272+ ;
273+ $ this ->assertSame (
274+ [['dsn ' => 'foo: ' ]],
275+ $ container ->getDefinition ('enqueue.transport.default.connection_factory ' )->getArguments ())
276+ ;
277+
278+ $ this ->assertTrue ($ container ->hasAlias ('enqueue.transport.connection_factory ' ));
279+ $ this ->assertEquals (
280+ 'enqueue.transport.default.connection_factory ' ,
281+ (string ) $ container ->getAlias ('enqueue.transport.connection_factory ' )
282+ );
283+ }
284+
167285 public function testShouldCreateContextFromDsn ()
168286 {
169287 $ container = new ContainerBuilder ();
0 commit comments