diff --git a/.travis.yml b/.travis.yml index e61e3ef82..7fef74f22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,14 +23,22 @@ matrix: - php: 7.0 sudo: false env: SYMFONY_VERSION=3.0.* UNIT_TESTS=true SYMFONY_DEPRECATIONS_HELPER=weak - - php: 7.0 + - php: 7.1 sudo: required services: docker env: SYMFONY_VERSION=2.8.* FUNCTIONAL_TESTS=true - - php: 7.0 + - php: 7.1 sudo: required services: docker env: SYMFONY_VERSION=3.0.* FUNCTIONAL_TESTS=true + - php: 7.1 + sudo: required + services: docker + env: SYMFONY_VERSION=3.2.* FUNCTIONAL_TESTS=true + - php: 7.1 + sudo: required + services: docker + env: SYMFONY_VERSION=3.3.* FUNCTIONAL_TESTS=true cache: directories: diff --git a/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncListener.php b/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncListener.php index a606b8602..aa4884bca 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncListener.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncListener.php @@ -2,11 +2,14 @@ namespace Enqueue\Bundle\Tests\Functional\App; +use Symfony\Component\EventDispatcher\Event; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + class TestAsyncListener { public $calls = []; - public function onEvent() + public function onEvent(Event $event, $eventName, EventDispatcherInterface $dispatcher) { $this->calls[] = func_get_args(); } diff --git a/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncSubscriber.php b/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncSubscriber.php index 880519b51..2b45bed6e 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncSubscriber.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncSubscriber.php @@ -2,13 +2,15 @@ namespace Enqueue\Bundle\Tests\Functional\App; +use Symfony\Component\EventDispatcher\Event; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class TestAsyncSubscriber implements EventSubscriberInterface { public $calls = []; - public function onEvent() + public function onEvent(Event $event, $eventName, EventDispatcherInterface $dispatcher) { $this->calls[] = func_get_args(); } diff --git a/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php b/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php index a2c65492c..38fca16f7 100644 --- a/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php @@ -8,6 +8,7 @@ use Enqueue\Psr\PsrContext; use Enqueue\Psr\PsrMessage; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\HttpKernel\Kernel; /** * @group functional @@ -49,6 +50,15 @@ public function provideEnqueueConfigs() ], ]]; + // Symfony 2.x does not such env syntax + if (version_compare(Kernel::VERSION, '3.2', '>=')) { + yield 'default_dsn_as_env' => [[ + 'transport' => [ + 'default' => '%env(AMQP_DSN)%', + ], + ]]; + } + yield 'default_dbal_as_dsn' => [[ 'transport' => [ 'default' => getenv('DOCTINE_DSN'), diff --git a/pkg/enqueue/Symfony/DefaultTransportFactory.php b/pkg/enqueue/Symfony/DefaultTransportFactory.php index dcc54cf8b..6e264c4e2 100644 --- a/pkg/enqueue/Symfony/DefaultTransportFactory.php +++ b/pkg/enqueue/Symfony/DefaultTransportFactory.php @@ -50,7 +50,7 @@ public function addConfiguration(ArrayNodeDefinition $builder) } if (is_string($v)) { - return false !== strpos($v, '://') ? + return false !== strpos($v, '://') || false !== strpos($v, 'env_') ? ['dsn' => $v] : ['alias' => $v]; } @@ -69,7 +69,9 @@ public function createConnectionFactory(ContainerBuilder $container, array $conf if (isset($config['alias'])) { $aliasId = sprintf('enqueue.transport.%s.connection_factory', $config['alias']); } else { - $aliasId = $this->findFactory($config['dsn'])->createConnectionFactory($container, $config); + $dsn = $this->resolveDSN($container, $config['dsn']); + + $aliasId = $this->findFactory($dsn)->createConnectionFactory($container, $config); } $factoryId = sprintf('enqueue.transport.%s.connection_factory', $this->getName()); @@ -88,7 +90,9 @@ public function createContext(ContainerBuilder $container, array $config) if (isset($config['alias'])) { $aliasId = sprintf('enqueue.transport.%s.context', $config['alias']); } else { - $aliasId = $this->findFactory($config['dsn'])->createContext($container, $config); + $dsn = $this->resolveDSN($container, $config['dsn']); + + $aliasId = $this->findFactory($dsn)->createContext($container, $config); } $contextId = sprintf('enqueue.transport.%s.context', $this->getName()); @@ -107,7 +111,9 @@ public function createDriver(ContainerBuilder $container, array $config) if (isset($config['alias'])) { $aliasId = sprintf('enqueue.client.%s.driver', $config['alias']); } else { - $aliasId = $this->findFactory($config['dsn'])->createDriver($container, $config); + $dsn = $this->resolveDSN($container, $config['dsn']); + + $aliasId = $this->findFactory($dsn)->createDriver($container, $config); } $driverId = sprintf('enqueue.client.%s.driver', $this->getName()); @@ -126,6 +132,33 @@ public function getName() return $this->name; } + /** + * This is a quick fix to the exception "Incompatible use of dynamic environment variables "ENQUEUE_DSN" found in parameters." + * TODO: We'll have to come up with a better solution. + * + * @param ContainerBuilder $container + * @param $dsn + * + * @return array|false|string + */ + private function resolveDSN(ContainerBuilder $container, $dsn) + { + if (method_exists($container, 'resolveEnvPlaceholders')) { + $dsn = $container->resolveEnvPlaceholders($dsn); + + $matches = []; + if (preg_match('/%env\((.*?)\)/', $dsn, $matches)) { + if (false === $realDsn = getenv($matches[1])) { + throw new \LogicException(sprintf('The env "%s" var is not defined', $matches[1])); + } + + return $realDsn; + } + } + + return $dsn; + } + /** * @param string * @param mixed $dsn