#buildinpublic #mbsync Well, that worked. We just had to add:
public function posts(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Post::class);
}
to the Blog model.
Now we can do the following in our test:
$blog = Blog::factory()->has(Post::factory()->count(1))->create();
$post = $blog->posts->first();
That post now has some fake data as defined in my PostFactory.
Time to write this to disk. We could use PostFilePersistorService::storePost
. This method makes a couple of assumptions about where to write data and I would like it to just write where I want it to. So I will refactor the path generation logic out of storePost
. In the future it should be handed in via a parameter. This is a big change but we’re the only developer and in the “break lots of things” phase, so I feel this is fine.
There is only one problem: We again have no test! So what I’ll do is make the other test pass, add a TODO to it and create a test for storePost. First things first.