17
17
use Symfony \Component \Messenger \Bridge \Amqp \Transport \AmqpStamp ;
18
18
use Symfony \Component \Messenger \Bridge \Amqp \Transport \Connection ;
19
19
use Symfony \Component \Messenger \Envelope ;
20
+ use Symfony \Component \Messenger \Exception \TransportException ;
21
+ use Symfony \Component \Messenger \Tests \Fixtures \DummyMessage ;
22
+ use Symfony \Component \Messenger \Transport \AmqpExt \AmqpSender ;
23
+ use Symfony \Component \Messenger \Transport \AmqpExt \AmqpStamp ;
24
+ use Symfony \Component \Messenger \Transport \AmqpExt \Connection ;
20
25
use Symfony \Component \Messenger \Transport \Serialization \SerializerInterface ;
21
26
22
27
/**
@@ -29,10 +34,10 @@ public function testItSendsTheEncodedMessage()
29
34
$ envelope = new Envelope (new DummyMessage ('Oy ' ));
30
35
$ encoded = ['body ' => '... ' , 'headers ' => ['type ' => DummyMessage::class]];
31
36
32
- $ serializer = $ this ->getMockBuilder (SerializerInterface::class)-> getMock ( );
37
+ $ serializer = $ this ->createMock (SerializerInterface::class);
33
38
$ serializer ->method ('encode ' )->with ($ envelope )->willReturnOnConsecutiveCalls ($ encoded );
34
39
35
- $ connection = $ this ->getMockBuilder (Connection::class)-> disableOriginalConstructor ()-> getMock ( );
40
+ $ connection = $ this ->createMock (Connection::class);
36
41
$ connection ->expects ($ this ->once ())->method ('publish ' )->with ($ encoded ['body ' ], $ encoded ['headers ' ]);
37
42
38
43
$ sender = new AmqpSender ($ connection , $ serializer );
@@ -59,10 +64,10 @@ public function testItSendsTheEncodedMessageWithoutHeaders()
59
64
$ envelope = new Envelope (new DummyMessage ('Oy ' ));
60
65
$ encoded = ['body ' => '... ' ];
61
66
62
- $ serializer = $ this ->getMockBuilder (SerializerInterface::class)-> getMock ( );
67
+ $ serializer = $ this ->createMock (SerializerInterface::class);
63
68
$ serializer ->method ('encode ' )->with ($ envelope )->willReturnOnConsecutiveCalls ($ encoded );
64
69
65
- $ connection = $ this ->getMockBuilder (Connection::class)-> disableOriginalConstructor ()-> getMock ( );
70
+ $ connection = $ this ->createMock (Connection::class);
66
71
$ connection ->expects ($ this ->once ())->method ('publish ' )->with ($ encoded ['body ' ], []);
67
72
68
73
$ sender = new AmqpSender ($ connection , $ serializer );
@@ -74,10 +79,10 @@ public function testContentTypeHeaderIsMovedToAttribute()
74
79
$ envelope = new Envelope (new DummyMessage ('Oy ' ));
75
80
$ encoded = ['body ' => '... ' , 'headers ' => ['type ' => DummyMessage::class, 'Content-Type ' => 'application/json ' ]];
76
81
77
- $ serializer = $ this ->getMockBuilder (SerializerInterface::class)-> getMock ( );
82
+ $ serializer = $ this ->createMock (SerializerInterface::class);
78
83
$ serializer ->method ('encode ' )->with ($ envelope )->willReturnOnConsecutiveCalls ($ encoded );
79
84
80
- $ connection = $ this ->getMockBuilder (Connection::class)-> disableOriginalConstructor ()-> getMock ( );
85
+ $ connection = $ this ->createMock (Connection::class);
81
86
unset($ encoded ['headers ' ]['Content-Type ' ]);
82
87
$ stamp = new AmqpStamp (null , \AMQP_NOPARAM , ['content_type ' => 'application/json ' ]);
83
88
$ connection ->expects ($ this ->once ())->method ('publish ' )->with ($ encoded ['body ' ], $ encoded ['headers ' ], 0 , $ stamp );
@@ -91,10 +96,10 @@ public function testContentTypeHeaderDoesNotOverwriteAttribute()
91
96
$ envelope = (new Envelope (new DummyMessage ('Oy ' )))->with ($ stamp = new AmqpStamp ('rk ' , \AMQP_NOPARAM , ['content_type ' => 'custom ' ]));
92
97
$ encoded = ['body ' => '... ' , 'headers ' => ['type ' => DummyMessage::class, 'Content-Type ' => 'application/json ' ]];
93
98
94
- $ serializer = $ this ->getMockBuilder (SerializerInterface::class)-> getMock ( );
99
+ $ serializer = $ this ->createMock (SerializerInterface::class);
95
100
$ serializer ->method ('encode ' )->with ($ envelope )->willReturnOnConsecutiveCalls ($ encoded );
96
101
97
- $ connection = $ this ->getMockBuilder (Connection::class)-> disableOriginalConstructor ()-> getMock ( );
102
+ $ connection = $ this ->createMock (Connection::class);
98
103
unset($ encoded ['headers ' ]['Content-Type ' ]);
99
104
$ connection ->expects ($ this ->once ())->method ('publish ' )->with ($ encoded ['body ' ], $ encoded ['headers ' ], 0 , $ stamp );
100
105
@@ -104,14 +109,14 @@ public function testContentTypeHeaderDoesNotOverwriteAttribute()
104
109
105
110
public function testItThrowsATransportExceptionIfItCannotSendTheMessage ()
106
111
{
107
- $ this ->expectException (\ Symfony \ Component \ Messenger \ Exception \ TransportException::class);
112
+ $ this ->expectException (TransportException::class);
108
113
$ envelope = new Envelope (new DummyMessage ('Oy ' ));
109
114
$ encoded = ['body ' => '... ' , 'headers ' => ['type ' => DummyMessage::class]];
110
115
111
- $ serializer = $ this ->getMockBuilder (SerializerInterface::class)-> getMock ( );
116
+ $ serializer = $ this ->createMock (SerializerInterface::class);
112
117
$ serializer ->method ('encode ' )->with ($ envelope )->willReturnOnConsecutiveCalls ($ encoded );
113
118
114
- $ connection = $ this ->getMockBuilder (Connection::class)-> disableOriginalConstructor ()-> getMock ( );
119
+ $ connection = $ this ->createMock (Connection::class);
115
120
$ connection ->method ('publish ' )->with ($ encoded ['body ' ], $ encoded ['headers ' ])->willThrowException (new \AMQPException ());
116
121
117
122
$ sender = new AmqpSender ($ connection , $ serializer );
0 commit comments