laravel-shift / factory-generator

MIT License
41 stars 20 forks source link

[Bug] Creating a factory for a single model fails to find Model if it is not stored in app/ #5

Closed chriischambers closed 3 years ago

chriischambers commented 3 years ago

If I try to create a factory for a single model using any of the following commands -

php artisan generate:factory Car php artisan generate:factory Car --path=app/Models

then I get the error below. It would appear that this single model option only works for models present is the app/ directory.

Class App\Car does not exist
jasonmccreary commented 3 years ago

Thanks for reporting this. Myself of @Naoray will take a look at this in the next few days. However, we encourage you to take a stab at the fix by opening a PR. After all, it's Hacktober.

chriischambers commented 3 years ago

I did look into this already but I could not get the existing tests to work? I actually have a fix working locally but I just assumed you wouldn't want a PR without tests.

➜  factory-generator git:(master) vendor/bin/phpunit
PHPUnit 9.4.0 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

FFEEEEEEEEEEE...........................                          40 / 40 (100%)

Time: 00:00.324, Memory: 26.00 MB

There were 11 errors:

1) Tests\GenerateCommandTest::it_can_create_prefilled_factories_for_defined_models_only_with_including_namespace
UnexpectedValueException: could not find model [\Tests\Fixtures\Models\Car]

Do i need a local .env or something for this to work?

Sorry if this is an obvious question? I don't do much package or open source work.

jasonmccreary commented 3 years ago

The tests are in a broken state. So for now, we'll accept the patch you have verified to be working locally.