laracasts/TestDummy

[PHPUnit_Framework_ExceptionWrapper] The path provided for the factories directory, tests/factories, does not exist.

Closed this issue · 3 comments

I've created my factories.php file in app/tests/factories directory and still get the error. After a little digging I found that I can provide the path in Factory::$factoriesPath. This isnt very convenient considering that I need to set this for each test. I think modifying the FactoriesLoader::assertThatFactoriesDirectoryExists() should probably check inside app_path() instead of is_dir. At the very least provide a config file where we can specify factories location as well as package namespace for classes.

I am on Laravel 4.1 using Codeception PHP Testing Framework v2.0.0 Powered by PHPUnit 4.5.0.

The easiest solution is to create a BaseTestCase to extend from that sets the Factory::$factoriesPath in the _before method. Using app_path() wouldn't be very friendly for non-Laravel projects.

Maybe something like (not tested):

abstract class CodeceptTestCase extends \Codeception\TestCase\Test
{
    public function _before()
    {
        DB::beginTransaction();
        Artisan::call('migrate');
        Factory::$factoriesPath = app_path('tests/factories');
    }

    public function _after()
    {
        DB::rollBack();
        m::close();
    }
}

You shoud create the /tests/factories outside the app directory. It all should work fine.

@bbrothers Why didnt I think of that. Thanks thats a good solution for my case.