【问题标题】:PHPUnit throws a PHPUnit_Framework_Exception with no error messagePHPUnit 抛出 PHPUnit_Framework_Exception 且没有错误消息
【发布时间】: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();
    }

}

【问题讨论】:

    标签: php laravel phpunit


    【解决方案1】:
    $this->$attributes = Helpers::add_class($attributes, 'modal');
    
    $string = "<div" . Helpers::getContainer('html')->attributes($this->$attributes) . ">";
    

    $this-&gt;$attributes 更改为$this-&gt;attributes 并将$attributes 更改为$this-&gt;attributes

    很难说这是否会导致您的问题,但请尝试一下。

    【讨论】:

    • 哎呀,我是个笨蛋。可悲的是没有解决它:(
    • 你也换行$string = "&lt;div" . Helpers::getContainer('html')-&gt;attributes($this-&gt;$attributes) . "&gt;";了吗?
    • 原来我还是个笨蛋。即使这样,它也不起作用。虽然我肯定会收到一条实际的错误消息吗?
    【解决方案2】:

    发现问题。 create 方法没有返回任何东西(因此给了我 null),这使得 PHPunit 框架出错。为什么它不给出错误消息是任何人的猜测。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-12
      • 2021-05-11
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      相关资源
      最近更新 更多