worksome / request-factories

Test requests in Laravel without all the boilerplate.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Method App\Http\Requests\<folder>\StoreRequest::factory does not exist.

jjjrmy opened this issue · comments

class StoreRequest extends FormRequest
{
    public static string $factory = StoreRequestFactory::class;

Can you provide more clear examples? Like where and what is being included.

No matter what I try I can't get Factories in other folders or the actual FormRequest::factory to work.

What version do you have installed? 👀

let me try now, I was on 2.5. Had to upgrade to PHP 8.2

Could not find [Database\Requests\Invoice\StoreRequestFactory].
Please specify a relevant RequestFactory FQCN using a public static $factory property on
[App\Http\Requests\Invoice\StoreRequest].

Invoice_Test.php

namespace Tests\Feature;

use App\Http\Requests\Invoice\StoreRequest;

it('does something', function () {

    $data = StoreRequest::factory()->create();

App\Http\Requests\Invoice\StoreRequest.php

namespace App\Http\Requests\Invoice;

use Database\Requests\Invoice\StoreRequestFactory;

class StoreRequest extends FormRequest
{

    public static $factory = StoreRequestFactory::class;

Database\Requests\Invoice\StoreRequestFactory.php

namespace Database\Requests\Invoice;

use Worksome\RequestFactories\RequestFactory;

class StoreRequestFactory extends RequestFactory
{
    public function definition(): array
    {
        return [

request-factories.php

return [
    /**
     * The default path for request factories is 'tests/RequestFactories'.
     * Keep this value as `null` to use the default. If you'd rather
     * change the default location, you may override it here.
     */
    'path' => 'database/requests',

    /**
     * If your request factories are located somewhere other than the
     * default location, you should update the namespace to reflect
     * that to prevent bugs when locating factories from a request.
     */
    'namespace' => 'Database\\Requests',
];

It seems to work fine if I move it back to the default folder and remove the config, but I thought the package lets you customize the locations?

let me add in the person who mainly build this :)

ping @lukeraymonddowning

bump

bump, still not working and completely unusable unless you are on 8.2 which is not possible for my current project.

@jjjrmy as far as the 8.2 part is concerned, I've just tagged v2.6.0 which adds support for L10 when using older versions of PHP.

Not had chance to look into the issue yet but it is on my todo list

@jjjrmy quick thought on this: have you added the relevant PSR-4 autoloading entry to your composer.json file for the namespace you've created here? Should look something like this:

"autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Seeders\\": "database/seeders/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Requests\\": "database/requests/"

Don't forget to composer dump-autoload afterwards

@jjjrmy as far as the 8.2 part is concerned, I've just tagged v2.6.0 which adds support for L10 when using older versions of PHP.

Thank you, I think this is very necessary! I will give it a try.

@jjjrmy quick thought on this: have you added the relevant PSR-4 autoloading entry to your composer.json file for the namespace you've created here?

I haven't revisited this, but I will try again with the v2.6.0

Going to close this as I haven't heard anything new 👍