示例#1
0
 public function stestTaskCreatedCommentPosted()
 {
     $user = User::firstOrFail();
     // variable
     $project = Project::create($this->projectdata);
     // variable
     $task = Task::create($this->taskdata);
     // variable
     $task->project()->associate($project);
     $this->assertEquals($task->project->id, $project->id);
     // test
     $comment = Comment::create($this->commentdata);
     // variable
     $user->comments()->save($comment);
     $this->assertEquals($user->id, $comment->owner->id);
     // test
     // $comment->commentable()->associate($task); // morphTo : fails
     // $comment->commentable()->save($task); // morphTo : fails
     $task->comments()->save($comment);
     // morphMany : ok
     $this->assertEquals($task->id, $comment->commentable->id);
     // test
     event(new TaskCreated($user, $project, $task));
     $this->assertEquals(1, Feed::count());
     // test
     event(new CommentPosted($user, $comment, $task));
     $this->assertEquals(2, Feed::count());
     // test
     $this->assertEquals($comment->commentable->id, $task->id);
     $this->assertEquals(TaskCreated::class, $task->feed->type);
     $this->assertEquals(CommentPosted::class, $comment->feed->type);
     $this->assertEquals(1, $task->comments->count());
     $this->assertEquals(1, $user->comments->count());
 }