New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+Tests to check if adapter passed in http_client_options gets correctly initialized #18

Merged
merged 2 commits into from Jul 27, 2016

Conversation

Projects
None yet
3 participants
@lorenzoferrarajr
Copy link
Contributor

lorenzoferrarajr commented Nov 24, 2013

Hello, I hope these tests are useful. I've added three tests to check if the adapter passed in the http_client_options gets correctly initialized.

The first test testAdapterAlwaysReachableIfSpecified passes, but the other two don't. It seems there is some issue when passing access_token.

I got the problem while following the documentation on Authentication where it says that this configuration can be used:

$twitter = new ZendService\Twitter\Twitter(array(
    'access_token' => array( // or use "accessToken" as the key; both work
        'token' => 'your-access-token',
        'secret' => 'your-access-token-secret',
    ),
    'oauth_options' => array( // or use "oauthOptions" as the key; both work
        'consumerKey' => 'your-consumer-key',
        'consumerSecret' => 'your-consumer-secret',
    ),
    'http_client_options' => array(
        'adapter' => 'Zend_Http\Client\Adapter\Curl',
    ),
));
public function testAdapterAlwaysReachableIfSpecified()
{
$adapter = new \Zend\Http\Client\Adapter\Curl();

This comment has been minimized.

@Maks3w

Maks3w Nov 24, 2013

Member

Please import the class instead of use the FQCN

{
$adapter = new \Zend\Http\Client\Adapter\Curl();
$config = array(

This comment has been minimized.

@Maks3w

Maks3w Nov 24, 2013

Member

May should be refactored this three tests in a single one plus a data provider.

@lorenzoferrarajr

This comment has been minimized.

Copy link
Contributor

lorenzoferrarajr commented Nov 26, 2013

On line 163 of ZendService/Twitter/Twitter.php:

$this->setHttpClient($accessToken->getHttpClient($oauthOptions, static::OAUTH_BASE_URI, $httpClientOptions));

$httpClientOptions contains:

array(1) {
    ["adapter"]=> string(29) "Zend\Http\Client\Adapter\Curl"
}

$accessToken is an instance of ZendOAuth\Token\Access.

On line 83 of ZendOAuth/Token/Access.php:

$client = new Client($oauthOptions, $uri, $config, $excludeCustomParamsFromHeader);

What was in $httpClientOptions is now in $config and it's used to create an instance of ZendOAuth\Client.

So the constructor of ZendOauth\Client on line 61 calls

parent::__construct($uri, $config);

where $config is sting the array containing the specified adapter. The parent constructor is on line 132 of the Zend\Http\Client class.

This pull request seems to fix the unit tests I've added. Can you please take a look at it? I've closed the pull request because at one point it seemed like the problem wasn't on Zend\Http\Client.

Thanks!

weierophinney added a commit to weierophinney/ZendService_Twitter that referenced this pull request Jul 27, 2016

Merge pull request zendframework#18 from lorenzoferrarajr/master
+Tests to check if adapter passed in http_client_options gets correctly initialized

@weierophinney weierophinney merged commit 4bfe671 into zendframework:master Jul 27, 2016

1 check failed

default The Travis CI build failed
Details

weierophinney added a commit that referenced this pull request Jul 27, 2016

Merge branch 'hotfix/18'
Close #31
Close #18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment