본문으로 바로가기

[PHP] VisualPHPUnit

category Helloworld!/PHP 2016. 5. 11. 15:48
요즘 Unit Test 를 위해 phpUnit 에 대해 공부중인데, phpUnit 으로 테스트 케이스를 만든다음에 터미널에서 실행해보면 성공과 실패를 성공은 점(.) 실패는 F로 표현하고 그것도 한 줄로 보여준다
> phpunit
PHPUnit 4.8.24 by Sebastian Bergmann and contributors.

........F..........

Time: 3.55 seconds, Memory: 6.00Mb

There was 1 failure:

1) SignUpTest::testValidEmail with data set #3 ('xesper1s@@yahoo.com')
Failed asserting that false is true.

path\MyTest.php:129
path\php\pear\PHPUnit\TextUI\Command.php:176
path\php\pear\PHPUnit\TextUI\Command.php:129

FAILURES!
Tests: 19, Assertions: 14, Failures: 1.

OK (19 tests, 14 assertions)

너무 보기힘들어서 터미널에서 색깔도 넣고 좀 더 보기 편한 모양으로 바꿔주는 방법이 없을까 싶어 구글링해보니까 VisualPHPUnit 라는 라이브러리를 찾았다.
자신을 front-end for PHPUnit 이라고 설명하면서 다음과 같이 phpUnit 결과물을 웹페이지에서 보여준다고 한다.



부트스트랩 디자인에 그래프까지 제공해준다는걸 보고 가차없이 설치 ㄲㄲ

1. 우선 VisualPHPUnit을 다운로드 받는다


2. 원하는 곳에 압축을 풀면 VisualPHPUnit 폴더가 생성이 된다. 

3. 본인이 이용하는 에디터에서 VisualPHPUnit/app/config 안에 있는 bootstrap.php 를 연다

4. 거기에 $config 라는 배열이 있는데 그중에서 composer_vendor_pathtest_directories를 자신 세팅 환경에 알맞게 변경해준다.
 $config = array(
    /* Required */

    // The directory where Composer vendor is located (the one that phpunit was required into)
    'composer_vendor_path' => $root . '/vendor', //내 phpunit composer vendor 가 위치한 곳 설정
    // The directory where Composer bin is located (where phpunit command is located)
    'composer_bin_path' => $root . '/bin',

    // The directories where the tests reside
    'test_directories' => array(
        'Sample Tests' => "{$root}/app/test", //내가 Test 하고 싶은 Test Case 소스코드가 있는 곳 설정
        //'My Project' => '/var/www/sites/my.awesome.site.com/laravel/tests', //또는 Array 추가로 여러개의 Directory를 설정할 수 있다.
    ),
   ....
   ....
   ....


설치가 완료되면 위 스크린샵에서 보는 것과 같이 이쁜 모양으로 테스트 결과를 확인할 수 있다.