Welcome Guest, Not a member yet? Register   Sign In
How do I mock Models when testing?
#4

(This post was last modified: 06-19-2022, 03:24 AM by MGatner.)

I like your model factory approach! You could keep using it that way and even expand it by placing it on a parent BaseModel and have it do something like this:


PHP Code:
public static function factory(): static
{
    return model(static::class);



That way you could always access your shared factory instance but still use the actual model class you are after:

PHP Code:
UserModel::factory()->find(1); 
Reply


Messages In This Thread
How do I mock Models when testing? - by tgix - 06-17-2022, 03:50 AM
RE: How do I mock Models when testing? - by tgix - 06-17-2022, 04:19 AM
RE: How do I mock Models when testing? - by MGatner - 06-19-2022, 03:22 AM
RE: How do I mock Models when testing? - by tgix - 06-19-2022, 07:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB