JeffreyWay / Laravel-Test-Helpers

Easier testing in Laravel.
https://packagist.org/packages/way/laravel-test-helpers
217 stars 40 forks source link

Factory::create() weird behaviour #61

Open toonevdb opened 10 years ago

toonevdb commented 10 years ago

What I encounter is that Factory::product() does an sql query for categories when I use a Factory::create() call.

    // create dummy data in db
    //$user = Factory::create('User');
    $user = Factory::user();
    $user->company_id = null;
    $user->save();

    //$company = Factory::create('Company');
    $company = Factory::company();
    $company->save();

    $category = Factory::category();
    $category->parent_id = null;
    $category->save();

    $product = Factory::product();
    dd($product);
    $product->category_id = $category->id;
    $product->company_id = $company->id;
    //$product->save();

If I uncomment $company = Factory::create('Company') or $user = Factory::create('User') an error is thrown on the $product = Factory::product() line because it tries to insert data in the categories table.. I do see that the last call with Factory is Factory::category() before calling Factory::product() but it should not do any queries and certainly not on the categories table.

The code above works because all Factory::create() calls are worked around. I can create my test and make it work but it's probably not expected behaviour.