Correct way of getting dependencies when using PHPUnit

Notice: This thread is very old.
Member | 117

My current code includes:

	public function setUp()
		$this->container = $GLOBALS['container'];
		$this->db = $this->container->getByType('Dibi\Connection');

I have seperate bootstrap.php/config for tests, as well as seperate temp directory.
While this works I'm thinking is there some better way?

Tomáš Votruba
Moderator | 1110

Hi, your setup has good logic.

Instead of using $GLOBALS I recommend using encapsulation in ContainerFactory.

Use like this

protected function setUp()
	$container = (new ContainerFactory)->create();
	$this->database = $container->getByType(Dibi\Connection::class);