2011-10-31 20 views
3

私はPHP 5.3.6とGithubの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(); 

$ E-> getComparisonFailure(NULL、いないオブジェクトを返します。私は間違って何をしていますか?

UPDATE:修正はまだ私の地平線上にありませんが

私は、失敗の理由を発見しました。 PHPUnitの/フレームワーク/ Constraint.phpのライン92に

、それはのように定義される

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

使用呼び出し:NULLは、何PHPUnit_Framework_ComparisonFailureが渡されないので

protected function fail($other, $description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL)

をPHPUnit/Framework/Constraint.phpの141行目に渡されました

スロー新しいPHPUnit_Framework_ExpectationFailedException( $ failureDescription、 $ comparisonFailure)。

上記のように、オブジェクトを返すことになっているgetComparisonFailure()によってフェッチされます。

これ以上のアイデアはありませんか?

+0

phpunit-seleniumのデフォルトのコピー貼り付けの例では、コピーと貼り付けが失敗する唯一のアサーションが失敗したときにバグがありますか? –

答えて

4

ちょうどそれは私がする$message = $e->getComparisonFailure()->toString();を置き換え

+0

$ e-> getComparisonFailureによって返されたオブジェクトがNULLであり、メソッドとして "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プロジェクト私はこの問題を修正するコミットを1つ作成し、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プロジェクトに受け入れられることを望みます。少なくとも、PEUのPHPUnitとPHPUnit-Seleniumの最新のアップデートで問題が解決しました。

+0

ベストアンサー - 12/14/2011 – jchapa

関連する問題