17
17
use Prophecy \Argument ;
18
18
use Prophecy \Prophecy \ObjectProphecy ;
19
19
use Psr \Http \Message \RequestInterface ;
20
- use SendinBlue \Client \ApiException ;
21
20
use Sulu \Bundle \FormBundle \Configuration \FormConfiguration ;
22
21
use Sulu \Bundle \FormBundle \Entity \Dynamic ;
23
22
use Sulu \Bundle \FormBundle \Entity \Form ;
@@ -70,20 +69,14 @@ public function testGetSubscribedEvents(): void
70
69
71
70
public function testlistSubscribeNotExist (): void
72
71
{
73
- $ this ->requestStack ->push (Request::create ('http://localhost/ ' , 'POST ' ));
72
+ $ this ->requestStack ->push (Request::create ('http://localhost/newsletter ' , 'POST ' ));
74
73
$ event = $ this ->createFormSavePostEvent ();
75
74
76
75
$ self = $ this ;
77
76
$ this ->client ->send (Argument::cetera ())->will (function ($ args ) use ($ self ) {
78
77
/** @var RequestInterface $request */
79
78
$ request = $ args [0 ];
80
79
81
- if ('https://api.sendinblue.com/v3/contacts/john.doe%40example.org ' === $ request ->getUri ()->__toString ()) {
82
- $ self ->assertSame ('GET ' , $ request ->getMethod ());
83
-
84
- throw new ApiException ('' , 404 );
85
- }
86
-
87
80
if ('https://api.sendinblue.com/v3/contacts/doubleOptinConfirmation ' === $ request ->getUri ()->__toString ()) {
88
81
$ self ->assertSame ('POST ' , $ request ->getMethod ());
89
82
@@ -92,67 +85,20 @@ public function testlistSubscribeNotExist(): void
92
85
$ self ->assertSame ([
93
86
94
87
'attributes ' => [
95
- 'FIRST_NAME ' => 'John ' ,
96
- 'LAST_NAME ' => 'Doe ' ,
88
+ 'firstname ' => 'John ' ,
89
+ 'lastname ' => 'Doe ' ,
97
90
],
98
91
'includeListIds ' => ['789 ' ],
99
92
'templateId ' => 456 ,
100
- 'redirectionUrl ' => 'http://localhost? subscribe=true ' ,
93
+ 'redirectionUrl ' => 'http://localhost/newsletter?send=true& subscribe=true ' ,
101
94
], $ json );
102
95
103
96
return new Response ();
104
97
}
105
98
106
99
throw new \RuntimeException ('Unexpected request: ' . $ request ->getUri ()->__toString ());
107
100
})
108
- ->shouldBeCalledTimes (2 );
109
-
110
- // act
111
- $ this ->sendinblueListSubscriber ->listSubscribe ($ event );
112
-
113
- $ this ->assertTrue (true );
114
- }
115
-
116
- public function testlistSubscribeAlreadyExist (): void
117
- {
118
- $ this ->requestStack ->push (Request::create ('http://localhost/ ' , 'POST ' ));
119
- $ event = $ this ->createFormSavePostEvent ();
120
-
121
- $ self = $ this ;
122
- $ this ->client ->send (Argument::cetera ())->will (function ($ args ) use ($ self ) {
123
- /** @var RequestInterface $request */
124
- $ request = $ args [0 ];
125
-
126
- if ('https://api.sendinblue.com/v3/contacts/john.doe%40example.org ' === $ request ->getUri ()->__toString ()
127
- && 'GET ' === $ request ->getMethod ()
128
- ) {
129
- return new Response (200 , ['Content-Type ' => 'application/json ' ], \json_encode ([
130
- 'id ' => 123 ,
131
-
132
- 'attributes ' => [],
133
- 'listIds ' => [],
134
- ]));
135
- }
136
-
137
- if ('https://api.sendinblue.com/v3/contacts/john.doe%40example.org ' === $ request ->getUri ()->__toString ()
138
- && 'PUT ' === $ request ->getMethod ()
139
- ) {
140
- $ json = \json_decode ($ request ->getBody ()->getContents (), true );
141
-
142
- $ self ->assertSame ([
143
- 'attributes ' => [
144
- 'FIRST_NAME ' => 'John ' ,
145
- 'LAST_NAME ' => 'Doe ' ,
146
- ],
147
- 'listIds ' => ['789 ' ],
148
- ], $ json );
149
-
150
- return new Response ();
151
- }
152
-
153
- throw new \RuntimeException ('Unexpected request ( ' . $ request ->getMethod () . '): ' . $ request ->getUri ()->__toString ());
154
- })
155
- ->shouldBeCalledTimes (2 );
101
+ ->shouldBeCalledOnce ();
156
102
157
103
// act
158
104
$ this ->sendinblueListSubscriber ->listSubscribe ($ event );
0 commit comments