@忽略Laravel testcase方法上的beforeClass注释

@忽略Laravel testcase方法上的beforeClass注释,laravel,annotations,phpunit,Laravel,Annotations,Phpunit,在我的Laravel 5.1应用程序的基本测试用例中,扩展了illighted\Foundation\Testing\TestCase我有以下方法: /** * @beforeClass */ public function resetDatabase() { echo "I never see this message\n"; $this->artisan("migrate:refresh"); } 该类中的其他@before和@after注释被视为广告。为什么在我

在我的Laravel 5.1应用程序的基本测试用例中,扩展了
illighted\Foundation\Testing\TestCase
我有以下方法:

/**
 * @beforeClass
 */
public function resetDatabase()
{
    echo "I never see this message\n";
    $this->artisan("migrate:refresh");
}

该类中的其他@before和@after注释被视为广告。为什么在我的单元测试中没有调用此方法?

结果表明,所有注释都不相等

检查
vendor/phpunit/phpunit/src/Util/Test.php
显示:

private static function isBeforeClassMethod(ReflectionMethod $method)
{
    return $method->isStatic() && strpos($method->getDocComment(), '@beforeClass') !== false;
}


private static function isBeforeMethod(ReflectionMethod $method)
{
    return preg_match('/@before\b/', $method->getDocComment());
}

因此,如果我将函数设置为静态,它将在类测试之前被识别并运行。周围的@before注释示例都是实例方法,因此这导致了混淆。

鉴于您已使其正常工作,我有一个后续问题。如何从静态方法中调用Artisan命令?显然,
$this
不起作用,我试图在静态方法中使用任何facade,导致在第17行的/path to app/tests/support/DatabaseMigrations.php中找不到类似
类“Artisan”的错误消息。检查我的答案,我还有一个问题,Artisan不能从静态方法调用。