2011-10-31 5 views
3

Github에서 PHP 5.3.6 및 최신 버전의 PHPUnit을 실행하고 있습니다. 문서에서 예제 17.1을 복사하면 assertTitle이 실패 할 때 치명적인 오류가 발생합니다. 이 오류 메시지가 나타납니다 :PHPUnit, Selenium Basic 테스트가 치명적 오류로 인해 실패 함

Fatal error: Call to a member function toString() on a non-object in <path>/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumTestCase.php on line 1041 

어설 션을 변경하면 PHPUnit이 정상적으로 실행됩니다.

나는 선을 발굴하고이 코드 조각입니다 :

protected function onNotSuccessfulTest(Exception $e) 
    { 
     if ($e instanceof PHPUnit_Framework_ExpectationFailedException) { 
      $buffer = 'Current URL: ' . $this->drivers[0]->getLocation() . 
         "\n"; 
      $message = $e->getComparisonFailure()->toString(); 

$ 전자> getComparisonFailure()가 NULL이 아닌 개체를 반환합니다. 내가 뭘 잘못하고 있니?

업데이트 : 수정 아직 내 지평선에 아니지만

나는 실패의 원인을 발견했다. phpunit을 라인 92

은/프레임 워크/Constraint.php, 그것을 사용하는 호출로 정의

$this->fail($other,$description)

:

더 PHPUnit_Framework_ComparisonFailure이 전달되지 않기 때문에 protected function fail($other, $description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL)

NULL 인 PHPUnit/Framework/Constraint.php의 141 행을 통과했습니다.

던져 새로운 PHPUnit_Framework_ExpectationFailedException ( $ failureDescription, $ comparisonFailure);

위의 설명과 같이 객체를 반환해야하는 getComparisonFailure()로 가져옵니다.

더 이상의 아이디어가 있습니까?

+0

phpunit-selenium의 기본 복사 붙여 넣기 예제에는 복사 및 붙여 넣기가 실패 할 때 단 하나의 단정에 실패 할 때 버그가 있다고합니다. –

답변

4

그냥 그것은 내가 할 $message = $e->getComparisonFailure()->toString(); 교체

+0

$ e-> getComparisonFailure에 의해 반환 된 객체가 메서드로 "exceptionToString"을 가진 객체가 아니기 때문에 나를 위해 작동하지 않습니다. –

+0

exceptionToString()에서 exceptionToString으로 변경하고 작동했습니다. 풀 요청을 요구하는 PHPUnit의 버그입니까? –

1

나를 위해 잘 작동 $message = $e->getComparisonFailure()->exceptionToString;

$message = $e->getComparisonFailure()->toString(); 교체 :

if($e->getComparisonFailure() == NULL) 
{ 
    $message = $e; 
} 
else 
{ 
    $message = $e->getComparisonFailure()->toString(); 
} 

가 나는 또한 그래서이 다시 3.5.3로 PHPUnit_Framework_ExpectationFailedException을 되돌아 setCustomMessage()

3

이 문제는 PHPU의 issue #66과 관련 있습니다. Github의 nit-Selenium 프로젝트. 저는이 문제를 수정 한 한 가지 커밋을했고 Matthew가 언급 한 "setCustomMessage()" problem을 수정했습니다.

// ?: Does the setCustomMessage method exist on the exception object? (fixes issue #67) 
if(method_exists($e, 'setCustomMessage')) { 
    // -> Method setCustomMessage does exist on the object, this means we are using PHPUnit 
    // between 3.4 and 3.6 
    $e->setCustomMessage($buffer); 
} 
else { 
    // -> Method setCustomerMessages does not exist on the object, must make a new exception to 
    // add the new message (inc. current URL, screenshot path, etc) 
    $e = new PHPUnit_Framework_ExpectationFailedException($buffer, $e->getComparisonFailure()); 
} 
:

$e->setCustomMessage($buffer); 

변경 : 나는

// ?: Is "comparison failure" set and therefore an object? (fixes issue #66) 
if(is_object($e->getComparisonFailure())) { 
    // -> Comparison failure is and object and should therefore have the toString method 
    $message = $e->getComparisonFailure()->toString(); 
} 
else { 
    // -> Comparison failure is not an object. Lets use exception message instead 
    $message = $e->getMessage(); 
} 

에 그리고 onNotSuccessfulTest()의 마지막에 변경된 경우 one commit in PHPUnit 3.6

$message = $e->getComparisonFailure()->toString(); 

에 의해 도입 된 두 문제를 생각한다

두 변경 사항 모두 PHPUnit-Selenium 프로젝트에 반영되기를 바랍니다. 적어도 PEAR에서 PHPUnit 및 PHPUnit-Selenium에 대한 최신 업데이트가있는 경우 문제가 해결되었습니다.

+0

우수 답변 - 12/14/2011 – jchapa

관련 문제