22
33namespace spec \Omniphx \Forrest \Authentications ;
44
5- use PhpSpec \ObjectBehavior ;
6- use Prophecy \Argument ;
7-
85use GuzzleHttp \ClientInterface ;
9- use GuzzleHttp \Message \ResponseInterface ;
106use GuzzleHttp \Message \RequestInterface ;
11- use Omniphx \Forrest \Interfaces \StorageInterface ;
12- use Omniphx \Forrest \Interfaces \RedirectInterface ;
13- use Omniphx \Forrest \Interfaces \InputInterface ;
7+ use GuzzleHttp \Message \ResponseInterface ;
148use Omniphx \Forrest \Interfaces \EventInterface ;
9+ use Omniphx \Forrest \Interfaces \InputInterface ;
10+ use Omniphx \Forrest \Interfaces \RedirectInterface ;
11+ use Omniphx \Forrest \Interfaces \StorageInterface ;
12+ use PhpSpec \ObjectBehavior ;
13+ use Prophecy \Argument ;
1514
1615class UserPasswordSpec extends ObjectBehavior
1716{
18- function let (
17+ public function let (
1918 ClientInterface $ mockedClient ,
2019 ResponseInterface $ mockedResponse ,
2120 RequestInterface $ mockedRequest ,
2221 StorageInterface $ mockedStorage ,
2322 RedirectInterface $ mockedRedirect ,
2423 InputInterface $ mockedInput ,
25- EventInterface $ mockedEvent ) {
26-
27- $ settings = array (
24+ EventInterface $ mockedEvent )
25+ {
26+ $ settings = [
2827 'authenticationFlow ' => 'UserPassword ' ,
29- 'credentials ' => array (
28+ 'credentials ' => [
3029 'consumerKey ' => 'testingClientId ' ,
3130 'consumerSecret ' => 'testingClientSecret ' ,
3231 'callbackURI ' => 'callbackURL ' ,
3332 'loginURL ' => 'https://login.salesforce.com ' ,
34- 'username ' => '' ,
35- 'password ' => '' ,
33+ 'username ' => '' ,
34+ 'password ' => '' ,
3635
37- ) ,
38- 'parameters ' => array (
36+ ] ,
37+ 'parameters ' => [
3938 'display ' => 'popup ' ,
4039 'immediate ' => 'false ' ,
4140 'state ' => '' ,
4241 'scope ' => '' ,
43- ) ,
44- 'instanceURL ' => '' ,
42+ ] ,
43+ 'instanceURL ' => '' ,
4544 'authRedirect ' => 'redirectURL ' ,
46- 'version ' => '30.0 ' ,
47- 'defaults ' => array (
45+ 'version ' => '30.0 ' ,
46+ 'defaults ' => [
4847 'method ' => 'get ' ,
4948 'format ' => 'json ' ,
5049 'compression ' => false ,
5150 'compressionType ' => 'gzip ' ,
52- ) ,
53- 'language ' => 'en_US '
54- ) ;
51+ ] ,
52+ 'language ' => 'en_US ' ,
53+ ] ;
5554
5655 $ mockedStorage ->get ('resources ' )->willReturn ([
57- 'sobjects ' => '/services/data/v30.0/sobjects ' ,
56+ 'sobjects ' => '/services/data/v30.0/sobjects ' ,
5857 'connect ' => '/services/data/v30.0/connect ' ,
5958 'query ' => '/services/data/v30.0/query ' ,
6059 'theme ' => '/services/data/v30.0/theme ' ,
@@ -68,20 +67,20 @@ function let(
6867 'flexiPage ' => '/services/data/v30.0/flexiPage ' ,
6968 'search ' => '/services/data/v30.0/search ' ,
7069 'quickActions ' => '/services/data/v30.0/quickActions ' ,
71- 'appMenu ' => '/services/data/v30.0/appMenu ' ]);
70+ 'appMenu ' => '/services/data/v30.0/appMenu ' , ]);
7271 $ mockedStorage ->get ('version ' )->willReturn ([
73- 'url ' => 'resourceURLs ' ]);
72+ 'url ' => 'resourceURLs ' , ]);
7473 $ mockedStorage ->getTokenData ()->willReturn ([
7574 'access_token ' => 'accessToken ' ,
7675 'id ' => 'https://login.salesforce.com/id/00Di0000000XXXXXX/005i0000000xxxxXXX ' ,
7776 'instance_url ' => 'https://na00.salesforce.com ' ,
78- 'token_type ' => 'Oauth ' ]);
77+ 'token_type ' => 'Oauth ' , ]);
7978 $ mockedStorage ->putTokenData (Argument::any ())->willReturn (null );
80- $ mockedStorage ->put (Argument::any (),Argument::any ())->willReturn (null );
79+ $ mockedStorage ->put (Argument::any (), Argument::any ())->willReturn (null );
8180
8281 $ mockedClient ->send (Argument::any ())->willReturn ($ mockedResponse );
83- $ mockedClient ->createRequest (Argument::any (),Argument::any (),Argument::any ())->willReturn ($ mockedRequest );
84- $ mockedClient ->post (Argument::any (),Argument::any (),Argument::any ())->willReturn ($ mockedResponse );
82+ $ mockedClient ->createRequest (Argument::any (), Argument::any (), Argument::any ())->willReturn ($ mockedRequest );
83+ $ mockedClient ->post (Argument::any (), Argument::any (), Argument::any ())->willReturn ($ mockedResponse );
8584
8685 $ this ->beConstructedWith (
8786 $ mockedClient ,
@@ -90,36 +89,35 @@ function let(
9089 $ mockedInput ,
9190 $ mockedEvent ,
9291 $ settings );
93-
9492 }
9593
96- function it_is_initializable ()
94+ public function it_is_initializable ()
9795 {
9896 $ this ->shouldHaveType ('Omniphx\Forrest\Authentications\UserPassword ' );
9997 }
10098
101- function it_should_authenticate (
99+ public function it_should_authenticate (
102100 ResponseInterface $ versionResponse ,
103101 ClientInterface $ mockedClient )
104102 {
105103 $ mockedClient ->send (Argument::any ())->shouldBeCalled (1 )->willReturn ($ versionResponse );
106104
107- $ versionResponse ->json ()->shouldBeCalled ()->willReturn ([['version ' => '30.0 ' ],['version ' => '31.0 ' ]]);
105+ $ versionResponse ->json ()->shouldBeCalled ()->willReturn ([['version ' => '30.0 ' ],['version ' => '31.0 ' ]]);
108106
109107 $ this ->authenticate ('url ' )->shouldReturn (null );
110108 }
111109
112- function it_should_refresh (
110+ public function it_should_refresh (
113111 ResponseInterface $ mockedResponse ,
114112 StorageInterface $ mockedStorage )
115113 {
116- $ mockedResponse ->json ()->shouldBeCalled ()->willReturn (['key ' => 'value ' ]);
114+ $ mockedResponse ->json ()->shouldBeCalled ()->willReturn (['key ' => 'value ' ]);
117115 $ mockedStorage ->putTokenData (Argument::type ('array ' ))->shouldBeCalled ();
118116
119117 $ this ->refresh ()->shouldReturn (null );
120118 }
121119
122- function it_should_return_the_request (
120+ public function it_should_return_the_request (
123121 ClientInterface $ mockedClient ,
124122 RequestInterface $ mockedRequest ,
125123 ResponseInterface $ mockedResponse )
@@ -128,133 +126,132 @@ function it_should_return_the_request(
128126
129127 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('worked ' );
130128
131- $ this ->request ('url ' ,['key ' => 'value ' ])->shouldReturn ('worked ' );
129+ $ this ->request ('url ' , ['key ' => 'value ' ])->shouldReturn ('worked ' );
132130 }
133131
134- function it_should_refresh_the_token_if_response_throws_error (
132+ public function it_should_refresh_the_token_if_response_throws_error (
135133 ClientInterface $ mockedClient ,
136134 RequestInterface $ mockedRequest )
137135 {
138-
139136 $ mockedClient ->send ($ mockedRequest )->willThrow ('\Omniphx\Forrest\Exceptions\TokenExpiredException ' );
140137
141138 //This might seem counter-intuitive. We are throwing an exception with the send() method, but we can't stop it. Since we are calling the send() method twice, the behavior is correct for it to throw an exception. Actual behavior would never throw the exception, it would return a response.
142- $ this ->shouldThrow ('\Omniphx\Forrest\Exceptions\TokenExpiredException ' )->duringRequest ('url ' ,['key ' => 'value ' ]);
139+ $ this ->shouldThrow ('\Omniphx\Forrest\Exceptions\TokenExpiredException ' )->duringRequest ('url ' , ['key ' => 'value ' ]);
143140 }
144141
145- function it_should_revoke_the_authentication_token (ClientInterface $ mockedClient )
142+ public function it_should_revoke_the_authentication_token (ClientInterface $ mockedClient )
146143 {
147- $ mockedClient ->post (Argument::type ('string ' ),Argument::type ('array ' ))->shouldBeCalled ();
144+ $ mockedClient ->post (Argument::type ('string ' ), Argument::type ('array ' ))->shouldBeCalled ();
148145 $ this ->revoke ()->shouldReturn (null );
149146 }
150147
151148 //Client
152149
153- function it_should_return_the_versions (ResponseInterface $ mockedResponse )
150+ public function it_should_return_the_versions (ResponseInterface $ mockedResponse )
154151 {
155- $ mockedResponse ->json ()->shouldBeCalled ()->willReturn (array ( 'version ' => '29.0 ' ,'version ' => '30.0 ' ) );
152+ $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ([ 'version ' => '29.0 ' ,'version ' => '30.0 ' ] );
156153
157- $ this ->versions ()->shouldReturn (array ( 'version ' => '29.0 ' ,'version ' => '30.0 ' ) );
154+ $ this ->versions ()->shouldReturn ([ 'version ' => '29.0 ' ,'version ' => '30.0 ' ] );
158155 }
159156
160- function it_should_return_resources (ResponseInterface $ mockedResponse )
157+ public function it_should_return_resources (ResponseInterface $ mockedResponse )
161158 {
162159 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('versionURLs ' );
163160
164161 $ this ->resources ()->shouldReturn ('versionURLs ' );
165162 }
166163
167- function it_should_return_identity (ResponseInterface $ mockedResponse )
164+ public function it_should_return_identity (ResponseInterface $ mockedResponse )
168165 {
169166 $ mockedResponse ->json ()->willReturn ('Identity ' );
170167
171168 $ this ->identity ()->shouldReturn ('Identity ' );
172169 }
173170
174- function it_should_return_limits (
171+ public function it_should_return_limits (
175172 StorageInterface $ mockedStorage ,
176173 ResponseInterface $ mockedResponse )
177174 {
178- $ mockedStorage ->get ('version ' )->shouldBeCalled ()->willReturn (array ( 'url ' => 'versionURL ' ) );
175+ $ mockedStorage ->get ('version ' )->shouldBeCalled ()->willReturn ([ 'url ' => 'versionURL ' ] );
179176 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('limits ' );
180177
181178 $ this ->limits ()->shouldReturn ('limits ' );
182179 }
183180
184- function it_should_return_describe (
181+ public function it_should_return_describe (
185182 StorageInterface $ mockedStorage ,
186183 ResponseInterface $ mockedResponse )
187184 {
188- $ mockedStorage ->get ('version ' )->shouldBeCalled ()->willReturn (array ( 'url ' => 'versionURL ' ) );
185+ $ mockedStorage ->get ('version ' )->shouldBeCalled ()->willReturn ([ 'url ' => 'versionURL ' ] );
189186 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('describe ' );
190187
191- $ this ->describe ()->shouldReturn ('describe ' );
188+ $ this ->describe ()->shouldReturn ('describe ' );
192189 }
193190
194- function it_should_return_query (ResponseInterface $ mockedResponse )
191+ public function it_should_return_query (ResponseInterface $ mockedResponse )
195192 {
196193 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('query ' );
197194
198195 $ this ->query ('query ' )->shouldReturn ('query ' );
199196 }
200197
201- function it_should_return_query_next (ResponseInterface $ mockedResponse )
198+ public function it_should_return_query_next (ResponseInterface $ mockedResponse )
202199 {
203200 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('query ' );
204201
205202 $ this ->next ('nextUrl ' )->shouldReturn ('query ' );
206203 }
207204
208- function it_should_return_queryExplain (ResponseInterface $ mockedResponse )
205+ public function it_should_return_queryExplain (ResponseInterface $ mockedResponse )
209206 {
210207 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('queryExplain ' );
211208
212209 $ this ->queryExplain ('query ' )->shouldReturn ('queryExplain ' );
213210 }
214211
215- function it_should_return_queryAll (ResponseInterface $ mockedResponse )
212+ public function it_should_return_queryAll (ResponseInterface $ mockedResponse )
216213 {
217214 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('queryAll ' );
218215
219216 $ this ->queryAll ('query ' )->shouldReturn ('queryAll ' );
220217 }
221218
222- function it_should_return_quickActions (ResponseInterface $ mockedResponse )
219+ public function it_should_return_quickActions (ResponseInterface $ mockedResponse )
223220 {
224221 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('quickActions ' );
225222
226223 $ this ->quickActions ()->shouldReturn ('quickActions ' );
227224 }
228225
229- function it_should_return_search (ResponseInterface $ mockedResponse )
226+ public function it_should_return_search (ResponseInterface $ mockedResponse )
230227 {
231228 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('search ' );
232229
233230 $ this ->search ('query ' )->shouldReturn ('search ' );
234231 }
235232
236- function it_should_return_ScopeOrder (ResponseInterface $ mockedResponse )
233+ public function it_should_return_ScopeOrder (ResponseInterface $ mockedResponse )
237234 {
238235 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('searchScopeOrder ' );
239236
240237 $ this ->scopeOrder ()->shouldReturn ('searchScopeOrder ' );
241238 }
242239
243- function it_should_return_searchLayouts (ResponseInterface $ mockedResponse )
240+ public function it_should_return_searchLayouts (ResponseInterface $ mockedResponse )
244241 {
245242 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('searchLayouts ' );
246243
247244 $ this ->searchLayouts ('objectList ' )->shouldReturn ('searchLayouts ' );
248245 }
249246
250- function it_should_return_suggestedArticles (ResponseInterface $ mockedResponse )
247+ public function it_should_return_suggestedArticles (ResponseInterface $ mockedResponse )
251248 {
252249 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('suggestedArticles ' );
253250
254251 $ this ->suggestedArticles ('query ' )->shouldReturn ('suggestedArticles ' );
255252 }
256253
257- function it_should_return_suggestedQueries (ResponseInterface $ mockedResponse )
254+ public function it_should_return_suggestedQueries (ResponseInterface $ mockedResponse )
258255 {
259256 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('searchSuggestedQueries ' );
260257
@@ -263,31 +260,30 @@ function it_should_return_suggestedQueries(ResponseInterface $mockedResponse)
263260
264261 //Resource class
265262
266- function it_returns_a_resource (
263+ public function it_returns_a_resource (
267264 ClientInterface $ mockedClient ,
268265 StorageInterface $ mockedStorage ,
269266 RequestInterface $ mockedRequest ,
270267 ResponseInterface $ mockedResponse )
271268 {
272- $ mockedClient ->createRequest (Argument::type ('string ' ),Argument::type ('string ' ),Argument::type ('array ' ))->willReturn ($ mockedRequest );
269+ $ mockedClient ->createRequest (Argument::type ('string ' ), Argument::type ('string ' ), Argument::type ('array ' ))->willReturn ($ mockedRequest );
273270 $ mockedClient ->send (Argument::any ())->willReturn ($ mockedResponse );
274271
275272 $ mockedResponse ->json ()->shouldBeCalled ()->willReturn ('jsonResource ' );
276273 $ mockedResponse ->xml ()->shouldBeCalled ()->willReturn ('xmlResource ' );
277274
278- $ mockedStorage ->getTokenData ()->willReturn (array (
279- 'access_token ' =>'abc ' ,
280- 'instance_url ' =>'def ' ,
281- 'token_type ' =>'bearer ' ) );
275+ $ mockedStorage ->getTokenData ()->willReturn ([
276+ 'access_token ' => 'abc ' ,
277+ 'instance_url ' => 'def ' ,
278+ 'token_type ' => 'bearer ' , ] );
282279
283- $ this ->request ('uri ' ,[])->shouldReturn ('jsonResource ' );
284- $ this ->request ('uri ' ,['format ' => 'xml ' ])->shouldReturn ('xmlResource ' );
280+ $ this ->request ('uri ' , [])->shouldReturn ('jsonResource ' );
281+ $ this ->request ('uri ' , ['format ' => 'xml ' ])->shouldReturn ('xmlResource ' );
285282 }
286283
287- function it_allows_access_to_the_guzzle_client (
284+ public function it_allows_access_to_the_guzzle_client (
288285 ClientInterface $ mockedClient )
289286 {
290287 $ this ->getClient ()->shouldReturn ($ mockedClient );
291288 }
292-
293- }
289+ }
0 commit comments