1313
1414use PHPUnit \Framework \TestCase ;
1515use Symfony \Bundle \MonologBundle \DependencyInjection \Compiler \AddSwiftMailerTransportPass ;
16+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
17+ use Symfony \Component \DependencyInjection \Definition ;
1618use Symfony \Component \DependencyInjection \Reference ;
1719
1820/**
@@ -32,60 +34,27 @@ class AddSwiftMailerTransportPassTest extends TestCase
3234 protected function doSetUp ()
3335 {
3436 $ this ->compilerPass = new AddSwiftMailerTransportPass ();
35- $ this ->definition = $ this ->getMockBuilder ('\Symfony\Component\DependencyInjection\Definition ' )->getMock ();
36- $ this ->definition ->expects ($ this ->any ())
37- ->method ('getArgument ' )
38- ->with (0 )
39- ->willReturn (new Reference ('swiftmailer ' ));
40- $ this ->container = $ this ->getMockBuilder ('\Symfony\Component\DependencyInjection\ContainerBuilder ' )
41- ->setMethods (['getParameter ' , 'getDefinition ' , 'hasDefinition ' , 'addMethodCall ' ])->getMock ();
42- $ this ->container ->expects ($ this ->any ())
43- ->method ('getParameter ' )
44- ->with ('monolog.swift_mailer.handlers ' )
45- ->willReturn (['foo ' ]);
46- $ this ->container ->expects ($ this ->any ())
47- ->method ('getDefinition ' )
48- ->with ('foo ' )
49- ->willReturn ($ this ->definition );
37+ $ this ->definition = new Definition (null , [new Reference ('swiftmailer ' )]);
38+ $ this ->container = new ContainerBuilder ();
39+ $ this ->container ->setParameter ('monolog.swift_mailer.handlers ' , ['foo ' ]);
40+ $ this ->container ->setDefinition ('foo ' , $ this ->definition );
5041 }
5142
5243 public function testWithRealTransport ()
5344 {
54- $ this ->container
55- ->expects ($ this ->any ())
56- ->method ('hasDefinition ' )
57- ->with ('swiftmailer.transport.real ' )
58- ->willReturn (true );
59- $ this ->definition
60- ->expects ($ this ->once ())
61- ->method ('addMethodCall ' )
62- ->with (
63- 'setTransport ' ,
64- $ this ->equalTo ([new Reference ('swiftmailer.transport.real ' )])
65- );
45+ $ this ->container ->register ('swiftmailer.transport.real ' );
6646
6747 $ this ->compilerPass ->process ($ this ->container );
48+
49+ $ this ->assertEquals ([['setTransport ' , [new Reference ('swiftmailer.transport.real ' )]]], $ this ->definition ->getMethodCalls ());
6850 }
6951
7052 public function testWithoutRealTransport ()
7153 {
72- $ this ->container
73- ->expects ($ this ->any ())
74- ->method ('hasDefinition ' )
75- ->willReturnMap (
76- [
77- ['swiftmailer.transport.real ' , false ],
78- ['swiftmailer.transport ' , true ],
79- ]
80- );
81- $ this ->definition
82- ->expects ($ this ->once ())
83- ->method ('addMethodCall ' )
84- ->with (
85- 'setTransport ' ,
86- $ this ->equalTo ([new Reference ('swiftmailer.transport ' )])
87- );
54+ $ this ->container ->register ('swiftmailer.transport ' );
8855
8956 $ this ->compilerPass ->process ($ this ->container );
57+
58+ $ this ->assertEquals ([['setTransport ' , [new Reference ('swiftmailer.transport ' )]]], $ this ->definition ->getMethodCalls ());
9059 }
9160}
0 commit comments