Functional testing works without a custom index-test.php file?


(Serban Cristian) #1

I’m trying to add testing to an existing app we’re working on, and even though our app does not have an index-test.php file, it seems functional tests are working.
This is a bit weird since our app structure is a bit different, something like:


So the /backend folder contains only the index.php file which is the entry point which in turn loads the app from /apps/backend/
Now, functional tests work just fine for the backend app, any idea how is this possible ?


(Alexander Makarov) #2

Yes, it does. Let’s take a look at index-test.php. Three significant lines are:

// Set debug mode on. Good to get errors when you test, right? 
// But never do it in production!
defined('YII_DEBUG') or define('YII_DEBUG', true); 
// This disables CAPTCHAs, CSRF token etc.
// to make testing easier. You can live w/o it but it won't be easy.
defined('YII_ENV') or define('YII_ENV', 'test'); 

// ...

// There you set different environment.
// You don't want to damage your real database when testing, right?
$config = require __DIR__ . '/../config/test.php';

So tests will run just fine. They could fail and consequences could be very bad but it will run.


(Serban Cristian) #3

I have no index-test.php file and yet it works, this is my question, how does the app know to use the regular index.php file when no index-test.php is present, is there a fallback on that file ?


(Alexander Makarov) #4

index-test.php is used for acceptance tests only. So either you don’t have any or you’ve configured acceptance.suite.yml to use index.php.