1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-26 19:15:10 +01:00
guzzle/tests/Guzzle/Tests/Http/Message/HeaderTest.php

127 lines
3.4 KiB
PHP
Raw Normal View History

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-21 00:23:07 -07:00
<?php
namespace Guzzle\Tests\Http\Message;
use Guzzle\Http\Message\Header;
/**
* @covers Guzzle\Http\Message\Header
*/
class HeaderTest extends \Guzzle\Tests\GuzzleTestCase
{
protected $test = array(
'zoo' => array('foo', 'Foo'),
'Zoo' => 'bar',
);
public function testRawReturnsRawArray()
{
$i = new Header('Zoo', $this->test);
$this->assertEquals(array(
'zoo' => array('foo', 'Foo'),
'Zoo' => array('bar')
), $i->raw());
}
public function testStoresHeaderName()
{
$i = new Header('Zoo', $this->test);
$this->assertEquals('Zoo', $i->getName());
}
public function testConvertsToString()
{
$i = new Header('Zoo', $this->test);
$this->assertEquals('foo; Foo; bar', (string) $i);
$i->setGlue(', ');
$this->assertEquals('foo, Foo, bar', (string) $i);
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-21 00:23:07 -07:00
}
public function testNormalizesCases()
{
$h = new Header('Zoo', $this->test);
$h->normalize();
$this->assertEquals(array(
'Zoo' => array('foo', 'Foo', 'bar')
), $h->raw());
}
public function testCanSearchForValues()
{
$h = new Header('Zoo', $this->test);
$this->assertTrue($h->hasValue('foo'));
$this->assertTrue($h->hasValue('Foo'));
$this->assertTrue($h->hasValue('bar'));
$this->assertFalse($h->hasValue('moo'));
$this->assertFalse($h->hasValue('FoO'));
$this->assertTrue($h->hasValue('FoO', true));
}
public function testIsCountable()
{
$h = new Header('Zoo', $this->test);
$this->assertEquals(3, count($h));
}
public function testCanBeIterated()
{
$h = new Header('Zoo', $this->test);
$results = array();
foreach ($h as $key => $value) {
$results[$key] = $value;
}
$this->assertEquals(array(
'foo', 'Foo', 'bar'
), $results);
}
public function testAllowsFalseyValues()
{
// Allows 0
$h = new Header('Foo', 0, ';');
$this->assertEquals('0', (string) $h);
$this->assertEquals(1, count($h));
$this->assertEquals(';', $h->getGlue());
// Does not add a null header by default
$h = new Header('Foo');
$this->assertEquals('', (string) $h);
$this->assertEquals(0, count($h));
// Allows null array for a single null header
$h = new Header('Foo', array(null));
$this->assertEquals('', (string) $h);
$this->assertEquals(1, count($h));
// Allows empty string
$h = new Header('Foo', '');
$this->assertEquals('', (string) $h);
$this->assertEquals(1, count($h));
}
public function testUsesHeaderNameWhenNoneIsSupplied()
{
$h = new Header('Foo', 'bar', ';');
$h->add('baz');
$this->assertEquals(array('Foo'), array_keys($h->raw()));
}
public function testCanCheckForExactHeaderValues()
{
$h = new Header('Foo', 'bar', ';');
$this->assertTrue($h->hasExactHeader('Foo'));
$this->assertFalse($h->hasExactHeader('foo'));
}
public function testCanRemoveValues()
{
$h = new Header('Foo', array('Foo', 'baz', 'bar'));
$h->removeValue('bar');
$this->assertTrue($h->hasValue('Foo'));
$this->assertFalse($h->hasValue('bar'));
$this->assertTrue($h->hasValue('baz'));
}
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-21 00:23:07 -07:00
}