Respect/Config — Issue #14: Lazy Load and dependency problems
Author: augustohp
Created: 2012-02-06 20:41:37+00:00
State: open

When some configuration depends on another instance of the same configuration file, things don't go as one would expect:

# The configuration

[pdo Pdo]
dsn = [dsn]
username = [db_user]
password = [db_passwd]

[connectionParams]
pdo = [pdo]
dbname = [db_name]
user = [db_user]
password = [db_passwd]
host = [db_host]
driver = [db_driver]

[config Doctrine\DBAL\Configuration]

[event Doctrine\Common\EventManager]

[cache Doctrine\Common\Cache\ArrayCache]

[config Doctrine\ORM\Tools\Setup]
createAnnotationMetadataConfiguration[] = [[orm_entity_dir], [orm_proxy_autogenerate]]

[dbal Doctrine\DBAL\DriverManager]
getConnection[] = [[connectionParams], [config], [event]]

[entityManager Doctrine\ORM\EntityManager]
create[] = [[dbal], [config], [event]]

# The test code

Now, suppose I want to test the given code... it is quite normal to inject my *pdo* instance like that

class DoctrineTest extends \PHPUnit_Framework_TestCase
{
protected $container;

public function setUp()
{
$this->container = new Container('config.ini');
$pdo = new PDO('sqlite::memmory:');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->container->pdo = $pdo;
}
}

# The problem

The $this->container->pdo is actually the instance I gave, but everything that uses it inside the config is binded to the old PDO instance (the one that the Instantiator will create).