|
4 | 4 |
|
5 | 5 | use Bernard\BernardBundle\DependencyInjection\BernardBernardExtension; |
6 | 6 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 7 | +use Symfony\Component\DependencyInjection\Definition; |
| 8 | +use Symfony\Component\HttpKernel\Kernel; |
7 | 9 |
|
8 | 10 | class BernardBernardExtensionTest extends \PHPUnit_Framework_TestCase |
9 | 11 | { |
| 12 | + /** |
| 13 | + * @var BernardBernardExtension |
| 14 | + */ |
| 15 | + protected $extension; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var ContainerBuilder |
| 19 | + */ |
| 20 | + protected $container; |
| 21 | + |
10 | 22 | public function setUp() |
11 | 23 | { |
12 | 24 | $this->extension = new BernardBernardExtension; |
@@ -49,7 +61,7 @@ public function testMiddlewaresHaveMiddlewareTag() |
49 | 61 | $this->assertEquals(array(array('type' => 'consumer')), $definition->getTag('bernard.middleware')); |
50 | 62 | } |
51 | 63 |
|
52 | | - public function testDoctrinEventListenerIsAdded() |
| 64 | + public function testDoctrineEventListenerIsAdded() |
53 | 65 | { |
54 | 66 | $config = array_filter(array('driver' => 'doctrine', 'options' => array('connection' => 'bernard'))); |
55 | 67 |
|
@@ -97,4 +109,58 @@ public function testDriverIsAliased() |
97 | 109 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Alias', $alias); |
98 | 110 | $this->assertEquals('bernard.driver.doctrine', (string) $alias); |
99 | 111 | } |
| 112 | + |
| 113 | + public function testSqsDriverCanBeBuildFromConfiguration() |
| 114 | + { |
| 115 | + $configuredQueueMap = array('name1' => 'url1', 'name2' => 'url2'); |
| 116 | + $configuredPrefetch = 5; |
| 117 | + $configuredRegion = 'test-region'; |
| 118 | + $configuredKey = 'test-key'; |
| 119 | + $configuredSecret = 'test-secret'; |
| 120 | + |
| 121 | + $config = array( |
| 122 | + 'driver' => 'sqs', |
| 123 | + 'options' => array( |
| 124 | + 'queue_map' => $configuredQueueMap, |
| 125 | + 'prefetch' => $configuredPrefetch, |
| 126 | + ), |
| 127 | + 'sqs' => array( |
| 128 | + 'region' => $configuredRegion, |
| 129 | + 'key' => $configuredKey, |
| 130 | + 'secret' => $configuredSecret, |
| 131 | + ), |
| 132 | + ); |
| 133 | + |
| 134 | + $this->extension->load(array($config), $this->container); |
| 135 | + $driverDefinition = $this->container->getDefinition('bernard.driver.sqs'); |
| 136 | + |
| 137 | + /** @var Definition $resultingSqsClientArgument */ |
| 138 | + $resultingSqsClientArgument = $driverDefinition->getArgument(0); |
| 139 | + if ($this->definitionClassDeprecatesSetFactoryClassAndSetFactoryMethod()) { |
| 140 | + $this->assertSame(array('Aws\Sqs\SqsClient', 'factory'), $resultingSqsClientArgument->getFactory()); |
| 141 | + } else { |
| 142 | + $this->assertSame('Aws\Sqs\SqsClient', $resultingSqsClientArgument->getFactoryClass()); |
| 143 | + $this->assertSame('factory', $resultingSqsClientArgument->getFactoryMethod()); |
| 144 | + } |
| 145 | + |
| 146 | + $sqsClientFactoryArguments = $resultingSqsClientArgument->getArguments(); |
| 147 | + $sqsClientFactoryConfiguration = $sqsClientFactoryArguments[0]; |
| 148 | + $this->assertSame($configuredRegion, $sqsClientFactoryConfiguration['region']); |
| 149 | + $this->assertSame($configuredKey, $sqsClientFactoryConfiguration['key']); |
| 150 | + $this->assertSame($configuredSecret, $sqsClientFactoryConfiguration['secret']); |
| 151 | + |
| 152 | + $resultingQueueMapArgument = $driverDefinition->getArgument(1); |
| 153 | + $this->assertEquals($configuredQueueMap, $resultingQueueMapArgument); |
| 154 | + |
| 155 | + $resultingPrefetchArgument = $driverDefinition->getArgument(2); |
| 156 | + $this->assertEquals($configuredPrefetch, $resultingPrefetchArgument); |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * @return bool |
| 161 | + */ |
| 162 | + private function definitionClassDeprecatesSetFactoryClassAndSetFactoryMethod() |
| 163 | + { |
| 164 | + return method_exists(new Definition(), 'setFactory'); |
| 165 | + } |
100 | 166 | } |
0 commit comments