13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Bundle \MonologBundle \DependencyInjection \Compiler \AddSwiftMailerTransportPass ;
16
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
17
+ use Symfony \Component \DependencyInjection \Definition ;
16
18
use Symfony \Component \DependencyInjection \Reference ;
17
19
18
20
/**
@@ -32,60 +34,27 @@ class AddSwiftMailerTransportPassTest extends TestCase
32
34
protected function doSetUp ()
33
35
{
34
36
$ 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 );
50
41
}
51
42
52
43
public function testWithRealTransport ()
53
44
{
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 ' );
66
46
67
47
$ this ->compilerPass ->process ($ this ->container );
48
+
49
+ $ this ->assertEquals ([['setTransport ' , [new Reference ('swiftmailer.transport.real ' )]]], $ this ->definition ->getMethodCalls ());
68
50
}
69
51
70
52
public function testWithoutRealTransport ()
71
53
{
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 ' );
88
55
89
56
$ this ->compilerPass ->process ($ this ->container );
57
+
58
+ $ this ->assertEquals ([['setTransport ' , [new Reference ('swiftmailer.transport ' )]]], $ this ->definition ->getMethodCalls ());
90
59
}
91
60
}
0 commit comments