Skip to content

Commit

Permalink
Use method_exists to avoid deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteWunsch committed Jun 8, 2015
1 parent 866b29c commit d4e4033
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions DependencyInjection/BernardBernardExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ protected function registerFlatFileConfiguration($config, $container)
protected function registerSqsConfiguration(array $config, ContainerBuilder $container)
{
$sqsClientDefinition = new Definition();
if (Kernel::MAJOR_VERSION == 2 && Kernel::MINOR_VERSION < 6) {
if ($this->definitionClassDeprecatesSetFactoryClassAndSetFactoryMethod()) {
$sqsClientDefinition->setFactory('Aws\Sqs\SqsClient::factory');
} else {
$sqsClientDefinition->setFactoryClass('Aws\Sqs\SqsClient')
->setFactoryMethod('factory');
} else {
$sqsClientDefinition->setFactory('Aws\Sqs\SqsClient::factory');
}
$sqsClientDefinition->setArguments(
array(
Expand Down Expand Up @@ -119,4 +119,12 @@ protected function registerPhpRedisConfiguration($config, $container)
{
$container->getDefinition('bernard.driver.phpredis')->replaceArgument(0, new Reference($config['phpredis_service']));
}

/**
* @return bool
*/
private function definitionClassDeprecatesSetFactoryClassAndSetFactoryMethod()
{
return method_exists(new Definition(), 'setFactory');
}
}
14 changes: 11 additions & 3 deletions Tests/DependencyInjection/BernardBernardExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ public function testSqsDriverCanBeBuildFromConfiguration()

/** @var Definition $resultingSqsClientArgument */
$resultingSqsClientArgument = $driverDefinition->getArgument(0);
if (Kernel::MAJOR_VERSION == 2 && Kernel::MINOR_VERSION < 6) {
if ($this->definitionClassDeprecatesSetFactoryClassAndSetFactoryMethod()) {
$this->assertSame(array('Aws\Sqs\SqsClient', 'factory'), $resultingSqsClientArgument->getFactory());
} else {
$this->assertSame('Aws\Sqs\SqsClient', $resultingSqsClientArgument->getFactoryClass());
$this->assertSame('factory', $resultingSqsClientArgument->getFactoryMethod());
} else {
$this->assertSame(array('Aws\Sqs\SqsClient', 'factory'), $resultingSqsClientArgument->getFactory());
}

$sqsClientFactoryArguments = $resultingSqsClientArgument->getArguments();
Expand All @@ -155,4 +155,12 @@ public function testSqsDriverCanBeBuildFromConfiguration()
$resultingPrefetchArgument = $driverDefinition->getArgument(2);
$this->assertEquals($configuredPrefetch, $resultingPrefetchArgument);
}

/**
* @return bool
*/
private function definitionClassDeprecatesSetFactoryClassAndSetFactoryMethod()
{
return method_exists(new Definition(), 'setFactory');
}
}

0 comments on commit d4e4033

Please sign in to comment.