测试 class 未指定或无效
test class is not specified or invalid
我需要 运行 对控制台命令进行一些测试,在测试 运行 之前,每个测试都会对数据库进行一些小的更改。我的结构如下:
class ActionRemindCommandEmail extends KernelTestCase
{
private $mailCollector;
/**
* @return mixed
*/
public function getMailCollector()
{
return $this->mailCollector;
}
/**
* @param mixed $mailCollector
*/
public function setMailCollector($mailCollector)
{
$this->mailCollector = $mailCollector;
}
protected function setUp()
{
exec('mysql database < prep.sql');
}
public function testExecute()
{
exec('echo "' . str_replace('"', '\"', $this->getPrepSql() ) . '" | mysql database');
self::bootKernel();
$application = new Application(self::$kernel);
$application->add(new ActionRemindCommand());
$client = static::createClient();
$client->enableProfiler();
$this->setMailCollector($client->getProfile()->getCollector('swiftmailer'));
$command = $application->find('app:ahp:remind');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'command' => $command->getName(),
'email' => ''
));
$output = $commandTester->getDisplay();
$this->assertions();
}
}
第一次实际测试是这样的
class ActionRemindCommandVetNotifyWhenSavedOnlyTest extends ActionRemindCommandEmailTest
{
protected function getPrepSql()
{
return "INSERT INTO `action` (farmer_id`, `group_id`, `name`, `due`, `active`, `completed`, `notify_vet_email`, `notify_farmer_email`, `notify_vet_text`, `notify_farmer_text`, `notify_tech_text`, `notify_clinic_email`, `notify_farmer_text2`, `notified_vet_email`, `notified_farmer_email`, `notified_clinic_email`, `notified_vet_text`, `notified_farmer_text`, `notified_farmer_text2`, `notified_tech_text`, `notify_vet_email_advance`, `notify_farmer_email_advance`, `notify_clinic_email_advance`, `notify_vet_text_advance`, `notify_farmer_text_advance`, `notify_farmer_text2_advance`, `notify_tech_text_advance`, `no_time`, `notes`, `pending_offline_id`) VALUES "
. " (116, NULL, 'Action 1', '"
. date('Y-m-d H:i:s',mktime(12,0,0,intval(date('n')), intval(date('j'))+14,intval(date('Y'))))
. "', 1, 0, 1, 0, 0, 0, 0, 0, 0, '000', '000', '000', '000', '000', '000', '000', -1, -1, -1, 24, 24, 24, 24, 0, 'undefined', 'N1478139417184')";
}
public function testExecute()
{
parent::testExecute();
}
protected function assertions()
{
$this->assertEquals(1, $this->getMailCollector()->getMessageCount());
}
}
在 phpstorm 中使用 app/phpunit 进行设置。xml.dist:
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="bootstrap.php.cache"
>
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<!--
<php>
<server name="KERNEL_DIR" value="/path/to/your/app/" />
</php>
-->
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
我发现我无法执行测试,因为"test class is not specified or invalid"
我尝试使用 scope: class 方法,但我不确定还缺少什么?
将测试作为后缀添加到父项 class 解决了问题。
如PHPUnit docs中所述:
If you point the PHPUnit command-line test runner to a directory it will look for *Test.php files.
意味着默认情况下 PHPUnit 只考虑 类 以 Test.php
结尾。
预期的测试后缀可以是changed in phpunit.xml.
看起来像这样:
<directory suffix=".test">./sourceFolder</directory>
有关详细信息,请参阅 this good answer。
我需要 运行 对控制台命令进行一些测试,在测试 运行 之前,每个测试都会对数据库进行一些小的更改。我的结构如下:
class ActionRemindCommandEmail extends KernelTestCase
{
private $mailCollector;
/**
* @return mixed
*/
public function getMailCollector()
{
return $this->mailCollector;
}
/**
* @param mixed $mailCollector
*/
public function setMailCollector($mailCollector)
{
$this->mailCollector = $mailCollector;
}
protected function setUp()
{
exec('mysql database < prep.sql');
}
public function testExecute()
{
exec('echo "' . str_replace('"', '\"', $this->getPrepSql() ) . '" | mysql database');
self::bootKernel();
$application = new Application(self::$kernel);
$application->add(new ActionRemindCommand());
$client = static::createClient();
$client->enableProfiler();
$this->setMailCollector($client->getProfile()->getCollector('swiftmailer'));
$command = $application->find('app:ahp:remind');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'command' => $command->getName(),
'email' => ''
));
$output = $commandTester->getDisplay();
$this->assertions();
}
}
第一次实际测试是这样的
class ActionRemindCommandVetNotifyWhenSavedOnlyTest extends ActionRemindCommandEmailTest
{
protected function getPrepSql()
{
return "INSERT INTO `action` (farmer_id`, `group_id`, `name`, `due`, `active`, `completed`, `notify_vet_email`, `notify_farmer_email`, `notify_vet_text`, `notify_farmer_text`, `notify_tech_text`, `notify_clinic_email`, `notify_farmer_text2`, `notified_vet_email`, `notified_farmer_email`, `notified_clinic_email`, `notified_vet_text`, `notified_farmer_text`, `notified_farmer_text2`, `notified_tech_text`, `notify_vet_email_advance`, `notify_farmer_email_advance`, `notify_clinic_email_advance`, `notify_vet_text_advance`, `notify_farmer_text_advance`, `notify_farmer_text2_advance`, `notify_tech_text_advance`, `no_time`, `notes`, `pending_offline_id`) VALUES "
. " (116, NULL, 'Action 1', '"
. date('Y-m-d H:i:s',mktime(12,0,0,intval(date('n')), intval(date('j'))+14,intval(date('Y'))))
. "', 1, 0, 1, 0, 0, 0, 0, 0, 0, '000', '000', '000', '000', '000', '000', '000', -1, -1, -1, 24, 24, 24, 24, 0, 'undefined', 'N1478139417184')";
}
public function testExecute()
{
parent::testExecute();
}
protected function assertions()
{
$this->assertEquals(1, $this->getMailCollector()->getMessageCount());
}
}
在 phpstorm 中使用 app/phpunit 进行设置。xml.dist:
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="bootstrap.php.cache"
>
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<!--
<php>
<server name="KERNEL_DIR" value="/path/to/your/app/" />
</php>
-->
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
我发现我无法执行测试,因为"test class is not specified or invalid"
我尝试使用 scope: class 方法,但我不确定还缺少什么?
将测试作为后缀添加到父项 class 解决了问题。
如PHPUnit docs中所述:
If you point the PHPUnit command-line test runner to a directory it will look for *Test.php files.
意味着默认情况下 PHPUnit 只考虑 类 以 Test.php
结尾。
预期的测试后缀可以是changed in phpunit.xml.
看起来像这样:
<directory suffix=".test">./sourceFolder</directory>
有关详细信息,请参阅 this good answer。