1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-26 02:53:22 +01:00
guzzle/tests/Guzzle/Tests/GuzzleTest.php
Michael Dowling c0dc85de35 Breaking / Potentially breaking changes:
1. Adopting a marker interface for Guzzle exceptions.
        A. All exceptions emitted from Guzzle are now wrapped with a Guzzle namespaced exception.
        B. Guzzle\Common\GuzzleExceptionInterface was renamed to Guzzle\Common\GuzzleException
        C. Guzzle\Common\ExceptionCollection was renamed to Guzzle\Common\Exception\ExceptionCollection
    2. Using Header objects for Request and Response objects
        A. When you call $request->getHeader('X'), you will get back a Guzzle\Http\Message\Header object that contains all of the headers that case insensitively match.  This object can be cast to a string or iterated like an array.  You can pass true in the second argument to retrieve the header as a string.
        B. Removing the old Guzzle\Common\Collection based searching arguments from most of the request and response header methods.  All retrievals are case-insensitive and return Header objects.
    3. Changing the two headers added by the cache plugin to just one header with key and ttl.
    4. Changing Guzzle\Http\Message\Response::factory() to fromMessage().
    5. Removing the NullObject return value from ServiceDescriptions and instead simply returning null

New Features / enhancements:

    1. Adding Guzzle\Http\Message\AbstractMessage::addHeaders()
    2. Making it simpler to create service descriptions using a unified factory method that delegates to other factories.
    3. Better handling of ports and hosts in Guzzle\Http\Url

Note: This is a noisy diff because I'm removing trailing whitespace and adding a new line at the end of each source file.
2012-04-22 00:17:49 -07:00

94 lines
2.8 KiB
PHP

<?php
namespace Guzzle\Tests;
use Guzzle\Guzzle;
use Guzzle\Common\Collection;
class GuzzleTest extends GuzzleTestCase
{
/**
* @covers Guzzle\Guzzle
*/
public function testGetDefaultUserAgent()
{
Guzzle::reset();
$version = curl_version();
$agent = sprintf('Guzzle/%s (PHP=%s; curl=%s; openssl=%s)', Guzzle::VERSION, \PHP_VERSION, $version['version'], $version['ssl_version']);
$this->assertEquals($agent, Guzzle::getDefaultUserAgent());
// Get it from cache this time
$this->assertEquals($agent, Guzzle::getDefaultUserAgent());
}
/**
* @covers Guzzle\Guzzle::getHttpDate
*/
public function testGetHttpDate()
{
$fmt = 'D, d M Y H:i:s \G\M\T';
$this->assertEquals(gmdate($fmt), Guzzle::getHttpDate('now'));
$this->assertEquals(gmdate($fmt), Guzzle::getHttpDate(strtotime('now')));
$this->assertEquals(gmdate($fmt, strtotime('+1 day')), Guzzle::getHttpDate('+1 day'));
}
public function dataProvider()
{
return array(
array('this_is_a_test', '{{ a }}_is_a_{{ b }}', array(
'a' => 'this',
'b' => 'test'
)),
array('this_is_a_test', '{{abc}}_is_a_{{ 0 }}', array(
'abc' => 'this',
0 => 'test'
)),
array('this_is_a_test', '{{ abc }}_is_{{ not_found }}a_{{ 0 }}', array(
'abc' => 'this',
0 => 'test'
)),
array('this_is_a_test', 'this_is_a_test', array(
'abc' => 'this'
)),
array('_is_a_', '{{ abc }}_is_{{ not_found }}a_{{ 0 }}', array()),
array('_is_a_', '{abc}_is_{not_found}a_{{0}}', array()),
);
}
/**
* @covers Guzzle\Guzzle::inject
* @dataProvider dataProvider
*/
public function testInjectsConfigData($output, $input, $config)
{
$this->assertEquals($output, Guzzle::inject($input, new Collection($config)));
}
/**
* @covers Guzzle\Guzzle::getCurlInfo
*/
public function testCachesCurlInfo()
{
Guzzle::reset();
$c = curl_version();
$info = Guzzle::getCurlInfo();
$this->assertInternalType('array', $info);
$this->assertEquals(false, Guzzle::getCurlInfo('ewfewfewfe'));
$this->assertEquals($c['version'], Guzzle::getCurlInfo('version'));
$this->assertSame(Guzzle::getCurlInfo(), $info);
}
/**
* @covers Guzzle\Guzzle::getCurlInfo
* @covers Guzzle\Guzzle::reset
*/
public function testDeterminesIfCurlCanFollowLocation()
{
Guzzle::reset();
if (!ini_get('open_basedir')) {
$this->assertTrue(Guzzle::getCurlInfo('follow_location'));
} else {
$this->assertFalse(Guzzle::getCurlInfo('follow_location'));
}
}
}