2
2
3
3
namespace League \OAuth2 \Client \Test \Provider ;
4
4
5
+ use UnexpectedValueException ;
5
6
use Eloquent \Liberator \Liberator ;
6
7
use Eloquent \Phony \Phpunit \Phony ;
7
8
use GuzzleHttp \Exception \BadResponseException ;
10
11
use League \OAuth2 \Client \Test \Provider \Fake as MockProvider ;
11
12
use League \OAuth2 \Client \Grant \AbstractGrant ;
12
13
use League \OAuth2 \Client \Grant \GrantFactory ;
14
+ use League \OAuth2 \Client \Grant \Exception \InvalidGrantException ;
13
15
use League \OAuth2 \Client \Token \AccessToken ;
14
16
use League \OAuth2 \Client \Token \AccessTokenInterface ;
15
17
use League \OAuth2 \Client \Tool \RequestFactory ;
@@ -35,19 +37,15 @@ protected function setUp()
35
37
]);
36
38
}
37
39
38
- /**
39
- * @expectedException League\OAuth2\Client\Grant\Exception\InvalidGrantException
40
- */
41
40
public function testInvalidGrantString ()
42
41
{
42
+ $ this ->expectException (InvalidGrantException::class);
43
43
$ this ->provider ->getAccessToken ('invalid_grant ' , ['invalid_parameter ' => 'none ' ]);
44
44
}
45
45
46
- /**
47
- * @expectedException League\OAuth2\Client\Grant\Exception\InvalidGrantException
48
- */
49
46
public function testInvalidGrantObject ()
50
47
{
48
+ $ this ->expectException (InvalidGrantException::class);
51
49
$ grant = new \StdClass ();
52
50
$ this ->provider ->getAccessToken ($ grant , ['invalid_parameter ' => 'none ' ]);
53
51
}
@@ -398,11 +396,9 @@ public function testErrorResponsesCanBeCustomizedAtTheProvider()
398
396
);
399
397
}
400
398
401
- /**
402
- * @expectedException \League\OAuth2\Client\Provider\Exception\IdentityProviderException
403
- */
404
399
public function testClientErrorTriggersProviderException ()
405
400
{
401
+ $ this ->expectException (IdentityProviderException::class);
406
402
$ provider = new MockProvider ([
407
403
'clientId ' => 'mock_client_id ' ,
408
404
'clientSecret ' => 'mock_secret ' ,
@@ -600,29 +596,34 @@ public function parseResponseProvider()
600
596
/**
601
597
* @dataProvider parseResponseProvider
602
598
*/
603
- public function testParseResponse ($ body , $ type , $ parsed )
599
+ public function testParseResponse ($ body , $ type , $ parsed, $ statusCode = 200 )
604
600
{
605
601
$ stream = Phony::mock (StreamInterface::class);
606
602
$ stream ->__toString ->returns ($ body );
607
603
608
604
$ response = Phony::mock (ResponseInterface::class);
609
605
$ response ->getBody ->returns ($ stream ->get ());
610
606
$ response ->getHeader ->with ('content-type ' )->returns ($ type );
607
+ $ response ->getStatusCode ->returns ($ statusCode );
611
608
612
609
$ method = $ this ->getMethod (AbstractProvider::class, 'parseResponse ' );
613
610
$ result = $ method ->invoke ($ this ->provider , $ response ->get ());
614
611
615
612
$ this ->assertEquals ($ parsed , $ result );
616
613
}
617
614
618
- /**
619
- * @expectedException UnexpectedValueException
620
- */
621
615
public function testParseResponseJsonFailure ()
622
616
{
617
+ $ this ->expectException (UnexpectedValueException::class);
623
618
$ this ->testParseResponse ('{a: 1} ' , 'application/json ' , null );
624
619
}
625
620
621
+ public function testParseResponseNonJsonFailure ()
622
+ {
623
+ $ this ->expectException (UnexpectedValueException::class);
624
+ $ this ->testParseResponse ('<xml></xml> ' , 'application/xml ' , null , 500 );
625
+ }
626
+
626
627
public function getAppendQueryProvider ()
627
628
{
628
629
return [
@@ -676,6 +677,31 @@ public function testDefaultPrepareAccessTokenResponse()
676
677
$ this ->assertEquals ($ result ['user_id ' ], $ newResult ['resource_owner_id ' ]);
677
678
}
678
679
680
+ public function testGuardedProperties ()
681
+ {
682
+ $ options = [
683
+ 'clientId ' => 'mock_client_id ' ,
684
+ 'clientSecret ' => 'mock_secret ' ,
685
+ 'redirectUri ' => 'none ' ,
686
+ 'skipMeDuringMassAssignment ' => 'bar ' ,
687
+ 'guarded ' => 'foo '
688
+ ];
689
+
690
+ $ provider = new Fake \ProviderWithGuardedProperties ($ options );
691
+
692
+ $ this ->assertAttributeNotEquals (
693
+ $ options ['skipMeDuringMassAssignment ' ],
694
+ 'skipMeDuringMassAssignment ' ,
695
+ $ provider
696
+ );
697
+
698
+ $ this ->assertAttributeNotEquals (
699
+ $ options ['guarded ' ],
700
+ 'guarded ' ,
701
+ $ provider
702
+ );
703
+ }
704
+
679
705
public function testPrepareAccessTokenResponseWithDotNotation ()
680
706
{
681
707
$ provider = Phony::partialMock (Fake \ProviderWithAccessTokenResourceOwnerId::class);
0 commit comments