Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing env variables for port config #532

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ services: mongodb

install:
- composer self-update
- pecl install memcached
- pecl install -f mongodb-${DRIVER_VERSION}
- composer update ${COMPOSER_FLAGS}

Expand Down
31 changes: 29 additions & 2 deletions Tests/DependencyInjection/AbstractMongoDBExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Security\Core\User\UserInterface;
use Vendor\Filter\BasicFilter;
use Vendor\Filter\ComplexFilter;
use Vendor\Filter\DisabledFilter;
use function array_map;
use function array_search;
use function extension_loaded;
use function reset;
use function sprintf;

abstract class AbstractMongoDBExtensionTest extends TestCase
{
Expand Down Expand Up @@ -175,6 +177,31 @@ public function testLoadSimpleSingleConnection()
$this->assertEquals('doctrine_mongodb.odm.default_connection.event_manager', (string) $container->getAlias('doctrine_mongodb.odm.event_manager'));
}

public function testLoadCacheService()
{
if (! extension_loaded('memcached')) {
$this->markTestSkipped(sprintf('The "%s" test requires the memcached extension', __METHOD__));
}

$container = $this->getContainer();
$loader = new DoctrineMongoDBExtension();
$container->registerExtension($loader);

$this->loadFromFile($container, 'mongodb_service_simple_single_connection');

$container->compile();

// Test retrieving the document manager
/** @var DocumentManager $documentManager */
$documentManager = $container->get('doctrine_mongodb.odm.default_document_manager');

/** @var MemcachedCache $cacheImplementation */
$cacheImplementation = $documentManager->getConfiguration()->getMetadataCacheImpl();
self::assertInstanceOf(MemcachedCache::class, $cacheImplementation);

$cacheImplementation->getMemcached()->getServerList();
}

public function testLoadSingleConnection()
{
$container = $this->getContainer();
Expand Down Expand Up @@ -498,7 +525,7 @@ protected function getContainer($bundle = 'XmlBundle')
{
require_once __DIR__ . '/Fixtures/Bundles/' . $bundle . '/' . $bundle . '.php';

return new ContainerBuilder(new ParameterBag([
return new ContainerBuilder(new EnvPlaceholderParameterBag([
'kernel.bundles' => [$bundle => 'DoctrineMongoDBBundle\\Tests\\DependencyInjection\\Fixtures\\Bundles\\' . $bundle . '\\' . $bundle],
'kernel.cache_dir' => __DIR__,
'kernel.compiled_classes' => [],
Expand Down
21 changes: 21 additions & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,27 @@ public function testNullReplicaSetValue()
$this->assertFalse(array_key_exists('replicaSet', $processedConfig['connections']['conn1']['options']));
}

public function testPortFromEnvVariable()
{
$config = [
'document_managers' => [
'dm1' => [
'metadata_cache_driver' => [
'type' => 'memcached',
'class' => 'fooClass',
'host' => 'host_val',
'port' => '%env(int:MEMCACHE_PORT)%',
'instance_class' => 'instance_val',
],
],
],
];

$processor = new Processor();
$configuration = new Configuration(false);
$processedConfig = $processor->processConfiguration($configuration, [$config]);
}

/**
* @dataProvider provideExceptionConfiguration
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ doctrine_mongodb:
type: memcached
class: Doctrine\Common\Cache\MemcachedCache
host: localhost
port: 11211
instance_class: Memcached
port: '%env(int:MEMCACHE_PORT)%'
instance_class: Doctrine\Bundle\MongoDBBundle\Tests\MemcachedStub
16 changes: 16 additions & 0 deletions Tests/MemcachedStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types = 1);

namespace Doctrine\Bundle\MongoDBBundle\Tests;

use function func_get_args;
use Memcached;

final class MemcachedStub extends Memcached
{
public function addServer($host, $port, $weight = 0)
{
parent::addServer(...func_get_args());
}
}