Unit testing 单元测试期间Laravel雄辩模型重置引导属性

Unit testing 单元测试期间Laravel雄辩模型重置引导属性,unit-testing,testing,laravel,laravel-4,phpunit,Unit Testing,Testing,Laravel,Laravel 4,Phpunit,我在一个类上有一个引导方法,该类是从Eloquent的基本模型类扩展而来的。我想运行一些单元测试,我需要它在每个测试中启动。不幸的是,illumb\Database\Eloquent\Model::$booted属性的类ID索引一直存在,该属性是在我扩展的构造函数中设置的,因此它只适用于第一个测试。我尝试过调整一些phpunit的标志-我尝试过进程隔离-似乎没有任何效果 是否有一种方法可以重置此属性,以便每次测试都可以触发我的启动方法? Illuminate\Database\Eloquent\

我在一个类上有一个引导方法,该类是从Eloquent的基本模型类扩展而来的。我想运行一些单元测试,我需要它在每个测试中启动。不幸的是,
illumb\Database\Eloquent\Model::$booted
属性的类ID索引一直存在,该属性是在我扩展的构造函数中设置的,因此它只适用于第一个测试。我尝试过调整一些phpunit的标志-我尝试过进程隔离-似乎没有任何效果

是否有一种方法可以重置此属性,以便每次测试都可以触发我的启动方法?

Illuminate\Database\Eloquent\Model.php
public function __construct(array $attributes = array())
{
    if ( ! isset(static::$booted[get_class($this)])) <-- Keeps persisting
    {
        static::$booted[get_class($this)] = true;

        static::boot();
    }

    ...
}


app\models\Foo.php
class Foo extends Model {
    ...

    protected static function boot() { <-- first test to execute wins, all other calls get skipped
        ...
    }

    ...
}
illumb\Database\elount\Model.php
公共函数构造(数组$attributes=array())
{

如果(!isset(static::$booted[get_class($this)])ahh-再多研究一下,答案就出来了

我的问题基本上是这个问题的重复,它在github上引用了这个问题作为解决方案