1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54:
<?php
namespace Guzzle\Tests\Service\Command;
use Guzzle\Service\Command\LocationVisitor\VisitorFlyweight;
use Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor as JsonRequestVisitor;
use Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor as JsonResponseVisitor;
class VisitorFlyweightTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testUsesDefaultMappingsWithGetInstance()
{
$f = VisitorFlyweight::getInstance();
$this->assertInstanceOf('Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor', $f->getRequestVisitor('json'));
$this->assertInstanceOf('Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor', $f->getResponseVisitor('json'));
}
public function testCanUseCustomMappings()
{
$f = new VisitorFlyweight(array());
$this->assertEquals(array(), $this->readAttribute($f, 'mappings'));
}
public function testThrowsExceptionWhenRetrievingUnknownVisitor()
{
VisitorFlyweight::getInstance()->getRequestVisitor('foo');
}
public function testCachesVisitors()
{
$f = new VisitorFlyweight();
$v1 = $f->getRequestVisitor('json');
$this->assertSame($v1, $f->getRequestVisitor('json'));
}
public function testAllowsAddingVisitors()
{
$f = new VisitorFlyweight();
$j1 = new JsonRequestVisitor();
$j2 = new JsonResponseVisitor();
$f->addRequestVisitor('json', $j1);
$f->addResponseVisitor('json', $j2);
$this->assertSame($j1, $f->getRequestVisitor('json'));
$this->assertSame($j2, $f->getResponseVisitor('json'));
}
}