This repository was archived by the owner on Jul 15, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 44namespace Actuallymab \LaravelComment ;
55
66use Actuallymab \LaravelComment \Contracts \Commentable ;
7+ use Actuallymab \LaravelComment \Models \Comment ;
78use Illuminate \Database \Eloquent \Relations \MorphMany ;
89
910trait CanComment
1011{
11- public function comment (Commentable $ commentable , string $ commentText = '' , int $ rate = 0 ): self
12+ public function comment (Commentable $ commentable , string $ commentText = '' , int $ rate = 0 ): Comment
1213 {
1314 $ commentModel = config ('comment.model ' );
1415
15- $ commentable -> comments ()-> save ( new $ commentModel ([
16+ $ comment = new $ commentModel ([
1617 'comment ' => $ commentText ,
1718 'rate ' => $ commentable ->canBeRated () ? $ rate : null ,
1819 'approved ' => $ commentable ->mustBeApproved () && !$ this ->canCommentWithoutApprove () ? false : true ,
1920 'commented_id ' => $ this ->primaryId (),
2021 'commented_type ' => get_class (),
21- ])) ;
22+ ]);
2223
23- return $ this ;
24+ $ commentable ->comments ()->save ($ comment );
25+
26+ return $ comment ;
2427 }
2528
2629 public function canCommentWithoutApprove (): bool
Original file line number Diff line number Diff line change 33
44namespace Actuallymab \LaravelComment \Tests ;
55
6+ use Actuallymab \LaravelComment \Models \Comment ;
67use Actuallymab \LaravelComment \Tests \Models \Product ;
78use Actuallymab \LaravelComment \Tests \Models \User ;
89use Illuminate \Foundation \Testing \WithFaker ;
@@ -27,6 +28,15 @@ public function it_belongs_to_a_can_comment_object()
2728 $ this ->assertTrue ($ product ->comments ()->first ()->commented ->is ($ user ));
2829 }
2930
31+ /** @test */
32+ public function comment_object_is_returned_after_comment_operation ()
33+ {
34+ $ user = $ this ->createUser ();
35+ $ product = $ this ->createProduct ();
36+
37+ $ this ->assertInstanceOf (Comment::class, $ user ->comment ($ product , $ this ->faker ->sentence ));
38+ }
39+
3040 /** @test */
3141 public function comment_can_be_checked ()
3242 {
You can’t perform that action at this time.
0 commit comments