Wrong appDir constant in config while testing

Notice: This thread is very old.
meridius
Member | 34
+
0
-

When I run the project in browser the %appDir% constant is set to myproj/app, but when I run the Tester (with myproj/tests/bootstrap.php and config.neon as shown below) I get exception about myproj/tests/entities dir given. Which suggests that the %appDir% is set to myproj/tests.

Why is ->addDirectory(__DIR__ . '/../app') not working?
And how do I fix that other than creating separate config.tests.neon?

tests/bootstrap.php:

<?php

require __DIR__ . '/../vendor/autoload.php';

if (!class_exists('Tester\Assert')) {
	echo "Install Nette Tester using `composer update --dev`\n";
	exit(1);
}

Tester\Environment::setup();

$configurator = new Nette\Configurator;
$configurator->setDebugMode(FALSE);
$configurator->setTempDirectory(__DIR__ . '/../temp');
$configurator->createRobotLoader()
	->addDirectory(__DIR__ . '/../app')
	->register();

$configurator->addConfig(__DIR__ . '/../app/config/config.neon', "common");
$configurator->addConfig(__DIR__ . '/../app/config/config.local.neon');
return $configurator->createContainer();

app/config/config.neon

common:
	# some config here

	doctrine < %databaseInfo%:
		metadata:
			App\Entities: '%appDir%/entities'	# namespace and directory for ORM entities

	extensions:
		console: Kdyby\Console\DI\ConsoleExtension
		events: Kdyby\Events\DI\EventsExtension
		annotations: Kdyby\Annotations\DI\AnnotationsExtension
		doctrine: Kdyby\Doctrine\DI\OrmExtension
greeny
Member | 405
+
0
-

Since you have already hardcoded the app directory into code, i suggest you to use %wwwDir%/app/entities. It should work, but I don't work with Doctrine much, so please test it by yourself.

David Matějka
Moderator | 6445
+
+8
-

You have to set appDir manually:

$configurator->addParameters(array(
	'appDir' => __DIR__ . '/../app',
));
meridius
Member | 34
+
0
-

Cool! This is exactly what I was looking for.
Thank you