|
2 | 2 |
|
3 | 3 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
|
4 | 4 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
|
| 5 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Comment; |
5 | 6 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile;
|
6 | 7 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher;
|
7 | 8 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store;
|
8 | 9 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
|
9 | 10 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook;
|
| 11 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedComment; |
10 | 12 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile;
|
11 | 13 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher;
|
12 | 14 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore;
|
@@ -39,4 +41,29 @@ public function testWithCountUpdatesAfterRecordIsAdded()
|
39 | 41 | $this->assertNotEquals($author1->books_count, $author2->books_count);
|
40 | 42 | $this->assertEquals($author1->books_count + 1, $author2->books_count);
|
41 | 43 | }
|
| 44 | + |
| 45 | + /** @group test */ |
| 46 | + public function testWithCountOnMorphManyRelationshipUpdatesAfterRecordIsAdded() |
| 47 | + { |
| 48 | + $book1 = (new Book) |
| 49 | + ->withCount("comments") |
| 50 | + ->first(); |
| 51 | + dump("start"); |
| 52 | + factory(Comment::class, 1) |
| 53 | + ->make() |
| 54 | + ->each(function ($comment) use ($book1) { |
| 55 | + $comment->commentable_id = $book1->id; |
| 56 | + $comment->commentable_type = $book1->getTable(); |
| 57 | + $comment->save(); |
| 58 | + }); |
| 59 | + dump("end"); |
| 60 | + |
| 61 | + $book2 = (new Book) |
| 62 | + ->withCount("comments") |
| 63 | + ->where("id", $book1->id) |
| 64 | + ->first(); |
| 65 | + |
| 66 | + $this->assertNotEquals($book1->comments_count, $book2->comments_count); |
| 67 | + $this->assertEquals($book1->comments_count + 1, $book2->comments_count); |
| 68 | + } |
42 | 69 | }
|
0 commit comments