From 7af5503b6ac28a0dca30eacdbb6c229af884611e Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 18 Jul 2016 16:06:42 +0200 Subject: [PATCH] Style fixes (#117) Applied fixes from StyleCI (#116) --- .styleci.yml | 2 +- src/Authenticator.php | 8 ++-- src/AuthenticatorInterface.php | 2 +- src/Http/LinkedInUrlGeneratorInterface.php | 2 +- src/Http/RequestManager.php | 1 - src/Http/UrlGenerator.php | 8 ++-- src/LinkedIn.php | 12 +++--- src/LinkedInInterface.php | 8 ++-- src/Storage/BaseDataStorage.php | 2 +- tests/AuthenticatorTest.php | 50 +++++++++++----------- tests/Http/UrlGeneratorTest.php | 32 ++++++++------ tests/LinkedInTest.php | 50 +++++++++++----------- 12 files changed, 91 insertions(+), 86 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 515f14c..dc4cd95 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,7 +1,7 @@ preset: symfony finder: - paths: + path: - "src" - "tests" diff --git a/src/Authenticator.php b/src/Authenticator.php index c7c9a88..a98f5fd 100644 --- a/src/Authenticator.php +++ b/src/Authenticator.php @@ -132,7 +132,7 @@ protected function getAccessTokenFromCode(LinkedInUrlGeneratorInterface $urlGene throw new LinkedInException('Could not get access token: The response from LinkedIn.com was empty.'); } - $tokenData = array_merge(array('access_token' => null, 'expires_in' => null), $response); + $tokenData = array_merge(['access_token' => null, 'expires_in' => null], $response); $token = new AccessToken($tokenData['access_token'], $tokenData['expires_in']); if (!$token->hasToken()) { @@ -145,18 +145,18 @@ protected function getAccessTokenFromCode(LinkedInUrlGeneratorInterface $urlGene /** * {@inheritdoc} */ - public function getLoginUrl(LinkedInUrlGeneratorInterface $urlGenerator, $options = array()) + public function getLoginUrl(LinkedInUrlGeneratorInterface $urlGenerator, $options = []) { // Generate a state $this->establishCSRFTokenState(); // Build request params - $requestParams = array_merge(array( + $requestParams = array_merge([ 'response_type' => 'code', 'client_id' => $this->appId, 'state' => $this->getStorage()->get('state'), 'redirect_uri' => null, - ), $options); + ], $options); // Save the redirect url for later $this->getStorage()->set('redirect_uri', $requestParams['redirect_uri']); diff --git a/src/AuthenticatorInterface.php b/src/AuthenticatorInterface.php index 98d9abb..60c3af3 100644 --- a/src/AuthenticatorInterface.php +++ b/src/AuthenticatorInterface.php @@ -32,7 +32,7 @@ public function fetchNewAccessToken(LinkedInUrlGeneratorInterface $urlGenerator) * * @return string */ - public function getLoginUrl(LinkedInUrlGeneratorInterface $urlGenerator, $options = array()); + public function getLoginUrl(LinkedInUrlGeneratorInterface $urlGenerator, $options = []); /** * Clear the storage. diff --git a/src/Http/LinkedInUrlGeneratorInterface.php b/src/Http/LinkedInUrlGeneratorInterface.php index 9f6ac66..ddda3d5 100644 --- a/src/Http/LinkedInUrlGeneratorInterface.php +++ b/src/Http/LinkedInUrlGeneratorInterface.php @@ -18,5 +18,5 @@ interface LinkedInUrlGeneratorInterface * * @return string The URL for the given parameters. The URL query MUST be build with PHP_QUERY_RFC3986 */ - public function getUrl($name, $path = '', $params = array()); + public function getUrl($name, $path = '', $params = []); } diff --git a/src/Http/RequestManager.php b/src/Http/RequestManager.php index a9a4627..794d633 100644 --- a/src/Http/RequestManager.php +++ b/src/Http/RequestManager.php @@ -75,7 +75,6 @@ public function setMessageFactory(MessageFactory $messageFactory) } /** - * * @return \Http\Message\MessageFactory */ private function getMessageFactory() diff --git a/src/Http/UrlGenerator.php b/src/Http/UrlGenerator.php index 656dbf9..8224d94 100644 --- a/src/Http/UrlGenerator.php +++ b/src/Http/UrlGenerator.php @@ -12,17 +12,17 @@ class UrlGenerator implements UrlGeneratorInterface * * A list of params that might be in the query string */ - public static $knownLinkedInParams = array('state', 'code', 'access_token', 'user'); + public static $knownLinkedInParams = ['state', 'code', 'access_token', 'user']; /** * @var array domainMap * * Maps aliases to LinkedIn domains. */ - public static $domainMap = array( + public static $domainMap = [ 'api' => 'https://api.linkedin.com/', 'www' => 'https://www.linkedin.com/', - ); + ]; /** * @var bool @@ -34,7 +34,7 @@ class UrlGenerator implements UrlGeneratorInterface /** * {@inheritdoc} */ - public function getUrl($name, $path = '', $params = array()) + public function getUrl($name, $path = '', $params = []) { $url = self::$domainMap[$name]; if ($path) { diff --git a/src/LinkedIn.php b/src/LinkedIn.php index b830aaa..6ec5b3f 100644 --- a/src/LinkedIn.php +++ b/src/LinkedIn.php @@ -97,7 +97,7 @@ public function isAuthenticated() return false; } - $user = $this->api('GET', '/v1/people/~:(id,firstName,lastName)', array('format' => 'json', 'response_data_type' => 'array')); + $user = $this->api('GET', '/v1/people/~:(id,firstName,lastName)', ['format' => 'json', 'response_data_type' => 'array']); return !empty($user['id']); } @@ -105,7 +105,7 @@ public function isAuthenticated() /** * {@inheritdoc} */ - public function api($method, $resource, array $options = array()) + public function api($method, $resource, array $options = []) { // Add access token to the headers $options['headers']['Authorization'] = sprintf('Bearer %s', (string) $this->getAccessToken()); @@ -117,7 +117,7 @@ public function api($method, $resource, array $options = array()) $url = $this->getUrlGenerator()->getUrl( 'api', $resource, - isset($options['query']) ? $options['query'] : array() + isset($options['query']) ? $options['query'] : [] ); $body = isset($options['body']) ? $options['body'] : null; @@ -170,7 +170,7 @@ protected function filterRequestOption(array &$options) /** * {@inheritdoc} */ - public function getLoginUrl($options = array()) + public function getLoginUrl($options = []) { $urlGenerator = $this->getUrlGenerator(); @@ -190,7 +190,7 @@ public function getLoginUrl($options = array()) * * @return mixed */ - public function get($resource, array $options = array()) + public function get($resource, array $options = []) { return $this->api('GET', $resource, $options); } @@ -203,7 +203,7 @@ public function get($resource, array $options = array()) * * @return mixed */ - public function post($resource, array $options = array()) + public function post($resource, array $options = []) { return $this->api('POST', $resource, $options); } diff --git a/src/LinkedInInterface.php b/src/LinkedInInterface.php index cc98e86..2cb0e14 100644 --- a/src/LinkedInInterface.php +++ b/src/LinkedInInterface.php @@ -42,7 +42,7 @@ public function isAuthenticated(); * * @return mixed this depends on the response_data_type parameter. */ - public function api($method, $resource, array $options = array()); + public function api($method, $resource, array $options = []); /** * Get a login URL where the user can put his/hers LinkedIn credentials and authorize the application. @@ -55,7 +55,7 @@ public function api($method, $resource, array $options = array()); * * @return string The URL for the login flow */ - public function getLoginUrl($options = array()); + public function getLoginUrl($options = []); /** * See docs for LinkedIn::api(). @@ -65,7 +65,7 @@ public function getLoginUrl($options = array()); * * @return mixed */ - public function get($resource, array $options = array()); + public function get($resource, array $options = []); /** * See docs for LinkedIn::api(). @@ -75,7 +75,7 @@ public function get($resource, array $options = array()); * * @return mixed */ - public function post($resource, array $options = array()); + public function post($resource, array $options = []); /** * Clear the data storage. This will forget everything about the user and authentication process. diff --git a/src/Storage/BaseDataStorage.php b/src/Storage/BaseDataStorage.php index abe2e59..0e210d1 100644 --- a/src/Storage/BaseDataStorage.php +++ b/src/Storage/BaseDataStorage.php @@ -9,7 +9,7 @@ */ abstract class BaseDataStorage implements DataStorageInterface { - public static $validKeys = array('state', 'code', 'access_token', 'redirect_uri'); + public static $validKeys = ['state', 'code', 'access_token', 'redirect_uri']; /** * {@inheritdoc} diff --git a/tests/AuthenticatorTest.php b/tests/AuthenticatorTest.php index 3b7c236..8413828 100644 --- a/tests/AuthenticatorTest.php +++ b/tests/AuthenticatorTest.php @@ -23,17 +23,17 @@ public function testGetLoginUrl() { $expected = 'loginUrl'; $state = 'random'; - $params = array( + $params = [ 'response_type' => 'code', 'client_id' => self::APP_ID, 'redirect_uri' => null, 'state' => $state, - ); + ]; $storage = $this->getMock('Happyr\LinkedIn\Storage\DataStorageInterface'); $storage->method('get')->with('state')->willReturn($state); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('establishCSRFTokenState', 'getStorage'), array($this->getRequestManagerMock(), self::APP_ID, self::APP_SECRET)); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['establishCSRFTokenState', 'getStorage'], [$this->getRequestManagerMock(), self::APP_ID, self::APP_SECRET]); $auth->expects($this->exactly(2))->method('establishCSRFTokenState')->willReturn(null); $auth->method('getStorage')->will($this->returnValue($storage)); @@ -47,20 +47,20 @@ public function testGetLoginUrl() * Test with a url in the param */ $otherUrl = 'otherUrl'; - $scope = array('foo', 'bar', 'baz'); - $params = array( + $scope = ['foo', 'bar', 'baz']; + $params = [ 'response_type' => 'code', 'client_id' => self::APP_ID, 'redirect_uri' => $otherUrl, 'state' => $state, 'scope' => 'foo bar baz', - ); + ]; $generator = m::mock('Happyr\LinkedIn\Http\LinkedInUrlGeneratorInterface') ->shouldReceive('getUrl')->once()->with('www', 'oauth/v2/authorization', $params)->andReturn($expected) ->getMock(); - $this->assertEquals($expected, $auth->getLoginUrl($generator, array('redirect_uri' => $otherUrl, 'scope' => $scope))); + $this->assertEquals($expected, $auth->getLoginUrl($generator, ['redirect_uri' => $otherUrl, 'scope' => $scope])); } public function testFetchNewAccessToken() @@ -72,7 +72,7 @@ public function testFetchNewAccessToken() ->shouldReceive('set')->once()->with('access_token', 'at') ->getMock(); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getCode', 'getStorage', 'getAccessTokenFromCode'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getCode', 'getStorage', 'getAccessTokenFromCode'], [], '', false); $auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage)); $auth->expects($this->once())->method('getAccessTokenFromCode')->with($generator, $code)->will($this->returnValue('at')); $auth->expects($this->once())->method('getCode')->will($this->returnValue($code)); @@ -91,7 +91,7 @@ public function testFetchNewAccessTokenFail() ->shouldReceive('clearAll')->once() ->getMock(); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getCode', 'getStorage', 'getAccessTokenFromCode'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getCode', 'getStorage', 'getAccessTokenFromCode'], [], '', false); $auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage)); $auth->expects($this->once())->method('getAccessTokenFromCode')->with($generator, $code)->willThrowException(new LinkedInException()); $auth->expects($this->once())->method('getCode')->will($this->returnValue($code)); @@ -107,7 +107,7 @@ public function testFetchNewAccessTokenNoCode() ->shouldReceive('get')->once()->with('access_token')->andReturn('baz') ->getMock(); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getCode', 'getStorage'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getCode', 'getStorage'], [], '', false); $auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage)); $auth->expects($this->once())->method('getCode'); @@ -123,7 +123,7 @@ public function testGetAccessTokenFromCodeEmptyString() $method = new \ReflectionMethod('Happyr\LinkedIn\Authenticator', 'getAccessTokenFromCode'); $method->setAccessible(true); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array(), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', [], [], '', false); $method->invoke($auth, $generator, ''); } @@ -137,7 +137,7 @@ public function testGetAccessTokenFromCodeNull() $method = new \ReflectionMethod('Happyr\LinkedIn\Authenticator', 'getAccessTokenFromCode'); $method->setAccessible(true); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array(), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', [], [], '', false); $method->invoke($auth, $generator, null); } @@ -151,7 +151,7 @@ public function testGetAccessTokenFromCodeFalse() $method = new \ReflectionMethod('Happyr\LinkedIn\Authenticator', 'getAccessTokenFromCode'); $method->setAccessible(true); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array(), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', [], [], '', false); $method->invoke($auth, $generator, false); } @@ -169,7 +169,7 @@ public function testGetAccessTokenFromCode() )->andReturn('url') ->getMock(); - $response = array('access_token' => 'foobar', 'expires_in' => 10); + $response = ['access_token' => 'foobar', 'expires_in' => 10]; $auth = $this->prepareGetAccessTokenFromCode($code, $response); $token = $method->invoke($auth, $generator, $code); $this->assertEquals('foobar', $token, 'Standard get access token form code'); @@ -191,7 +191,7 @@ public function testGetAccessTokenFromCodeNoTokenInResponse() )->andReturn('url') ->getMock(); - $response = array('foo' => 'bar'); + $response = ['foo' => 'bar']; $auth = $this->prepareGetAccessTokenFromCode($code, $response); $this->assertNull($method->invoke($auth, $generator, $code), 'Found array but no access token'); } @@ -236,16 +236,16 @@ protected function prepareGetAccessTokenFromCode($code, $responseData) $requestManager = m::mock('Happyr\LinkedIn\Http\RequestManager') ->shouldReceive('sendRequest')->once()->with('POST', 'url', [ 'Content-Type' => 'application/x-www-form-urlencoded', - ], http_build_query(array( + ], http_build_query([ 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => $currentUrl, 'client_id' => self::APP_ID, 'client_secret' => self::APP_SECRET, - )))->andReturn($response) + ]))->andReturn($response) ->getMock(); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array($requestManager, self::APP_ID, self::APP_SECRET)); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [$requestManager, self::APP_ID, self::APP_SECRET]); $auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage)); return $auth; @@ -259,11 +259,11 @@ public function testEstablishCSRFTokenState() $storage = m::mock('Happyr\LinkedIn\Storage\DataStorageInterface') ->shouldReceive('get')->with('state')->andReturn(null, 'state') ->shouldReceive('set')->once()->with('state', \Mockery::on(function (&$param) { - return !empty($param); - })) + return !empty($param); + })) ->getMock(); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [], '', false); $auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage)); // Make sure we only set the state once @@ -278,7 +278,7 @@ public function testGetCodeEmpty() $method = new \ReflectionMethod('Happyr\LinkedIn\Authenticator', 'getCode'); $method->setAccessible(true); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array(), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', [], [], '', false); $this->assertNull($method->invoke($auth)); } @@ -295,7 +295,7 @@ public function testGetCode() ->shouldReceive('get')->once()->with('state')->andReturn($state) ->getMock(); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [], '', false); $auth->expects($this->once())->method('getStorage')->will($this->returnValue($storage)); $_REQUEST['code'] = 'foobar'; @@ -317,7 +317,7 @@ public function testGetCodeInvalidCode() ->shouldReceive('get')->once()->with('state')->andReturn('bazbar') ->getMock(); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [], '', false); $auth->expects($this->once())->method('getStorage')->will($this->returnValue($storage)); $_REQUEST['code'] = 'foobar'; @@ -335,7 +335,7 @@ public function testGetCodeUsedCode() ->shouldReceive('get')->once()->with('code')->andReturn('foobar') ->getMock(); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [], '', false); $auth->expects($this->once())->method('getStorage')->will($this->returnValue($storage)); $_REQUEST['code'] = 'foobar'; diff --git a/tests/Http/UrlGeneratorTest.php b/tests/Http/UrlGeneratorTest.php index 7cb93f0..5b5706c 100644 --- a/tests/Http/UrlGeneratorTest.php +++ b/tests/Http/UrlGeneratorTest.php @@ -57,22 +57,22 @@ public function testGetUrl() $gen = new DummyUrlGenerator(); $expected = 'https://api.linkedin.com/?bar=baz'; - $this->assertEquals($expected, $gen->getUrl('api', '', array('bar' => 'baz')), 'No path'); + $this->assertEquals($expected, $gen->getUrl('api', '', ['bar' => 'baz']), 'No path'); $expected = 'https://api.linkedin.com/foobar'; $this->assertEquals($expected, $gen->getUrl('api', 'foobar'), 'Path does not begin with forward slash'); $this->assertEquals($expected, $gen->getUrl('api', '/foobar'), 'Path begins with forward slash'); $expected = 'https://api.linkedin.com/foobar?bar=baz'; - $this->assertEquals($expected, $gen->getUrl('api', 'foobar', array('bar' => 'baz')), 'One parameter'); + $this->assertEquals($expected, $gen->getUrl('api', 'foobar', ['bar' => 'baz']), 'One parameter'); $expected = 'https://api.linkedin.com/foobar?bar=baz&a=b&c=d'; - $this->assertEquals($expected, $gen->getUrl('api', 'foobar', array('bar' => 'baz', 'a' => 'b', 'c' => 'd')), 'Many parameters'); + $this->assertEquals($expected, $gen->getUrl('api', 'foobar', ['bar' => 'baz', 'a' => 'b', 'c' => 'd']), 'Many parameters'); $expected = 'https://api.linkedin.com/foobar?bar=baz%20a%20b'; $notExpected = 'https://api.linkedin.com/foobar?bar=baz+a+b'; - $this->assertEquals($expected, $gen->getUrl('api', 'foobar', array('bar' => 'baz a b')), 'Use of PHP_QUERY_RFC3986'); - $this->assertNotEquals($notExpected, $gen->getUrl('api', 'foobar', array('bar' => 'baz a b')), 'Dont use PHP_QUERY_RFC1738'); + $this->assertEquals($expected, $gen->getUrl('api', 'foobar', ['bar' => 'baz a b']), 'Use of PHP_QUERY_RFC3986'); + $this->assertNotEquals($notExpected, $gen->getUrl('api', 'foobar', ['bar' => 'baz a b']), 'Dont use PHP_QUERY_RFC1738'); } public function testGetUrlWithParams() @@ -80,18 +80,20 @@ public function testGetUrlWithParams() $gen = new UrlGenerator(); $expected = 'https://api.linkedin.com/endpoint?bar=baz&format=json'; - $this->assertEquals($expected, $gen->getUrl('api', 'endpoint?bar=baz', array('format' => 'json'))); + $this->assertEquals($expected, $gen->getUrl('api', 'endpoint?bar=baz', ['format' => 'json'])); $expected = 'https://api.linkedin.com/endpoint?bar=baz&bar=baz'; - $this->assertEquals($expected, $gen->getUrl('api', 'endpoint?bar=baz', array('bar' => 'baz'))); + $this->assertEquals($expected, $gen->getUrl('api', 'endpoint?bar=baz', ['bar' => 'baz'])); } public function testGetCurrentURL() { - $gen = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', array('getHttpProtocol', 'getHttpHost', 'dropLinkedInParams'), array()); + $gen = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', ['getHttpProtocol', 'getHttpHost', 'dropLinkedInParams'], []); $gen->expects($this->any())->method('getHttpProtocol')->will($this->returnValue('http')); $gen->expects($this->any())->method('getHttpHost')->will($this->returnValue('www.test.com')); - $gen->expects($this->any())->method('dropLinkedInParams')->will($this->returnCallback(function ($arg) {return empty($arg) ? '' : '?'.$arg;})); + $gen->expects($this->any())->method('dropLinkedInParams')->will($this->returnCallback(function ($arg) { + return empty($arg) ? '' : '?'.$arg; + })); // fake the HPHP $_SERVER globals $_SERVER['REQUEST_URI'] = '/unit-tests.php?one=one&two=two&three=three'; @@ -120,10 +122,12 @@ public function testGetCurrentURL() public function testGetCurrentURLPort80() { - $gen = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', array('getHttpProtocol', 'getHttpHost', 'dropLinkedInParams'), array()); + $gen = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', ['getHttpProtocol', 'getHttpHost', 'dropLinkedInParams'], []); $gen->expects($this->any())->method('getHttpProtocol')->will($this->returnValue('http')); $gen->expects($this->any())->method('getHttpHost')->will($this->returnValue('www.test.com:80')); - $gen->expects($this->any())->method('dropLinkedInParams')->will($this->returnCallback(function ($arg) {return empty($arg) ? '' : '?'.$arg;})); + $gen->expects($this->any())->method('dropLinkedInParams')->will($this->returnCallback(function ($arg) { + return empty($arg) ? '' : '?'.$arg; + })); //test port 80 $_SERVER['REQUEST_URI'] = '/foobar.php'; @@ -136,10 +140,12 @@ public function testGetCurrentURLPort80() public function testGetCurrentURLPort8080() { - $gen = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', array('getHttpProtocol', 'getHttpHost', 'dropLinkedInParams'), array()); + $gen = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', ['getHttpProtocol', 'getHttpHost', 'dropLinkedInParams'], []); $gen->expects($this->any())->method('getHttpProtocol')->will($this->returnValue('http')); $gen->expects($this->any())->method('getHttpHost')->will($this->returnValue('www.test.com:8080')); - $gen->expects($this->any())->method('dropLinkedInParams')->will($this->returnCallback(function ($arg) {return empty($arg) ? '' : '?'.$arg;})); + $gen->expects($this->any())->method('dropLinkedInParams')->will($this->returnCallback(function ($arg) { + return empty($arg) ? '' : '?'.$arg; + })); //test non default port 8080 $_SERVER['REQUEST_URI'] = '/foobar.php'; diff --git a/tests/LinkedInTest.php b/tests/LinkedInTest.php index 6d8b70b..7f93b4d 100644 --- a/tests/LinkedInTest.php +++ b/tests/LinkedInTest.php @@ -16,26 +16,26 @@ public function testApi() { $resource = 'resource'; $token = 'token'; - $urlParams = array('url' => 'foo'); - $postParams = array('post' => 'bar'); + $urlParams = ['url' => 'foo']; + $postParams = ['post' => 'bar']; $method = 'GET'; - $expected = array('foobar' => 'test'); + $expected = ['foobar' => 'test']; $response = new Response(200, [], json_encode($expected)); $url = 'http://example.com/test'; - $headers = array('Authorization' => 'Bearer '.$token, 'Content-Type' => 'application/json', 'x-li-format' => 'json'); + $headers = ['Authorization' => 'Bearer '.$token, 'Content-Type' => 'application/json', 'x-li-format' => 'json']; - $generator = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', array('getUrl')); + $generator = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', ['getUrl']); $generator->expects($this->once())->method('getUrl')->with( $this->equalTo('api'), $this->equalTo($resource), - $this->equalTo(array( + $this->equalTo([ 'url' => 'foo', 'format' => 'json', - ))) + ])) ->willReturn($url); - $requestManager = $this->getMock('Happyr\LinkedIn\Http\RequestManager', array('sendRequest')); + $requestManager = $this->getMock('Happyr\LinkedIn\Http\RequestManager', ['sendRequest']); $requestManager->expects($this->once())->method('sendRequest')->with( $this->equalTo($method), $this->equalTo($url), @@ -43,30 +43,30 @@ public function testApi() $this->equalTo(json_encode($postParams))) ->willReturn($response); - $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', array('getAccessToken', 'getUrlGenerator', 'getRequestManager'), array(self::APP_ID, self::APP_SECRET)); + $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', ['getAccessToken', 'getUrlGenerator', 'getRequestManager'], [self::APP_ID, self::APP_SECRET]); $linkedIn->expects($this->once())->method('getAccessToken')->willReturn($token); $linkedIn->expects($this->once())->method('getUrlGenerator')->willReturn($generator); $linkedIn->expects($this->once())->method('getRequestManager')->willReturn($requestManager); - $result = $linkedIn->api($method, $resource, array('query' => $urlParams, 'json' => $postParams)); + $result = $linkedIn->api($method, $resource, ['query' => $urlParams, 'json' => $postParams]); $this->assertEquals($expected, $result); } public function testIsAuthenticated() { - $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', array('getAccessToken'), array(self::APP_ID, self::APP_SECRET)); + $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', ['getAccessToken'], [self::APP_ID, self::APP_SECRET]); $linkedIn->expects($this->once())->method('getAccessToken')->willReturn(null); $this->assertFalse($linkedIn->isAuthenticated()); - $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', array('api', 'getAccessToken'), array(self::APP_ID, self::APP_SECRET)); + $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', ['api', 'getAccessToken'], [self::APP_ID, self::APP_SECRET]); $linkedIn->expects($this->once())->method('getAccessToken')->willReturn('token'); - $linkedIn->expects($this->once())->method('api')->willReturn(array('id' => 4711)); + $linkedIn->expects($this->once())->method('api')->willReturn(['id' => 4711]); $this->assertTrue($linkedIn->isAuthenticated()); - $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', array('api', 'getAccessToken'), array(self::APP_ID, self::APP_SECRET)); + $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', ['api', 'getAccessToken'], [self::APP_ID, self::APP_SECRET]); $linkedIn->expects($this->once())->method('getAccessToken')->willReturn('token'); - $linkedIn->expects($this->once())->method('api')->willReturn(array('foobar' => 4711)); + $linkedIn->expects($this->once())->method('api')->willReturn(['foobar' => 4711]); $this->assertFalse($linkedIn->isAuthenticated()); } @@ -77,10 +77,10 @@ public function testAccessTokenAccessors() { $token = 'token'; - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('fetchNewAccessToken'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['fetchNewAccessToken'], [], '', false); $auth->expects($this->once())->method('fetchNewAccessToken')->will($this->returnValue($token)); - $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', array('getAuthenticator'), array(), '', false); + $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', ['getAuthenticator'], [], '', false); $linkedIn->expects($this->once())->method('getAuthenticator')->willReturn($auth); // Make sure we go to the authenticator only once @@ -161,15 +161,15 @@ public function testLoginUrl() $currentUrl = 'currentUrl'; $loginUrl = 'result'; - $generator = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', array('getCurrentUrl')); + $generator = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator', ['getCurrentUrl']); $generator->expects($this->once())->method('getCurrentUrl')->willReturn($currentUrl); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getLoginUrl'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getLoginUrl'], [], '', false); $auth->expects($this->once())->method('getLoginUrl') - ->with($generator, array('redirect_uri' => $currentUrl)) + ->with($generator, ['redirect_uri' => $currentUrl]) ->will($this->returnValue($loginUrl)); - $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', array('getAuthenticator', 'getUrlGenerator'), array(), '', false); + $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', ['getAuthenticator', 'getUrlGenerator'], [], '', false); $linkedIn->expects($this->once())->method('getAuthenticator')->willReturn($auth); $linkedIn->expects($this->once())->method('getUrlGenerator')->willReturn($generator); @@ -183,15 +183,15 @@ public function testLoginUrlWithParameter() $generator = $this->getMock('Happyr\LinkedIn\Http\UrlGenerator'); - $auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getLoginUrl'), array(), '', false); + $auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getLoginUrl'], [], '', false); $auth->expects($this->once())->method('getLoginUrl') - ->with($generator, array('redirect_uri' => $otherUrl)) + ->with($generator, ['redirect_uri' => $otherUrl]) ->will($this->returnValue($loginUrl)); - $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', array('getAuthenticator', 'getUrlGenerator'), array(), '', false); + $linkedIn = $this->getMock('Happyr\LinkedIn\LinkedIn', ['getAuthenticator', 'getUrlGenerator'], [], '', false); $linkedIn->expects($this->once())->method('getAuthenticator')->willReturn($auth); $linkedIn->expects($this->once())->method('getUrlGenerator')->willReturn($generator); - $linkedIn->getLoginUrl(array('redirect_uri' => $otherUrl)); + $linkedIn->getLoginUrl(['redirect_uri' => $otherUrl]); } }