Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Locked History Actions

Mockery

Mockery

バグ

2010/12/24時点のバージョン0.6のバグとその対処

PHP 5.3.6のバグによるSegmentation Fault

PHP 5.3.6のバグにより、以下のような単純なコードを実行するとSegmentation Faultが発生する。原因は不明。

<?php
include 'Mockery/Loader.php';
$loader = new \Mockery\Loader;
$loader->register();

$a = \Mockery::mock('foo');        
$a->shouldReceive('exec');

?>

※PHP 5.3.5では発生しない。PHPは言語仕様としてもレベルの低いものだが、実装技術も低水準であるので注意が必要。

参照渡しのメソッドのあるインターフェース等からモック作成しようとするとエラー

interface CouldNotMock {
  public function someMethod(&$reference);  
}
$mock = \Mockery::mock('CouldNotMock');

を実行すると、

Fatal error: Declaration of Mockery_4d141dd0a5cc0::someMethod() must be compatible with that of CouldNotMock::someMethod() in /usr/share/pear/Mockery/Generator.php(82) : eval()'d code on line 1

というエラーが発生する。

修正箇所はMockery/Generator.phpの中の_replacePublicMethod(\RefelectionMethod $method)の以下の部分。

            $paramDef = '';
            if ($param->isArray()) {
                $paramDef .= 'array ';
            } elseif ($param->getClass()) {
                $paramDef .= $param->getClass()->getName() . ' ';
            }
            if ($param->isPassedByReference()) $paramDef .= "&"; // !!!!! この行を追加 !!!!
            $paramDef .= '$' . $param->getName();
            if ($param->isOptional()) {
                $paramDef .= ' = ';
                if ($param->isDefaultValueAvailable()) {
                    $paramDef .= var_export($param->getDefaultValue(), true);
                }
            }
            $methodParams[] = $paramDef;

マニュアル