zendframework / ZendService_Twitter

PHP OOP wrapper for the Twitter API
BSD 3-Clause "New" or "Revised" License
22 stars 23 forks source link

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

Closed lorenzoferrarajr closed 8 years ago

lorenzoferrarajr commented 10 years ago

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',
    ),
));
lorenzoferrarajr commented 10 years ago

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!