0

I'm coding a functional test that calls a route whose controller has to read on local file system a specific file. The code in my controller is:

$document_root = $_SERVER['DOCUMENT_ROOT'];
$patch = $document_root . "/../app/config/tabelle/config.json";
if (file_exists($patch)) { ... }else{ die; }

The problem is that when I run the controller visiting by myself the URL and loading the page on my browser, everything works properly. But when I run my functional test, that is supposed to load exactly the same URL I visited manually by browser, the test fails because controller cannot find the file. Maybe I have to configure phpunit in a way that tells him which root folder he has to consider? Thanks

user3255068
  • 53
  • 1
  • 6

1 Answers1

0

I solved adopting the Symfony2 native way to get the ROOT_DIR. Rather than using $_SERVER['DOCUMENT_ROOT'] I used: $document_root = $this->container->getParameter('kernel.root_dir');

user3255068
  • 53
  • 1
  • 6