【发布时间】:2013-12-20 13:24:13
【问题描述】:
我正在为我使用的包开发一些新功能,但 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();
}
}
【问题讨论】: