تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Planning Reply Tests0:00

Let's implement the reply functionality. Now, of course, to do that, we are going to implement some tests and our first one is going to be, can reply to Post. And we're gonna write two tests. The first is going to, uh, where we can create a Post using our factory. We don't need a Profile for this particular test, at least for the original Post. And then the second one, we will use just our factory.

for the original Post. And then the second one, we will use just our factory to create all the Posts that we need. Because we are going to, first of all, test if we can make a Reply. And then the second one will be to test if we can have multiple Replys. So we have our original post and let's just call it original. And then we're gonna do two things.

Defining Reply Signature0:48

and let's just call it original. And then we're gonna do two things. We will create a ReplyingProfile. So let's create that profile from our factory, and then we will create the reply. But we're gonna do, so kind of like what we did with the published method from our Post model, so that it will look something like this. We will just call reply. But what was the signature?

We will just call reply. But what was the signature? So we passed in the profile first, followed by the content. And I think we can kind of follow that. It's of course going to be a little bit different. But the first thing I think we should pass in is the profile that is creating this post. Then we can pass in the original post that we are replying to. And then finally we will have our reply content.

that we are replying to. And then finally we will have our reply content. So that's what we want to do. And then we just have to test these things. And I want to do this from both sides, both from the original Post side and then from the reply side. So we can say that the reply parent is the original Post and we want that to be true. And then we could check if the original Post replies two have count of one.

And then we could check if the original replies two have count of one. And you know, that should be fine because at this point in time we have just one post, we have just one reply. If the replies are one, then that should pass. So of course, let's run our pass. It's going to fail because we don't have that reply method, but that's okay. We will of course implement that.

Implementing Reply Method2:31

but that's okay. We will of course implement that. And let's just take what we have for publish and let's use that as the basis for the reply method. But we have three arguments here. We have the profile, then we have the originalPost followed by the content, and everything else is gonna be the same. So that's the profileId is set, the content is set.

and everything else is gonna be the same. So that's the profileId is set, the content is set to the parentId, is going to be the original id, and that should be that. So now if we run our test, that should pass. We should have two passing. We do. So that's great. So now the next, or or the next test that I want to test is can we have multiple replies? So can haveMany replies.

Testing Multiple Replies3:16

is can we have multiple replies? So can have many replies. And we are going to still create this original Post, but now we will just create our replies using our factory. And we want, you know, it really doesn't matter how many. So let's do three, or let's do four because that's what I fat fingered. And then, uh, we want to reply to the original Post for those four posts, and then we will create those. So now we don't have the reply.

for those four Posts, and then we will create those. So now we don't have the reply. We don't have the reply, we just have this original end replies. So let's do this. The replies. Let's get the first reply and we will check that the parent is the original. That should be true. Then we can test if the original replies have a count of four. But let's also do this.

replies have a count of four. But let's also do this. Now that we have multiple replies, I want to be, I'm not gonna say thorough because this isn't thorough, or is it, I don't know. We'll say originalReplies contains, and then we'll grab one of the replies. Let, let's just grab the first one and that should be true. All right, so if the replies first parent is the original, then if the original has four replies,

All right, so if the replies first parent is the original, then if the original has four replies, then if the original replies contains the first reply, kind of a mouthful. But if we run our tests, we should have three passing. And that's great. So now not only do we have an easy way of replying to a post, we also know that it works and that we can have as many replies as we need. Now we just need to work on the repost functionality.

Transition to Reposts5:06

Now we just need to work on the repost functionality.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟