2010-06-16 7 views
3

내 필터/유효성 검사기가 내 양식에서 올바르게 작동하지 못하여 단위 테스트를 작성하여 양식에 제출중인 데이터가 필터링되고 올바르게 검증되는지 확인하려고합니다. 그럼 내가 터미널을 열고Zend Framework : PHPUnit이 Forms를 테스트하는 방법을 시작 하시겠습니까?

<?php 
require_once 'PHPUnit/Framework/TestCase.php'; 

/** 
* Form_Event test case. 
*/ 
class Form_EventTest extends PHPUnit_Framework_TestCase 
{ 
    /** 
    * @var Form_Event 
    */ 
    private $Form_Event; 
    /** 
    * Prepares the environment before running a test. 
    */ 
    protected function setUp() 
    { 
     parent::setUp(); 
     // TODO Auto-generated Form_EventTest::setUp() 
     $this->Form_Event = new Form_Event(/* parameters */); 
    } 
    /** 
    * Cleans up the environment after running a test. 
    */ 
    protected function tearDown() 
    { 
     // TODO Auto-generated Form_EventTest::tearDown() 
     $this->Form_Event = null; 
     parent::tearDown(); 
    } 
    /** 
    * Constructs the test case. 
    */ 
    public function __construct() 
    { // TODO Auto-generated constructor 
    } 
    /** 
    * Tests Form_Event->init() 
    */ 
    public function testInit() 
    { 
     // TODO Auto-generated Form_EventTest->testInit() 
     $this->markTestIncomplete(
     "init test not implemented"); 
     $this->Form_Event->init(/* parameters */); 
    } 
    /** 
    * Tests Form_Event->getFormattedMessages() 
    */ 
    public function testGetFormattedMessages() 
    { 
     // TODO Auto-generated Form_EventTest->testGetFormattedMessages() 
     $this->markTestIncomplete(
     "getFormattedMessages test not implemented"); 
     $this->Form_Event->getFormattedMessages(/* parameters */); 
    } 
} 

디렉토리로 이동하고 테스트를 실행하려고 :

나는 자동 생성하는 저에게이 있습니다 젠드 스튜디오에서 phpunit을 테스트를 시작
$ cd my_app/tests/unit/application/forms 
$ phpunit EventTest.php 

Fatal error: Class 'Form_Event' not found in .../tests/unit/application/forms/EventTest.php on line 19 

그렇다면 상단에 require_once을 추가하여 내 Form 클래스를 포함시키고 다시 시도하십시오. 이제는 다른 수업을 찾을 수 없다고합니다. 나는 그 중 하나를 포함하고 그것을 다시 시도하십시오. 그런 다음 다른 클래스와 다른 클래스를 찾을 수 없다고 말합니다. 다른 모든 Zend_Form 클래스에 이러한 모든 종속성이 있습니다. 어떻게해야합니까? 유효성 검사기와 필터가 올바르게 연결되어 있는지 확인하기 위해 양식을 테스트하고 테스트를 수행해야합니다. 아니면 내가 잘못 생각한거야?

답변

3

귀하는 Unittest를 위해 Zend Framework Application Configuration을 사용해야합니다. PHPUnit의 "XML"설정으로 작업하는 경우 테스트가 실행되기 전에 실행되는 부트 스트랩 파일을 추가하십시오.

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit bootstrap="TestConfig.php"> 
    <testsuite name="XY"> 
     <directory>./</directory> 
    </testsuite> 
</phpunit> 
당신의 TestConfig.php 설정 자동로드 및 기타 필요한 능숙에서

, 또는 내 예제처럼 응용 프로그램에서 config.ini 파일을 사용합니다.

$includeConfig = parse_ini_file(TEST_PATH . '/config/config.ini', true); 

set_include_path(
    implode(PATH_SEPARATOR, $includeConfig['includes']) 
    . PATH_SEPARATOR 
    . TEST_PATH . PATH_SEPARATOR 
    . get_include_path() 
); 
unset($includeConfig); 

require_once 'Zend/Loader/Autoloader.php'; 
$autoloader = Zend_Loader_Autoloader::getInstance(); 
$autoloader->registerNamespace('App_'); 

더 많은 힌트를 phpunit을 PHPUnit + Zend Framework

+0

아르네와 젠드 프레임 워크에서이 튜토리얼을 확인해야하는 경우 : 귀하의 주어진 링크 (503) 오류가오고, 고장, 당신은 위의 링크를 변경하거나 새로운 예제를 추가하십시오 수 있습니다 링크가 있다면 – Shreyas