laracasts / TestDummy

Easy factories for PHP integration testing.
https://laracasts.com/lessons/whats-new-in-testdummy
MIT License
455 stars 80 forks source link

Could not locate a factory #93

Open prady00 opened 9 years ago

prady00 commented 9 years ago

php artisan db:seed --class=TeamsTableSeeder

[Laracasts\TestDummy\TestDummyException] Could not locate a factory with the name: App\Team

I have done composer dump-autoload and clear-cache

All files are present in their appropriate namespace.

What could be the possible reason for this error?

JeffreyWay commented 9 years ago

Let me see your factories file.

Luckyfox commented 9 years ago

Hi Jeff,

I get the same issue as above. But when in iterm2 all works fine apart from 5 of these messages each time..

Warning: include_once(): Failed opening '/Users/nigel/projects/work/laravel/tests/functional' for inclusion (include_path='/Users/nigel/projects/work/laravel/vendor/phpunit/php-text-template:/Users/nigel/projects/work/laravel/vendor/phpunit/php-timer:/Users/nigel/projects/work/laravel/vendor/phpunit/php-file-iterator:.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/lib/php/PHPUnit/Util/Fileloader.php on line 95

Hope that might shed some light ont he issue..

ruuter commented 9 years ago

I'm getting same error, but only in remote server. In my local installation all works fine without any problems. Dumping composer autoload and clearing cache did not help.

$ php artisan db:seed -vvv --class=WishTableSeeder

[Laracasts\TestDummy\TestDummyException] Could not locate a factory with the name: App\Models\Wish

Exception trace:

() at ...vendor/laracasts/testdummy/src/Builder.php:196 Laracasts\TestDummy\Builder->getFixture() at ...vendor/laracasts/testdummy/src/Builder.php:155 Laracasts\TestDummy\Builder->getAttributes() at ...vendor/laracasts/testdummy/src/Builder.php:96 Laracasts\TestDummy\Builder->build() at ...vendor/laracasts/testdummy/src/Builder.php:134 Laracasts\TestDummy\Builder->persist() at ...vendor/laracasts/testdummy/src/Builder.php:115 Laracasts\TestDummy\Builder->create() at ...database/seeds/WishTableSeeder.php:11

antoniputra commented 9 years ago

I have the same issue. in my case, because the name of defineAs and factory method is different. this happen for me after I change the namespaces of Model and I forgot to update the namespaces in factory() method

// ModelFactory.php
$factory->defineAs(App\Models\User::class, 'superadmin', function ($faker) use ($factory) {
    $user = $factory->raw(App\Models\User::class);

    return array_merge($user, config('site_default.users.superadmin'));
});
// UserSeeder.php file
factory('App\User', 'superadmin')->create();   // <---- I forget change this. should : App\Models\User
$this->command->comment(PHP_EOL .'User superadmin was generated...');
ruuter commented 9 years ago

@antoniputra Unfortunately that is not a case for me, since everything is working in my local installation. This happens only in remote server.

antoniputra commented 9 years ago

oh, are you sure with your remote server environment set up ?

you are using external package, I don't familiar with this Exception. [Laracasts\TestDummy\TestDummyException]

can you show me your ModelFactories and WishTableSeeder code ?

ruuter commented 9 years ago

@antoniputra I am using Laracast/Testdummy, the very same package in which git repo we talk right now. Yes, I'm positive this only happens in remote server. Not sure what can cause this. I'm trying to track this down right now. One interesting thing I did not notice before is the fact that my whole factories.php file gets printed to stdout.

ruuter commented 9 years ago

I found it. It was PHP environment problem. I have shortcode php start tag in factories.php and even though I do have short_open_tag = On in remote php, I did not have it On in php cli. So it was PHP environment problem.

antoniputra commented 9 years ago

glad hear it. :D