我正在为我使用的软件包开发一些新功能,但是PHPUnit正在抛出一个没有任何错误消息的异常。
代码:
use Bootstrapper\Modal;
class ModalTest extends BootstrapperWrapper
{
public function testCanOpenModel() {
$modal = Modal::create();
$matcher = array(
'tag' => 'div',
'attributes' => array(
'class' => 'modal'
),
);
$this->assertHTML($matcher, $modal);
}
}
AssertHTML只是我们使用的assertTag的包装器,因此我们可以提供有用的错误消息。
class Modal {
protected static $modal = null;
protected $attributes;
protected $header;
protected $body;
protected $footer;
public static function create($attributes = null, $header = null, $body = null, $footer = null) {
static::$modal = new static($attributes, $header, $body, $footer);
}
public function __construct($attributes, $header, $body, $footer) {
$this->attributes = $attributes;
$this->header = $header;
$this->body = $body;
$this->footer = $footer;
}
public function render() {
$this->attributes = Helpers::add_class($this->attributes, 'modal');
$string = "<div" . Helpers::getContainer('html')->attributes($this->$attributes) . ">";
return $string . "</div>";
}
public function __toString() {
return $this->render();
}
}
答案 0 :(得分:0)
$this->$attributes = Helpers::add_class($attributes, 'modal');
$string = "<div" . Helpers::getContainer('html')->attributes($this->$attributes) . ">";
将$this->$attributes
更改为$this->attributes
,将$attributes
更改为$this->attributes
。
很难说这是否会导致您的问题,但请尝试一下。
答案 1 :(得分:0)
发现了这个问题。 create方法没有返回任何东西(因此给我留空),这使PHPunit框架错误。为什么它没有给出错误信息是任何人的猜测。