summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory')
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/AliasFactoryTest.php76
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/CompositeFactoryTest.php124
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/ConcreteClassFactoryTest.php49
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/MapFactoryTest.php37
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/ServiceDescriptionFactoryTest.php68
5 files changed, 354 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/AliasFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/AliasFactoryTest.php
new file mode 100644
index 0000000..ab1041a
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/AliasFactoryTest.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command;
+
+use Guzzle\Service\Client;
+use Guzzle\Service\Command\Factory\AliasFactory;
+use Guzzle\Service\Command\Factory\MapFactory;
+use Guzzle\Service\Command\Factory\CompositeFactory;
+
+/**
+ * @covers Guzzle\Service\Command\Factory\AliasFactory
+ */
+class AliasFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ private $factory;
+ private $client;
+
+ public function setup()
+ {
+ $this->client = new Client();
+
+ $map = new MapFactory(array(
+ 'test' => 'Guzzle\Tests\Service\Mock\Command\MockCommand',
+ 'test1' => 'Guzzle\Tests\Service\Mock\Command\OtherCommand'
+ ));
+
+ $this->factory = new AliasFactory($this->client, array(
+ 'foo' => 'test',
+ 'bar' => 'sub',
+ 'sub' => 'test1',
+ 'krull' => 'test3',
+ 'krull_2' => 'krull',
+ 'sub_2' => 'bar',
+ 'bad_link' => 'jarjar'
+ ));
+
+ $map2 = new MapFactory(array(
+ 'test3' => 'Guzzle\Tests\Service\Mock\Command\Sub\Sub'
+ ));
+
+ $this->client->setCommandFactory(new CompositeFactory(array($map, $this->factory, $map2)));
+ }
+
+ public function aliasProvider()
+ {
+ return array(
+ array('foo', 'Guzzle\Tests\Service\Mock\Command\MockCommand', false),
+ array('bar', 'Guzzle\Tests\Service\Mock\Command\OtherCommand', false),
+ array('sub', 'Guzzle\Tests\Service\Mock\Command\OtherCommand', false),
+ array('sub_2', 'Guzzle\Tests\Service\Mock\Command\OtherCommand', false),
+ array('krull', 'Guzzle\Tests\Service\Mock\Command\Sub\Sub', false),
+ array('krull_2', 'Guzzle\Tests\Service\Mock\Command\Sub\Sub', false),
+ array('missing', null, true),
+ array('bad_link', null, true)
+ );
+ }
+
+ /**
+ * @dataProvider aliasProvider
+ */
+ public function testAliasesCommands($key, $result, $exception)
+ {
+ try {
+ $command = $this->client->getCommand($key);
+ if (is_null($result)) {
+ $this->assertNull($command);
+ } else {
+ $this->assertInstanceof($result, $command);
+ }
+ } catch (\Exception $e) {
+ if (!$exception) {
+ $this->fail('Got exception when it was not expected');
+ }
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/CompositeFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/CompositeFactoryTest.php
new file mode 100644
index 0000000..b896dcf
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/CompositeFactoryTest.php
@@ -0,0 +1,124 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command;
+
+use Guzzle\Service\Command\Factory\CompositeFactory;
+
+/**
+ * @covers Guzzle\Service\Command\Factory\CompositeFactory
+ */
+class CompositeFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ private function getFactory($class = 'Guzzle\\Service\\Command\\Factory\\MapFactory')
+ {
+ return $mock = $this->getMockBuilder($class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ public function testIsIterable()
+ {
+ $factory = new CompositeFactory(array($this->getFactory(), $this->getFactory()));
+ $this->assertEquals(2, count($factory));
+ $this->assertEquals(2, count(iterator_to_array($factory->getIterator())));
+ }
+
+ public function testFindsFactories()
+ {
+ $f1 = $this->getFactory();
+ $f2 = $this->getFactory('Guzzle\\Service\\Command\\Factory\\CompositeFactory');
+ $factory = new CompositeFactory(array($f1, $f2));
+ $this->assertNull($factory->find('foo'));
+ $this->assertNull($factory->find($this->getFactory()));
+ $this->assertSame($f1, $factory->find('Guzzle\\Service\\Command\\Factory\\MapFactory'));
+ $this->assertSame($f2, $factory->find('Guzzle\\Service\\Command\\Factory\\CompositeFactory'));
+ $this->assertSame($f1, $factory->find($f1));
+ $this->assertSame($f2, $factory->find($f2));
+
+ $this->assertFalse($factory->has('foo'));
+ $this->assertTrue($factory->has('Guzzle\\Service\\Command\\Factory\\MapFactory'));
+ $this->assertTrue($factory->has('Guzzle\\Service\\Command\\Factory\\CompositeFactory'));
+ }
+
+ public function testCreatesCommands()
+ {
+ $factory = new CompositeFactory();
+ $this->assertNull($factory->factory('foo'));
+
+ $f1 = $this->getFactory();
+ $mockCommand1 = $this->getMockForAbstractClass('Guzzle\\Service\\Command\\AbstractCommand');
+
+ $f1->expects($this->once())
+ ->method('factory')
+ ->with($this->equalTo('foo'))
+ ->will($this->returnValue($mockCommand1));
+
+ $factory = new CompositeFactory(array($f1));
+ $this->assertSame($mockCommand1, $factory->factory('foo'));
+ }
+
+ public function testAllowsRemovalOfFactories()
+ {
+ $f1 = $this->getFactory();
+ $f2 = $this->getFactory();
+ $f3 = $this->getFactory('Guzzle\\Service\\Command\\Factory\\CompositeFactory');
+ $factories = array($f1, $f2, $f3);
+ $factory = new CompositeFactory($factories);
+
+ $factory->remove('foo');
+ $this->assertEquals($factories, $factory->getIterator()->getArrayCopy());
+
+ $factory->remove($f1);
+ $this->assertEquals(array($f2, $f3), $factory->getIterator()->getArrayCopy());
+
+ $factory->remove('Guzzle\\Service\\Command\\Factory\\MapFactory');
+ $this->assertEquals(array($f3), $factory->getIterator()->getArrayCopy());
+
+ $factory->remove('Guzzle\\Service\\Command\\Factory\\CompositeFactory');
+ $this->assertEquals(array(), $factory->getIterator()->getArrayCopy());
+
+ $factory->remove('foo');
+ $this->assertEquals(array(), $factory->getIterator()->getArrayCopy());
+ }
+
+ public function testAddsFactoriesBeforeAndAtEnd()
+ {
+ $f1 = $this->getFactory();
+ $f2 = $this->getFactory();
+ $f3 = $this->getFactory('Guzzle\\Service\\Command\\Factory\\CompositeFactory');
+ $f4 = $this->getFactory();
+
+ $factory = new CompositeFactory();
+
+ $factory->add($f1);
+ $this->assertEquals(array($f1), $factory->getIterator()->getArrayCopy());
+
+ $factory->add($f2);
+ $this->assertEquals(array($f1, $f2), $factory->getIterator()->getArrayCopy());
+
+ $factory->add($f3, $f2);
+ $this->assertEquals(array($f1, $f3, $f2), $factory->getIterator()->getArrayCopy());
+
+ $factory->add($f4, 'Guzzle\\Service\\Command\\Factory\\CompositeFactory');
+ $this->assertEquals(array($f1, $f4, $f3, $f2), $factory->getIterator()->getArrayCopy());
+ }
+
+ public function testProvidesDefaultChainForClients()
+ {
+ $client = $this->getMock('Guzzle\\Service\\Client');
+ $chain = CompositeFactory::getDefaultChain($client);
+ $a = $chain->getIterator()->getArrayCopy();
+ $this->assertEquals(1, count($a));
+ $this->assertInstanceOf('Guzzle\\Service\\Command\\Factory\\ConcreteClassFactory', $a[0]);
+
+ $description = $this->getMock('Guzzle\\Service\\Description\\ServiceDescription');
+ $client->expects($this->once())
+ ->method('getDescription')
+ ->will($this->returnValue($description));
+ $chain = CompositeFactory::getDefaultChain($client);
+ $a = $chain->getIterator()->getArrayCopy();
+ $this->assertEquals(2, count($a));
+ $this->assertInstanceOf('Guzzle\\Service\\Command\\Factory\\ServiceDescriptionFactory', $a[0]);
+ $this->assertInstanceOf('Guzzle\\Service\\Command\\Factory\\ConcreteClassFactory', $a[1]);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/ConcreteClassFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/ConcreteClassFactoryTest.php
new file mode 100644
index 0000000..7664718
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/ConcreteClassFactoryTest.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command;
+
+use Guzzle\Tests\Service\Mock\MockClient;
+use Guzzle\Service\Command\Factory\ConcreteClassFactory;
+
+/**
+ * @covers Guzzle\Service\Command\Factory\ConcreteClassFactory
+ */
+class ConcreteClassFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testProvider()
+ {
+ return array(
+ array('foo', null, 'Guzzle\\Tests\\Service\\Mock\\Command\\'),
+ array('mock_command', 'Guzzle\Tests\Service\Mock\Command\MockCommand', 'Guzzle\\Tests\\Service\\Mock\\Command\\'),
+ array('other_command', 'Guzzle\Tests\Service\Mock\Command\OtherCommand', 'Guzzle\\Tests\\Service\\Mock\\Command\\'),
+ array('sub.sub', 'Guzzle\Tests\Service\Mock\Command\Sub\Sub', 'Guzzle\\Tests\\Service\\Mock\\Command\\'),
+ array('sub.sub', null, 'Guzzle\\Foo\\'),
+ array('foo', null, null),
+ array('mock_command', 'Guzzle\Tests\Service\Mock\Command\MockCommand', null),
+ array('other_command', 'Guzzle\Tests\Service\Mock\Command\OtherCommand', null),
+ array('sub.sub', 'Guzzle\Tests\Service\Mock\Command\Sub\Sub', null)
+ );
+ }
+
+ /**
+ * @dataProvider testProvider
+ */
+ public function testCreatesConcreteCommands($key, $result, $prefix)
+ {
+ if (!$prefix) {
+ $client = new MockClient();
+ } else {
+ $client = new MockClient('', array(
+ 'command.prefix' => $prefix
+ ));
+ }
+
+ $factory = new ConcreteClassFactory($client);
+
+ if (is_null($result)) {
+ $this->assertNull($factory->factory($key));
+ } else {
+ $this->assertInstanceof($result, $factory->factory($key));
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/MapFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/MapFactoryTest.php
new file mode 100644
index 0000000..ee720d1
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/MapFactoryTest.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command;
+
+use Guzzle\Service\Command\Factory\MapFactory;
+
+/**
+ * @covers Guzzle\Service\Command\Factory\MapFactory
+ */
+class MapFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function mapProvider()
+ {
+ return array(
+ array('foo', null),
+ array('test', 'Guzzle\Tests\Service\Mock\Command\MockCommand'),
+ array('test1', 'Guzzle\Tests\Service\Mock\Command\OtherCommand')
+ );
+ }
+
+ /**
+ * @dataProvider mapProvider
+ */
+ public function testCreatesCommandsUsingMappings($key, $result)
+ {
+ $factory = new MapFactory(array(
+ 'test' => 'Guzzle\Tests\Service\Mock\Command\MockCommand',
+ 'test1' => 'Guzzle\Tests\Service\Mock\Command\OtherCommand'
+ ));
+
+ if (is_null($result)) {
+ $this->assertNull($factory->factory($key));
+ } else {
+ $this->assertInstanceof($result, $factory->factory($key));
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/ServiceDescriptionFactoryTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/ServiceDescriptionFactoryTest.php
new file mode 100644
index 0000000..3372634
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/Factory/ServiceDescriptionFactoryTest.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command;
+
+use Guzzle\Service\Description\ServiceDescription;
+use Guzzle\Service\Command\Factory\ServiceDescriptionFactory;
+use Guzzle\Inflection\Inflector;
+
+/**
+ * @covers Guzzle\Service\Command\Factory\ServiceDescriptionFactory
+ */
+class ServiceDescriptionFactoryTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testProvider()
+ {
+ return array(
+ array('foo', null),
+ array('jar_jar', 'Guzzle\Tests\Service\Mock\Command\MockCommand'),
+ array('binks', 'Guzzle\Tests\Service\Mock\Command\OtherCommand')
+ );
+ }
+
+ /**
+ * @dataProvider testProvider
+ */
+ public function testCreatesCommandsUsingServiceDescriptions($key, $result)
+ {
+ $d = $this->getDescription();
+
+ $factory = new ServiceDescriptionFactory($d);
+ $this->assertSame($d, $factory->getServiceDescription());
+
+ if (is_null($result)) {
+ $this->assertNull($factory->factory($key));
+ } else {
+ $this->assertInstanceof($result, $factory->factory($key));
+ }
+ }
+
+ public function testUsesUcFirstIfNoExactMatch()
+ {
+ $d = $this->getDescription();
+ $factory = new ServiceDescriptionFactory($d, new Inflector());
+ $this->assertInstanceof('Guzzle\Tests\Service\Mock\Command\OtherCommand', $factory->factory('Test'));
+ $this->assertInstanceof('Guzzle\Tests\Service\Mock\Command\OtherCommand', $factory->factory('test'));
+ }
+
+ public function testUsesInflectionIfNoExactMatch()
+ {
+ $d = $this->getDescription();
+ $factory = new ServiceDescriptionFactory($d, new Inflector());
+ $this->assertInstanceof('Guzzle\Tests\Service\Mock\Command\OtherCommand', $factory->factory('Binks'));
+ $this->assertInstanceof('Guzzle\Tests\Service\Mock\Command\OtherCommand', $factory->factory('binks'));
+ $this->assertInstanceof('Guzzle\Tests\Service\Mock\Command\MockCommand', $factory->factory('JarJar'));
+ $this->assertInstanceof('Guzzle\Tests\Service\Mock\Command\MockCommand', $factory->factory('jar_jar'));
+ }
+
+ protected function getDescription()
+ {
+ return ServiceDescription::factory(array(
+ 'operations' => array(
+ 'jar_jar' => array('class' => 'Guzzle\Tests\Service\Mock\Command\MockCommand'),
+ 'binks' => array('class' => 'Guzzle\Tests\Service\Mock\Command\OtherCommand'),
+ 'Test' => array('class' => 'Guzzle\Tests\Service\Mock\Command\OtherCommand')
+ )
+ ));
+ }
+}