如何选择在Laravel3.x中运行哪些PHPUnit测试?
我使用php artisan test来执行我的测试,但是现在我有太多的测试,我希望能够选择运行哪一个。我熟悉PHPUnit中的测试组,只是不知道如何将其应用于Laravel,因为PHPUnit.xml是在这里动态生成的如何选择在Laravel3.x中运行哪些PHPUnit测试?,phpunit,laravel,laravel-3,Phpunit,Laravel,Laravel 3,我使用php artisan test来执行我的测试,但是现在我有太多的测试,我希望能够选择运行哪一个。我熟悉PHPUnit中的测试组,只是不知道如何将其应用于Laravel,因为PHPUnit.xml是在这里动态生成的 谢谢您可以将PHPUnit测试与分组。我想您也可以参考artisan的这一组: 您可以将@group放在测试类上,也可以只放在测试方法上。您可以在一个类/方法上放置多个组。这样您就可以组织它们。如果不修改几个Laravel的核心文件,就不可能做到这一点。 我非常需要这个功能,所
谢谢您可以将PHPUnit测试与分组。我想您也可以参考artisan的这一组:
您可以将@group放在测试类上,也可以只放在测试方法上。您可以在一个类/方法上放置多个组。这样您就可以组织它们。如果不修改几个Laravel的核心文件,就不可能做到这一点。 我非常需要这个功能,所以继续向Laravel添加了这个功能 以下内容适用于Laravel 3: 打开Laravel/cli/tasks/tests/runner.php,并用以下内容替换bundle函数:
public function bundle($bundles = array())
{
if (count($bundles) == 0)
{
$bundles = Bundle::names();
}
$is_bundle = false;
$this->base_path = path('sys').'cli'.DS.'tasks'.DS.'test'.DS;
foreach ($bundles as $bundle)
{
// To run PHPUnit for the application, bundles, and the framework
// from one task, we'll dynamically stub PHPUnit.xml files via
// the task and point the test suite to the correct directory
// based on what was requested.
if (is_dir($path = Bundle::path($bundle).'tests'))
{
$this->stub($path);
$this->test();
$is_bundle = true;
}
}
if (!$is_bundle)
{
$this->stub($path);
// Run a specific test group
$this->test($bundles[0], $bundles[1]);
}
}
protected function test($group = null, $file = null)
{
// We'll simply fire off PHPUnit with the configuration switch
// pointing to our requested configuration file. This allows
// us to flexibly run tests for any setup.
$path = 'phpunit.xml';
// fix the spaced directories problem when using the command line
// strings with spaces inside should be wrapped in quotes.
$esc_path = escapeshellarg($path);
$group_string = '';
if ($group)
{
$group_string = '--group ' . $group . ' ';
if ($file)
{
$group_string .= path('app') . 'tests/' . $file . '.test.php';
}
else
{
$group_string .= path('app') . 'tests/' . $group . '.test.php';
}
}
passthru('phpunit --configuration '.$esc_path.' '.$group_string, $status);
@unlink($path);
// Pass through the exit status
exit($status);
}
然后,将测试功能替换为以下功能:
public function bundle($bundles = array())
{
if (count($bundles) == 0)
{
$bundles = Bundle::names();
}
$is_bundle = false;
$this->base_path = path('sys').'cli'.DS.'tasks'.DS.'test'.DS;
foreach ($bundles as $bundle)
{
// To run PHPUnit for the application, bundles, and the framework
// from one task, we'll dynamically stub PHPUnit.xml files via
// the task and point the test suite to the correct directory
// based on what was requested.
if (is_dir($path = Bundle::path($bundle).'tests'))
{
$this->stub($path);
$this->test();
$is_bundle = true;
}
}
if (!$is_bundle)
{
$this->stub($path);
// Run a specific test group
$this->test($bundles[0], $bundles[1]);
}
}
protected function test($group = null, $file = null)
{
// We'll simply fire off PHPUnit with the configuration switch
// pointing to our requested configuration file. This allows
// us to flexibly run tests for any setup.
$path = 'phpunit.xml';
// fix the spaced directories problem when using the command line
// strings with spaces inside should be wrapped in quotes.
$esc_path = escapeshellarg($path);
$group_string = '';
if ($group)
{
$group_string = '--group ' . $group . ' ';
if ($file)
{
$group_string .= path('app') . 'tests/' . $file . '.test.php';
}
else
{
$group_string .= path('app') . 'tests/' . $group . '.test.php';
}
}
passthru('phpunit --configuration '.$esc_path.' '.$group_string, $status);
@unlink($path);
// Pass through the exit status
exit($status);
}
这个解决方案有点老套,但它完成了任务
简而言之,要运行PHPUnit的特定测试组,请从命令行运行以下命令:
php artisan test group_name_here
这将从与组同名的文件(groupname.test.php)运行组。
要在特定文件中运行特定组,请指定组名,然后指定文件名的第一部分:
php artisan test mygroupname myfilename
我想,您可以随时添加功能,允许它从目录中的所有文件运行组名
我希望这能帮助其他需要该功能的人:)我假设bundle name会起作用。。。现在我正在读一点关于拉雷维尔的文章,请跟quick谈谈。然而,这应该是可能的,因为这个测试包()使用这个@group注释。也许这就是诀窍?php artisan test:()。我刚刚尝试了php artisan test:my_group_name,我只是得到了“抱歉,我找不到该方法!”抱歉,我浏览了laravel的源代码,但没有看到传递额外参数的选项。配置文件phpunit.xml是动态生成的,因此也没有选项。也许更多有知识的laravel用户可以帮助您找到解决方案。我也在看类似的东西?