Php Silverstrip单元测试夹具_文件不工作
我正在学习SilverStripe,同时也在尝试将单元测试集成到我的简单项目中。我正在尝试使用$fixture\u文件为数据种子。但它不起作用 这是我的phpunit.xmlPhp Silverstrip单元测试夹具_文件不工作,php,phpunit,silverstripe,functional-testing,silverstripe-4,Php,Phpunit,Silverstripe,Functional Testing,Silverstripe 4,我正在学习SilverStripe,同时也在尝试将单元测试集成到我的简单项目中。我正在尝试使用$fixture\u文件为数据种子。但它不起作用 这是我的phpunit.xml <phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true"> <testsuite name="Default"> <directory>app/test
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>app/tests</directory>
</testsuite>
<groups>
<exclude>
<group>sanitychecks</group>
</exclude>
</groups>
</phpunit>
这是我的固定装置
ContactFormSubmission:
wai:
Name: Wai
Email: iljimae.ic@gmail.com
Message: ThisIsAMessage
这是我的ContactFormSubmission.php
<?php
namespace {
use SilverStripe\ORM\DataObject;
class ContactFormSubmission extends DataObject
{
private static $db = [
'Name' => 'Varchar',
'Email' => 'Varchar',
'Message' => 'Text',
];
}
}
我发现它无法连接到数据库。我尝试像这样覆盖phpunit.xml中的数据库配置
<env name="SS_DATABASE_NAME" value="test"/>
但它仍在尝试连接到临时数据库。如何在Silverstripe中为单元测试定义数据库?无法为SS中当前的测试设置DB名称。如果您没有在生产或UAT服务器上运行测试(您不应该),那么我建议让一个DB用户拥有创建和删除数据库的权限,以使其正常工作。无法为SS中当前的测试设置DB名称。如果您没有在生产服务器或UAT服务器上运行测试(您不应该),那么我建议让一个DB用户拥有创建和删除数据库的权限,以使其正常工作。
Time: 1.06 seconds, Memory: 16.00MB
There was 1 error:
1) PageTest::testMyMethod
SilverStripe\ORM\Connect\DatabaseException: Couldn't run query:
CREATE DATABASE "ss_tmpdb_1558273911_5783864" DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci
42000-1044: Access denied for user 'wai'@'%' to database 'ss_tmpdb_1558273911_5783864'
/var/www/vendor/silverstripe/framework/src/ORM/Connect/DBConnector.php:64
/var/www/vendor/silverstripe/framework/src/ORM/Connect/PDOConnector.php:398
/var/www/vendor/silverstripe/framework/src/ORM/Connect/PDOConnector.php:287
/var/www/vendor/silverstripe/framework/src/ORM/Connect/Database.php:143
/var/www/vendor/silverstripe/framework/src/ORM/Connect/Database.php:228
/var/www/vendor/silverstripe/framework/src/ORM/Connect/Database.php:144
/var/www/vendor/silverstripe/framework/src/ORM/Connect/MySQLDatabase.php:381
/var/www/vendor/silverstripe/framework/src/ORM/Connect/DBSchemaManager.php:120
/var/www/vendor/silverstripe/framework/src/ORM/Connect/MySQLSchemaManager.php:231
/var/www/vendor/silverstripe/framework/src/ORM/Connect/Database.php:830
/var/www/vendor/silverstripe/framework/src/ORM/Connect/TempDatabase.php:190
/var/www/vendor/silverstripe/framework/src/Dev/State/FixtureTestState.php:44
/var/www/vendor/silverstripe/framework/src/Dev/State/SapphireTestState.php:68
/var/www/vendor/silverstripe/framework/src/Dev/SapphireTest.php:274
/var/www/vendor/phpunit/phpunit/phpunit:52
<env name="SS_DATABASE_NAME" value="test"/>