2013-08-02 2 views
0

PHPUnit을 사용하는 데 어려움을 겪고 있습니다. 내 디렉토리 php는 C:/wamp/bin/php/php5.4.3입니다. 이제 PHPUnit은 PEAR 없이는 작동하지 않습니다. 따라서 go-pear.phar 파일을 가져 와서 C:/wamp/bin/php/php5.4.3/PEAR/에 배치하고 go-pear.phar 파일을 실행하고 시스템에 설치했습니다. 셋째, 내가 phpunit을가 Git Bash를 사용하여 (디렉토리가 올바른지 확실하지 않음) 이제 C:/wamp/www/local/unit-testing/PHPUnit 설치 및 작업

를 넣어 설치, 나는 간단한 UserTest 파일

<?php 
require_once "phpunit/PHPUnit/Autoload.php"; 
require_once "User.php"; 
class UserTest extends PHPUnit_Framework_TestCase 
{ 
    protected $user; 

    // test the talk method 
    protected function setUp() { 
     $this->user = new User(); 
     $this->user->setName("Tom"); 
    } 

    protected function tearDown() { 
     unset($this->user); 
    } 

public function testTalk() { 
     $expected = "Hello world!"; 
     $actual = $this->user->talk(); 
     $this->assertEquals($expected, $actual); 
    } 

} 

을 만들고이 파일 실행을 요구하는 시도 Windows의 명령 줄에서. 그러나이 파일이 정확히 어디에 있어야하는지에 대한 지침이 없기 때문에 실행할 수 없습니다.

현재 문제는 명령 줄에서 PEAR 명령을 인식하지 못하는 것입니다. 비록 나는 PEAR_ENV.reg 파일을 실행하여 파일에 PATH 변수를 추가했습니다.

둘째로, 정확히 현재 PEU 번호가 & 인 PHPUnit을 설치해야하는지 잘 모르겠습니다. 내 모든 PHP 페이지/프로젝트를 C:/wamp/www/local/ <에 보관 -이 디렉토리에있는 파일을 테스트해야합니다.

+0

내가 너라면, Linux를 개발 증거 (예 : 보조 시스템)로 설치 한 다음 몇 가지 명령 줄을 입력하여 pear, pecl, phpunit 및 기타 모든 도구를 설치하십시오. 이것은 Windows와의 전투보다 훨씬 적은 시간이 걸릴 것입니다. – takeshin

+0

누구든지 만족할만한 답변을 받았습니까? 아니면 여전히 제안 사항에 문제가 있습니까? –

답변

2

PHPUnit 배치 파일이 경로에 있어야합니다. 커맨드 라인에서 PHPUnit을 실행하는 것은 셸에서 수행되며, 현재 디렉토리는 모든 것을 설치 한 곳이며, User.php 파일도 거기에 있다고 가정합니다.

소스 코드 디렉토리에서 실행할 bootstrap.php 파일을 작성했습니다.

<?php 
/** 
* This file is used to configure the basic environment for testing in PHPUnit. 
*/ 

// PHP and Web server settings 
error_reporting(E_ALL | E_STRICT); 
date_default_timezone_set("America/Toronto");  // Set the default timezone 
$_SERVER['SERVER_NAME'] = 'http://xxx';  // Set Web Server name 

// Process the Include Path to allow the additional applications to be set. 
$IncludePaths = explode(PATH_SEPARATOR, get_include_path()); 
$NewIncludePaths = array_merge($IncludePaths, array(dirname(__FILE__))); 
set_include_path(implode(PATH_SEPARATOR, array_unique($NewIncludePaths))); // Update Include Path 

//define('PHPUNIT_RUNNING', 1); // Indicate to the code that Automated Testing is running. 
?> 

은 내가 PEAR Installation Instructions for PHPUnit을 따라 물건을 얻을 PHPUnit.bat 내 DOS 경로에 있던 존재하는 디렉토리 일단 실행 할 수 있었다.