티스토리 뷰

Codeception이란?

  • PHP 진영에는 PHPUnit이라는 독보적인 유닛 테스트 프레임워크가 존재한다. 하지만 PHPUnit으로 REST API를 테스트하려면 상당히 번거롭다. 1개 API를 테스트를 할 때마다 json_encode, json_decode, curl_exec가 등장하면서 테스트 코드가 장황해진다.

  • Codeception은 바로 이러한 REST API를 테스트하는데 최적화된 PHPUnit 기반의 프레임워크이다. 테스트 코드의 양이 줄면서 가독성이 증가하고 테스트 자체에 집중할 수 있다.
<?php
$I->sendGET('/users/1');
$I->seeResponseCodeIs(HttpCode::OK); // 200
$I->seeResponseIsJson();
$I->seeResponseMatchesJsonType([
    'id' => 'integer',
    'name' => 'string',
    'email' => 'string:email',
    'homepage' => 'string:url|null',
    'created_at' => 'string:date',
    'is_active' => 'boolean'
]);

Codeception 설치

  • 프로젝트 루트에서 Composer로 아래와 같이 설치한다.
# PHP >= 5.4.0
$ composer require codeception/codeception

# PHP >= 5.3.19
$ composer require codeception/codeception:1.8.7

PhpStorm 연동

  • PhpStorm 2017.1 부터 Codeception을 지원한다. 아래와 같이 연동 설정을 한다.
File -> Settings -> Language & Frameworks -> PHP -> Codeception
-> Path to Codeception executable: {프로젝트 루트}/vendor/codeception/codeception/codecept.bat
-> OK

참고 글

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함