Skip to content

Commit

Permalink
Merge pull request #28 from jeskew/schodemeiss-patch-1
Browse files Browse the repository at this point in the history
Alias services with class name
  • Loading branch information
jeskew authored Jul 12, 2017
2 parents 1d10837 + c089776 commit 3c083b8
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: php
dist: trusty

php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

env:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"symfony/http-kernel": "~2.3|~3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.7",
"phpunit/phpunit": "^4.8.35|^5.4.0|^6.0.0",
"symfony/framework-bundle": "~2.3|~3.0",
"symfony/yaml": "~2.3|~3.0"
},
Expand Down
9 changes: 5 additions & 4 deletions src/DependencyInjection/AwsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public function load(array $configs, ContainerBuilder $container)
]]);

foreach (array_column(Aws\manifest(), 'namespace') as $awsService) {
$container->setDefinition(
'aws.' . strtolower($awsService),
$this->createServiceDefinition($awsService)
);
$serviceName = 'aws.' . strtolower($awsService);
$serviceDefinition = $this->createServiceDefinition($awsService);
$container->setDefinition($serviceName, $serviceDefinition);

$container->setAlias($serviceDefinition->getClass(), $serviceName);
}
}

Expand Down
29 changes: 24 additions & 5 deletions tests/DependencyInjection/AwsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

use AppKernel;
use Aws\AwsClient;
use Aws\Sdk;
use ReflectionClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;

class AwsExtensionTest extends \PHPUnit_Framework_TestCase
class AwsExtensionTest extends TestCase
{
/**
* @var ContainerInterface
Expand Down Expand Up @@ -81,7 +80,9 @@ public function extension_should_escape_strings_that_begin_with_at_sign()
'key' => '@@key',
'secret' => '@@secret'
]];
$container = $this->getMock(ContainerBuilder::class, ['getDefinition', 'replaceArgument']);
$container = $this->getMockBuilder(ContainerBuilder::class)
->setMethods(['getDefinition', 'replaceArgument'])
->getMock();
$container->expects($this->once())
->method('getDefinition')
->with('aws_sdk')
Expand All @@ -107,7 +108,9 @@ public function extension_should_expand_service_references()
{
$extension = new AwsExtension;
$config = ['credentials' => '@aws_sdk'];
$container = $this->getMock(ContainerBuilder::class, ['getDefinition', 'replaceArgument']);
$container = $this->getMockBuilder(ContainerBuilder::class)
->setMethods(['getDefinition', 'replaceArgument'])
->getMock();
$container->expects($this->once())
->method('getDefinition')
->with('aws_sdk')
Expand Down Expand Up @@ -157,4 +160,20 @@ function (array $service) use ($config) {
$this->serviceProvider()
);
}

/**
* @test
*
* @dataProvider serviceProvider
*/
public function extension_should_load_services_by_class_name(
$webServiceName,
$containerServiceName,
$clientClassName
) {
$this->assertInstanceOf(
$clientClassName,
$this->container->get($clientClassName)
);
}
}
4 changes: 2 additions & 2 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace Aws\Symfony\DependencyInjection;


use AppKernel;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;

class ConfigurationTest extends \PHPUnit_Framework_TestCase
class ConfigurationTest extends TestCase
{
public function setUp()
{
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Aws\DynamoDb\DynamoDbClient;
use Symfony\Component\DependencyInjection\Reference;

$container->loadFromExtension('framework', [
Expand Down Expand Up @@ -31,3 +32,10 @@
->register('a_service', 'Aws\\Credentials\\Credentials')
->addArgument('a-different-fake-key')
->addArgument('a-different-fake-secret');

$container
->register(DynamoDbClient::class, DynamoDbClient::class)
->addArgument([
'region' => 'eu-central-1',
'version' => '2012-08-10',
]);
11 changes: 11 additions & 0 deletions tests/fixtures/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@
<aws:Sqs credentials="@a_service"/>
</aws:config>

<parameters>
<parameter key="dynamodb_client_config" type="collection">
<parameter key="region">eu-central-1</parameter>
<parameter key="version">2012-08-10</parameter>
</parameter>
</parameters>

<services>
<service id="a_service" class="Aws\Credentials\Credentials">
<argument>a-different-fake-key</argument>
<argument>a-different-fake-secret</argument>
</service>

<service id="Aws\DynamoDb\DynamoDbClient" class="Aws\DynamoDb\DynamoDbClient">
<argument>%dynamodb_client_config%</argument>
</service>
</services>
</container>
6 changes: 6 additions & 0 deletions tests/fixtures/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ aws:
endpoint: https://search-with-some-subdomain.us-east-1.cloudsearch.amazonaws.com

services:
'Aws\DynamoDb\DynamoDbClient':
class: Aws\DynamoDb\DynamoDbClient
arguments:
-
region: eu-central-1
version: '2012-08-10'
a_service:
class: Aws\Credentials\Credentials
arguments:
Expand Down

0 comments on commit 3c083b8

Please sign in to comment.