Open Monograph Press  3.3.0
AliasFactoryTest.php
1 <?php
2 
4 
9 
14 {
15  private $factory;
16  private $client;
17 
18  public function setup()
19  {
20  $this->client = new Client();
21 
22  $map = new MapFactory(array(
23  'test' => 'Guzzle\Tests\Service\Mock\Command\MockCommand',
24  'test1' => 'Guzzle\Tests\Service\Mock\Command\OtherCommand'
25  ));
26 
27  $this->factory = new AliasFactory($this->client, array(
28  'foo' => 'test',
29  'bar' => 'sub',
30  'sub' => 'test1',
31  'krull' => 'test3',
32  'krull_2' => 'krull',
33  'sub_2' => 'bar',
34  'bad_link' => 'jarjar'
35  ));
36 
37  $map2 = new MapFactory(array(
38  'test3' => 'Guzzle\Tests\Service\Mock\Command\Sub\Sub'
39  ));
40 
41  $this->client->setCommandFactory(new CompositeFactory(array($map, $this->factory, $map2)));
42  }
43 
44  public function aliasProvider()
45  {
46  return array(
47  array('foo', 'Guzzle\Tests\Service\Mock\Command\MockCommand', false),
48  array('bar', 'Guzzle\Tests\Service\Mock\Command\OtherCommand', false),
49  array('sub', 'Guzzle\Tests\Service\Mock\Command\OtherCommand', false),
50  array('sub_2', 'Guzzle\Tests\Service\Mock\Command\OtherCommand', false),
51  array('krull', 'Guzzle\Tests\Service\Mock\Command\Sub\Sub', false),
52  array('krull_2', 'Guzzle\Tests\Service\Mock\Command\Sub\Sub', false),
53  array('missing', null, true),
54  array('bad_link', null, true)
55  );
56  }
57 
61  public function testAliasesCommands($key, $result, $exception)
62  {
63  try {
64  $command = $this->client->getCommand($key);
65  if (is_null($result)) {
66  $this->assertNull($command);
67  } else {
68  $this->assertInstanceof($result, $command);
69  }
70  } catch (\Exception $e) {
71  if (!$exception) {
72  $this->fail('Got exception when it was not expected');
73  }
74  }
75  }
76 }
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Service\Client
Definition: paymethod/paypal/lib/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php:25
Guzzle\Service\Command\Factory\AliasFactory
Definition: AliasFactory.php:11
Guzzle\Service\Command\Factory\MapFactory
Definition: MapFactory.php:8
Guzzle\Tests\Service\Command\AliasFactoryTest
Definition: AliasFactoryTest.php:13
Guzzle\Tests\Service\Command\AliasFactoryTest\testAliasesCommands
testAliasesCommands($key, $result, $exception)
Definition: AliasFactoryTest.php:61
Guzzle\Tests\Service\Command\AliasFactoryTest\setup
setup()
Definition: AliasFactoryTest.php:18
Guzzle\Service\Command\Factory\CompositeFactory
Definition: CompositeFactory.php:11
Guzzle\Tests\Service\Command
Definition: AbstractCommandTest.php:3
Guzzle\Tests\Service\Command\AliasFactoryTest\aliasProvider
aliasProvider()
Definition: AliasFactoryTest.php:44