summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource')
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/CompositeResourceIteratorFactoryTest.php37
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/MapResourceIteratorFactoryTest.php40
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ModelTest.php65
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ResourceIteratorClassFactoryTest.php41
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ResourceIteratorTest.php184
5 files changed, 367 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/CompositeResourceIteratorFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/CompositeResourceIteratorFactoryTest.php
new file mode 100644
index 0000000..41c2073
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/CompositeResourceIteratorFactoryTest.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Guzzle\Tests\Service\Resource;
+
+use Guzzle\Service\Resource\CompositeResourceIteratorFactory;
+use Guzzle\Service\Resource\ResourceIteratorClassFactory;
+use Guzzle\Tests\Service\Mock\Command\MockCommand;
+
+/**
+ * @covers Guzzle\Service\Resource\CompositeResourceIteratorFactory
+ */
+class CompositeResourceIteratorFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Iterator was not found for mock_command
+ */
+ public function testEnsuresIteratorClassExists()
+ {
+ $factory = new CompositeResourceIteratorFactory(array(
+ new ResourceIteratorClassFactory(array('Foo', 'Bar'))
+ ));
+ $cmd = new MockCommand();
+ $this->assertFalse($factory->canBuild($cmd));
+ $factory->build($cmd);
+ }
+
+ public function testBuildsResourceIterators()
+ {
+ $f1 = new ResourceIteratorClassFactory('Guzzle\Tests\Service\Mock\Model');
+ $factory = new CompositeResourceIteratorFactory(array());
+ $factory->addFactory($f1);
+ $command = new MockCommand();
+ $iterator = $factory->build($command, array('client.namespace' => 'Guzzle\Tests\Service\Mock'));
+ $this->assertInstanceOf('Guzzle\Tests\Service\Mock\Model\MockCommandIterator', $iterator);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/MapResourceIteratorFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/MapResourceIteratorFactoryTest.php
new file mode 100644
index 0000000..d166e92
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/MapResourceIteratorFactoryTest.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Guzzle\Tests\Service\Resource;
+
+use Guzzle\Service\Resource\MapResourceIteratorFactory;
+use Guzzle\Tests\Service\Mock\Command\MockCommand;
+
+/**
+ * @covers Guzzle\Service\Resource\MapResourceIteratorFactory
+ */
+class MapResourceIteratorFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /**
+ * @expectedException InvalidArgumentException
+ * @expectedExceptionMessage Iterator was not found for mock_command
+ */
+ public function testEnsuresIteratorClassExists()
+ {
+ $factory = new MapResourceIteratorFactory(array('Foo', 'Bar'));
+ $factory->build(new MockCommand());
+ }
+
+ public function testBuildsResourceIterators()
+ {
+ $factory = new MapResourceIteratorFactory(array(
+ 'mock_command' => 'Guzzle\Tests\Service\Mock\Model\MockCommandIterator'
+ ));
+ $iterator = $factory->build(new MockCommand());
+ $this->assertInstanceOf('Guzzle\Tests\Service\Mock\Model\MockCommandIterator', $iterator);
+ }
+
+ public function testUsesWildcardMappings()
+ {
+ $factory = new MapResourceIteratorFactory(array(
+ '*' => 'Guzzle\Tests\Service\Mock\Model\MockCommandIterator'
+ ));
+ $iterator = $factory->build(new MockCommand());
+ $this->assertInstanceOf('Guzzle\Tests\Service\Mock\Model\MockCommandIterator', $iterator);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ModelTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ModelTest.php
new file mode 100644
index 0000000..7214133
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ModelTest.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace Guzzle\Tests\Service\Resource;
+
+use Guzzle\Service\Resource\Model;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Common\Collection;
+
+/**
+ * @covers Guzzle\Service\Resource\Model
+ */
+class ModelTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testOwnsStructure()
+ {
+ $param = new Parameter(array('type' => 'object'));
+ $model = new Model(array('foo' => 'bar'), $param);
+ $this->assertSame($param, $model->getStructure());
+ $this->assertEquals('bar', $model->get('foo'));
+ $this->assertEquals('bar', $model['foo']);
+ }
+
+ public function testCanBeUsedWithoutStructure()
+ {
+ $model = new Model(array(
+ 'Foo' => 'baz',
+ 'Bar' => array(
+ 'Boo' => 'Bam'
+ )
+ ));
+ $transform = function ($key, $value) {
+ return ($value && is_array($value)) ? new Collection($value) : $value;
+ };
+ $model = $model->map($transform);
+ $this->assertInstanceOf('Guzzle\Common\Collection', $model->getPath('Bar'));
+ }
+
+ public function testAllowsFiltering()
+ {
+ $model = new Model(array(
+ 'Foo' => 'baz',
+ 'Bar' => 'a'
+ ));
+ $model = $model->filter(function ($i, $v) {
+ return $v[0] == 'a';
+ });
+ $this->assertEquals(array('Bar' => 'a'), $model->toArray());
+ }
+
+ public function testDoesNotIncludeEmptyStructureInString()
+ {
+ $model = new Model(array('Foo' => 'baz'));
+ $str = (string) $model;
+ $this->assertContains('Debug output of model', $str);
+ $this->assertNotContains('Model structure', $str);
+ }
+
+ public function testDoesIncludeModelStructureInString()
+ {
+ $model = new Model(array('Foo' => 'baz'), new Parameter(array('name' => 'Foo')));
+ $str = (string) $model;
+ $this->assertContains('Debug output of Foo model', $str);
+ $this->assertContains('Model structure', $str);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ResourceIteratorClassFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ResourceIteratorClassFactoryTest.php
new file mode 100644
index 0000000..7b061b5
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ResourceIteratorClassFactoryTest.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Guzzle\Tests\Service\Resource;
+
+use Guzzle\Service\Resource\ResourceIteratorClassFactory;
+use Guzzle\Tests\Service\Mock\Command\MockCommand;
+
+/**
+ * @covers Guzzle\Service\Resource\ResourceIteratorClassFactory
+ * @covers Guzzle\Service\Resource\AbstractResourceIteratorFactory
+ */
+class ResourceIteratorClassFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Iterator was not found for mock_command
+ */
+ public function testEnsuresIteratorClassExists()
+ {
+ $factory = new ResourceIteratorClassFactory(array('Foo', 'Bar'));
+ $factory->registerNamespace('Baz');
+ $command = new MockCommand();
+ $factory->build($command);
+ }
+
+ public function testBuildsResourceIterators()
+ {
+ $factory = new ResourceIteratorClassFactory('Guzzle\Tests\Service\Mock\Model');
+ $command = new MockCommand();
+ $iterator = $factory->build($command, array('client.namespace' => 'Guzzle\Tests\Service\Mock'));
+ $this->assertInstanceOf('Guzzle\Tests\Service\Mock\Model\MockCommandIterator', $iterator);
+ }
+
+ public function testChecksIfCanBuild()
+ {
+ $factory = new ResourceIteratorClassFactory('Guzzle\Tests\Service');
+ $this->assertFalse($factory->canBuild(new MockCommand()));
+ $factory = new ResourceIteratorClassFactory('Guzzle\Tests\Service\Mock\Model');
+ $this->assertTrue($factory->canBuild(new MockCommand()));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ResourceIteratorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ResourceIteratorTest.php
new file mode 100644
index 0000000..573fb6d
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Resource/ResourceIteratorTest.php
@@ -0,0 +1,184 @@
+<?php
+
+namespace Guzzle\Tests\Service\Resource;
+
+use Guzzle\Service\Resource\ResourceIterator;
+use Guzzle\Tests\Service\Mock\Model\MockCommandIterator;
+
+/**
+ * @group server
+ * @covers Guzzle\Service\Resource\ResourceIterator
+ */
+class ResourceIteratorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testDescribesEvents()
+ {
+ $this->assertInternalType('array', ResourceIterator::getAllEvents());
+ }
+
+ public function testConstructorConfiguresDefaults()
+ {
+ $ri = $this->getMockForAbstractClass('Guzzle\\Service\\Resource\\ResourceIterator', array(
+ $this->getServiceBuilder()->get('mock')->getCommand('iterable_command'),
+ array(
+ 'limit' => 10,
+ 'page_size' => 3
+ )
+ ), 'MockIterator');
+
+ $this->assertEquals(false, $ri->getNextToken());
+ $this->assertEquals(false, $ri->current());
+ }
+
+ public function testSendsRequestsForNextSetOfResources()
+ {
+ // Queue up an array of responses for iterating
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 52\r\n\r\n{ \"next_token\": \"g\", \"resources\": [\"d\", \"e\", \"f\"] }",
+ "HTTP/1.1 200 OK\r\nContent-Length: 52\r\n\r\n{ \"next_token\": \"j\", \"resources\": [\"g\", \"h\", \"i\"] }",
+ "HTTP/1.1 200 OK\r\nContent-Length: 41\r\n\r\n{ \"next_token\": \"\", \"resources\": [\"j\"] }"
+ ));
+
+ // Create a new resource iterator using the IterableCommand mock
+ $ri = new MockCommandIterator($this->getServiceBuilder()->get('mock')->getCommand('iterable_command'), array(
+ 'page_size' => 3
+ ));
+
+ // Ensure that no requests have been sent yet
+ $this->assertEquals(0, count($this->getServer()->getReceivedRequests(false)));
+
+ //$this->assertEquals(array('d', 'e', 'f', 'g', 'h', 'i', 'j'), $ri->toArray());
+ $ri->toArray();
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals(3, count($requests));
+
+ $this->assertEquals(3, $requests[0]->getQuery()->get('page_size'));
+ $this->assertEquals(3, $requests[1]->getQuery()->get('page_size'));
+ $this->assertEquals(3, $requests[2]->getQuery()->get('page_size'));
+
+ // Reset and resend
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 52\r\n\r\n{ \"next_token\": \"g\", \"resources\": [\"d\", \"e\", \"f\"] }",
+ "HTTP/1.1 200 OK\r\nContent-Length: 52\r\n\r\n{ \"next_token\": \"j\", \"resources\": [\"g\", \"h\", \"i\"] }",
+ "HTTP/1.1 200 OK\r\nContent-Length: 41\r\n\r\n{ \"next_token\": \"\", \"resources\": [\"j\"] }",
+ ));
+
+ $d = array();
+ foreach ($ri as $data) {
+ $d[] = $data;
+ }
+ $this->assertEquals(array('d', 'e', 'f', 'g', 'h', 'i', 'j'), $d);
+ }
+
+ public function testCalculatesPageSize()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 52\r\n\r\n{ \"next_token\": \"g\", \"resources\": [\"d\", \"e\", \"f\"] }",
+ "HTTP/1.1 200 OK\r\nContent-Length: 52\r\n\r\n{ \"next_token\": \"j\", \"resources\": [\"g\", \"h\", \"i\"] }",
+ "HTTP/1.1 200 OK\r\nContent-Length: 52\r\n\r\n{ \"next_token\": \"j\", \"resources\": [\"j\", \"k\"] }"
+ ));
+
+ $ri = new MockCommandIterator($this->getServiceBuilder()->get('mock')->getCommand('iterable_command'), array(
+ 'page_size' => 3,
+ 'limit' => 7
+ ));
+
+ $this->assertEquals(array('d', 'e', 'f', 'g', 'h', 'i', 'j'), $ri->toArray());
+ $requests = $this->getServer()->getReceivedRequests(true);
+ $this->assertEquals(3, count($requests));
+ $this->assertEquals(3, $requests[0]->getQuery()->get('page_size'));
+ $this->assertEquals(3, $requests[1]->getQuery()->get('page_size'));
+ $this->assertEquals(1, $requests[2]->getQuery()->get('page_size'));
+ }
+
+ public function testUseAsArray()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\nContent-Length: 52\r\n\r\n{ \"next_token\": \"g\", \"resources\": [\"d\", \"e\", \"f\"] }",
+ "HTTP/1.1 200 OK\r\nContent-Length: 52\r\n\r\n{ \"next_token\": \"\", \"resources\": [\"g\", \"h\", \"i\"] }"
+ ));
+
+ $ri = new MockCommandIterator($this->getServiceBuilder()->get('mock')->getCommand('iterable_command'));
+
+ // Ensure that the key is never < 0
+ $this->assertEquals(0, $ri->key());
+ $this->assertEquals(0, count($ri));
+
+ // Ensure that the iterator can be used as KVP array
+ $data = array();
+ foreach ($ri as $key => $value) {
+ $data[$key] = $value;
+ }
+
+ // Ensure that the iterate is countable
+ $this->assertEquals(6, count($ri));
+ $this->assertEquals(array('d', 'e', 'f', 'g', 'h', 'i'), $data);
+ }
+
+ public function testBailsWhenSendReturnsNoResults()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\n\r\n{ \"next_token\": \"g\", \"resources\": [\"d\", \"e\", \"f\"] }",
+ "HTTP/1.1 200 OK\r\n\r\n{ \"next_token\": \"\", \"resources\": [] }"
+ ));
+
+ $ri = new MockCommandIterator($this->getServiceBuilder()->get('mock')->getCommand('iterable_command'));
+
+ // Ensure that the iterator can be used as KVP array
+ $data = $ri->toArray();
+
+ // Ensure that the iterate is countable
+ $this->assertEquals(3, count($ri));
+ $this->assertEquals(array('d', 'e', 'f'), $data);
+
+ $this->assertEquals(2, $ri->getRequestCount());
+ }
+
+ public function testHoldsDataOptions()
+ {
+ $ri = new MockCommandIterator($this->getServiceBuilder()->get('mock')->getCommand('iterable_command'));
+ $this->assertNull($ri->get('foo'));
+ $this->assertSame($ri, $ri->set('foo', 'bar'));
+ $this->assertEquals('bar', $ri->get('foo'));
+ }
+
+ public function testSettingLimitOrPageSizeClearsData()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\n\r\n{ \"next_token\": \"\", \"resources\": [\"d\", \"e\", \"f\"] }",
+ "HTTP/1.1 200 OK\r\n\r\n{ \"next_token\": \"\", \"resources\": [\"d\", \"e\", \"f\"] }",
+ "HTTP/1.1 200 OK\r\n\r\n{ \"next_token\": \"\", \"resources\": [\"d\", \"e\", \"f\"] }"
+ ));
+
+ $ri = new MockCommandIterator($this->getServiceBuilder()->get('mock')->getCommand('iterable_command'));
+ $ri->toArray();
+ $this->assertNotEmpty($this->readAttribute($ri, 'resources'));
+
+ $ri->setLimit(10);
+ $this->assertEmpty($this->readAttribute($ri, 'resources'));
+
+ $ri->toArray();
+ $this->assertNotEmpty($this->readAttribute($ri, 'resources'));
+ $ri->setPageSize(10);
+ $this->assertEmpty($this->readAttribute($ri, 'resources'));
+ }
+
+ public function testWorksWithCustomAppendIterator()
+ {
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array(
+ "HTTP/1.1 200 OK\r\n\r\n{ \"next_token\": \"\", \"resources\": [\"d\", \"e\", \"f\"] }"
+ ));
+ $ri = new MockCommandIterator($this->getServiceBuilder()->get('mock')->getCommand('iterable_command'));
+ $a = new \Guzzle\Iterator\AppendIterator();
+ $a->append($ri);
+ $results = iterator_to_array($a, false);
+ $this->assertEquals(4, $ri->calledNext);
+ }
+}