'cast-board-posts', 'name' => ['ko' => '캐스트 테스트', 'en' => 'Cast Test'], 'is_active' => true, 'posts_count' => '5', ]); $this->assertSame(5, $board->refresh()->posts_count, 'posts_count 는 정수로 캐스트되어야 합니다'); } #[Test] public function board_comments_count_is_fillable_and_cast_to_integer(): void { $board = Board::create([ 'slug' => 'cast-board-comments', 'name' => ['ko' => '캐스트 테스트', 'en' => 'Cast Test'], 'is_active' => true, 'comments_count' => '3', ]); $this->assertSame(3, $board->refresh()->comments_count, 'comments_count 는 정수로 캐스트되어야 합니다'); } // ========================================================================= // Post 모델 // ========================================================================= #[Test] public function post_replies_count_is_fillable_and_cast_to_integer(): void { $post = Post::create([ 'board_id' => $this->board->id, 'title' => '캐스트 테스트', 'content' => '내용', 'author_name' => '테스트', 'ip_address' => '127.0.0.1', 'status' => 'published', 'replies_count' => '2', ]); $this->assertSame(2, $post->refresh()->replies_count, 'replies_count 는 정수로 캐스트되어야 합니다'); } #[Test] public function post_comments_count_is_fillable_and_cast_to_integer(): void { $post = Post::create([ 'board_id' => $this->board->id, 'title' => '캐스트 테스트', 'content' => '내용', 'author_name' => '테스트', 'ip_address' => '127.0.0.1', 'status' => 'published', 'comments_count' => '7', ]); $this->assertSame(7, $post->refresh()->comments_count, 'comments_count 는 정수로 캐스트되어야 합니다'); } #[Test] public function post_attachments_count_is_fillable_and_cast_to_integer(): void { $post = Post::create([ 'board_id' => $this->board->id, 'title' => '캐스트 테스트', 'content' => '내용', 'author_name' => '테스트', 'ip_address' => '127.0.0.1', 'status' => 'published', 'attachments_count' => '4', ]); $this->assertSame(4, $post->refresh()->attachments_count, 'attachments_count 는 정수로 캐스트되어야 합니다'); } // ========================================================================= // Comment 모델 // ========================================================================= #[Test] public function comment_replies_count_is_fillable_and_cast_to_integer(): void { $postId = $this->createTestPost(); $comment = Comment::create([ 'board_id' => $this->board->id, 'post_id' => $postId, 'author_name' => '테스트', 'content' => '댓글', 'ip_address' => '127.0.0.1', 'status' => 'published', 'replies_count' => '6', ]); $this->assertSame(6, $comment->refresh()->replies_count, 'Comment.replies_count 는 정수로 캐스트되어야 합니다'); } // ========================================================================= // 정수 캐스트 — DB 에서 문자열로 읽혀도 정수로 반환 // ========================================================================= #[Test] public function post_count_columns_are_cast_to_integer_when_loaded_from_db(): void { $postId = DB::table('board_posts')->insertGetId([ 'board_id' => $this->board->id, 'title' => '로드 캐스트 테스트', 'content' => '내용', 'author_name' => '테스트', 'ip_address' => '127.0.0.1', 'is_notice' => false, 'is_secret' => false, 'status' => 'published', 'trigger_type' => 'admin', 'view_count' => 0, 'replies_count' => 1, 'comments_count' => 2, 'attachments_count' => 3, 'created_at' => now(), 'updated_at' => now(), ]); $post = Post::findOrFail($postId); $this->assertSame(1, $post->replies_count); $this->assertSame(2, $post->comments_count); $this->assertSame(3, $post->attachments_count); } }