如何在Laravel中检测TestCase的最后一次测试?

时间:2016-05-27 13:50:29

标签: php laravel phpunit laravel-5.2

我可以轻松检测到第一次测试:

public static $databaseMigrated = false;

protected function setUp()
{
    parent::setUp();

    if (TestCase::$databaseMigrated === false) {
           $this->migrateDatabase();
        TestCase::$databaseMigrated = true;
    }
}

但有人知道如何检测上次测试吗?

protected function tearDown()
{
    // something here ? ?
}

1 个答案:

答案 0 :(得分:0)

解决方案是:

public static $databaseMigrated = false;

public function setUp()
{
    parent::setUp();

    if (TestCase::$databaseMigrated === false) {
        TestCase::$databaseMigrated = true;
        register_shutdown_function(function(){
            //register wanted code here
        });
    });
}