2009-04-23 3 views
1

필자는 PHPUnit DataBase를 사용하여 MDB2를 사용하여 일부 클래스를 테스트합니다.PHPUnit 데이터베이스로 MDB2를 사용하여 여러 테스트를 수행하는 방법은 무엇입니까?

모두는 잘 나는 오류를 반환 두 번째 테스트, 발생 이후 : 내가 처음 한 자리에 두 번째 테스트를 배치 할 때

Caught exception: Object of class MDB2_Error could not be converted to string

, 새로운 첫 번째 테스트는 OK입니다 만, 두 번째 하나는 같은 오류를 반환합니다! 다음 것들도!

MDB2 연결이 첫 번째 테스트 후에 닫힙니까?

public function __construct() 
{ 
    $this->pdo = new PDO('connectionstring', 'user', 'passwd'); 
    try { 
     $this->mdb2 = new MyDBA($this->dsn); 
    } 
    catch (Exception $e) { 
     error_log(' __construct Caught exception: '.$e->getMessage()); 
    } 
} 

MyDBA이 싱글을 반환

여기 내 생성자입니다. 예외는 여기에

는이 개 첫 번째 시험이다 ... 생성자 내부에서 발생하지 않습니다 :

public function testTranslationAdd() 
{ 
    try { 
     $id = $this->mdb2->addTranslation("This is the second english translation.","en"); 
    } 
    catch (Exception $e) { 
     error_log(' testTranslationAdd Caught exception: '.$e->getMessage()); 
    } 

    $xml_dataset = $this->createFlatXMLDataSet(dirname(__FILE__).'/state/twotranslations.xml'); 
    $this->assertDataSetsEqual($xml_dataset, 
           $this->getConnection()->createDataSet(array("translation"))); 
} 

public function testTranslationGet() 
{ 
    try { 
     $text = $this->mdb2->getTranslation(1,"en"); 
    } 
    catch (Exception $e) { 
     error_log(' testTranslationGet Caught exception: '.$e->getMessage()); 
    } 

    $this->assertEquals("This is the first english translation.",$text); 
} 
+0

나는 예외가 어디에서 던져 질까요? – james

답변

2

당신은 정말 당신의 MDB2 결과가 오류없는 주장을 추가해야합니다 :

$this->assertFalse(MDB2::isError($this->mdb2), 'MDB2 error'); 

을 그 불행히도 오류가 무엇인지 알지 못하며 오류가없는 경우 getMessage()을 직접 사용하면 오류가 발생합니다. 당신이 그런 식으로 뭔가를 써야하는 이유 :

if (MDB2::isError($this->mdb2)) { 
    $this->fail('MDB2 error: ' . $this->mdb2->getMessage()); 
} 
관련 문제