How to detect last test from TestCase in Laravel?

主宰稳场 提交于 2019-12-11 12:35:24

问题


I can easily detect first test:

public static $databaseMigrated = false;

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

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

But does anybody have idea how to detect last test ?

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

回答1:


Solution is:

public static $databaseMigrated = false;

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

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


来源:https://stackoverflow.com/questions/37485223/how-to-detect-last-test-from-testcase-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!