Files
Gnuboard7/modules/_bundled/sirsoft-board/tests/Unit/Support/ApiDocSampleServiceTest.php
T
HeuJung 70452745c4 feat(api-docs): API 레퍼런스 문서 전면화 — 추출 파이프라인·전 대상 문서화·audit 강제
코드에만 존재하던 REST API 계약(약 663 엔드포인트)을 코어/확장 책임별로
분리된 마크다운 레퍼런스로 전면 문서화한다. 674개 규모에서 수기 문서는
반드시 drift 하므로 "코드 추출 → 스캐폴딩 → 사람이 서술 채움 → 하네스가
커버리지 강제" 하이브리드로 구성했다.

추출 파이프라인 (app/Support/ApiDoc):
- ApiRouteInventory / FormRequestIntrospector / ApiEndpointProbe(실측 HTTP) /
 ResponseSchemaInferrer / ApiDocScaffolder / ColumnCommentResolver /
 ResourceFieldDescriber / ParameterDescriber
- api:docgen 커맨드(--scope/--seed/--check/--dry-run/--base-url/--user) +
 응답/파라미터 in-place 백필 커맨드 2종(재생성 없이 TODO 셀만 치환, 멱등)
- ApiDocSampleSeeder 계약 + 코어/확장 시더로 실측용 완전 샘플 멱등 생성

문서화 (실측 기반, GET read-only 실호출):
- 코어 291엔드포인트 35파일(docs/backend/api) + 규정 docs/backend/api-documentation.md
- 확장: ecommerce(231)·board(80)·page(17)·hello_module(2)·pay_kginicis(22)·
 gdpr(15)·ckeditor5(2)·marketing(2)·verification_kginicis(1)
- 표준 4구성(헤더·요청 파라미터·응답 필드·에러 표) + 엔드포인트 용도 서술
- 파라미터 용도·응답 필드 설명 셀 전수 채움(도메인 지식 수기)

하네스:
- audit 룰 api-doc-coverage — API 표면(라우트/컨트롤러/FormRequest/Resource)
 변경 시 대응 문서 미동반이면 차단. 전 대상 문서 완비로 error 승격
- file-rules 리마인더(컨트롤러/라우트 편집 시), coverage.json, dev-dashboard 카드
- docs/backend/routing.md 확장 공개 API URL 스킴 정정(/api/modules|plugins/{id})
- /AGENTS.md/docs-index 동기
2026-07-08 18:22:33 +09:00

113 lines
4.5 KiB
PHP

<?php
namespace Modules\Sirsoft\Board\Tests\Unit\Support;
// ModuleTestCase를 수동으로 require (autoload 전에 로드 필요)
require_once __DIR__.'/../../ModuleTestCase.php';
use App\Contracts\ApiDoc\ApiDocSampleSeeder;
use Modules\Sirsoft\Board\Models\Attachment;
use Modules\Sirsoft\Board\Models\Board;
use Modules\Sirsoft\Board\Models\Comment;
use Modules\Sirsoft\Board\Models\Post;
use Modules\Sirsoft\Board\Support\ApiDoc\ApiDocSampleService;
use Modules\Sirsoft\Board\Tests\ModuleTestCase;
use PHPUnit\Framework\Attributes\Test;
/**
* sirsoft-board API 문서 실측용 완전 샘플 시더 테스트.
*
* 게시판 도메인 대표 샘플(공개 게시글 + 댓글 + 첨부)이 생성되고, slug 라우팅
* 실측을 위한 도메인별 path_params 맵이 반환되며, 재실행 시 멱등한지 검증한다.
*/
class ApiDocSampleServiceTest extends ModuleTestCase
{
/**
* @var string 샘플 게시판 슬러그 마커
*/
private const SAMPLE_SLUG = 'apidoc-sample-board';
#[Test]
public function 시더는_계약을_구현한다(): void
{
$this->assertInstanceOf(ApiDocSampleSeeder::class, new ApiDocSampleService);
}
#[Test]
public function 게시판_도메인_대표_샘플_맵을_반환한다(): void
{
$map = (new ApiDocSampleService)->seed();
// 공개(boards)/관리자(board) 두 도메인 키가 모두 존재
$this->assertArrayHasKey('boards', $map);
$this->assertArrayHasKey('board', $map);
$this->assertSame(Board::class, $map['boards']['model']);
$this->assertNotEmpty($map['boards']['value']);
}
#[Test]
public function slug_라우팅_실측용_path_params_맵을_제공한다(): void
{
$map = (new ApiDocSampleService)->seed();
// boards 도메인은 slug/board/id/postId/commentId/hash 를 실제 값으로 제공
$params = $map['boards']['path_params'];
$this->assertSame(self::SAMPLE_SLUG, $params['slug']);
$this->assertArrayHasKey('id', $params);
$this->assertArrayHasKey('postId', $params);
$this->assertArrayHasKey('commentId', $params);
$this->assertArrayHasKey('hash', $params);
// 각 값은 실제 시드된 레코드의 키와 일치
$post = Post::query()->where('title', 'API 문서 샘플 게시글')->firstOrFail();
$comment = Comment::query()->where('content', 'API 문서 샘플 댓글입니다.')->firstOrFail();
$attachment = Attachment::query()->where('original_filename', 'apidoc-sample.png')->firstOrFail();
$this->assertSame((string) $post->getKey(), $params['id']);
$this->assertSame((string) $post->getKey(), $params['postId']);
$this->assertSame((string) $comment->getKey(), $params['commentId']);
$this->assertSame((string) $attachment->hash, $params['hash']);
}
#[Test]
public function 대표_샘플_게시판은_공개_게시글과_댓글과_첨부를_갖는다(): void
{
(new ApiDocSampleService)->seed();
$board = Board::query()->where('slug', self::SAMPLE_SLUG)->firstOrFail();
$post = Post::query()->where('board_id', $board->id)->where('title', 'API 문서 샘플 게시글')->firstOrFail();
$this->assertTrue((bool) $board->is_active);
$this->assertFalse((bool) $post->is_secret);
$this->assertSame('published', $post->status->value);
$this->assertSame(1, Comment::query()->where('post_id', $post->id)->count());
$this->assertSame(1, Attachment::query()->where('post_id', $post->id)->count());
}
#[Test]
public function 게시판별_권한이_admin_역할에_등록되어_실측_사용자가_접근할_수_있다(): void
{
(new ApiDocSampleService)->seed();
// ensureBoardPermissions 로 게시판별 권한이 생성됨 (posts.read 등)
$this->assertDatabaseHas('permissions', [
'identifier' => 'sirsoft-board.'.self::SAMPLE_SLUG.'.posts.read',
]);
}
#[Test]
public function 재실행_시_샘플이_중복_생성되지_않는다(): void
{
$service = new ApiDocSampleService;
$service->seed();
$service->seed();
$this->assertSame(1, Board::query()->where('slug', self::SAMPLE_SLUG)->count());
$this->assertSame(1, Post::query()->where('title', 'API 문서 샘플 게시글')->count());
$this->assertSame(1, Comment::query()->where('content', 'API 문서 샘플 댓글입니다.')->count());
$this->assertSame(1, Attachment::query()->where('original_filename', 'apidoc-sample.png')->count());
}
}