If it's static methods, then you don't need mocking. However, how do you want to generate a data without model factories and seeders?
Aug 4, 2023
6
Level 1
Mocking A Static Eloquent Model?
Currently, I have a bunch of static helper methods with a fair amount of logic that requires testing.
Buried in those numerous methods is a single database call used in a single helper function:
Categories::where('x', 'y')->first().
I currently do not want to go through all the trouble of configuring a whole sqlite database and populating it with seeder data (our .env files are pretty custom), OR to pass a $Category class into every instance of this function to fake it. (Although they either is a possible last resort.)
Ideally, what I'd like to be able to do it something like:
$mock = Mockery::mock('alias:Category');
$mock->shouldreceive('first')->andReturn('someObject');
$this->assertequals(Category::first, 'someObject');
But you know, with that actually working. Is there an easy way?
Please or to participate in this conversation.