我试图在symfony2中的behat测试中使用sqlite基础。就我而言,symfony2中的behat找到我的基地,并且可以在其中创建固定装置。问题是我的测试网站无法连接到这个基地。Symfony2无法连接到sqlite
这是我config_test.yml
:
doctrine:
dbal:
driver: pdo_sqlite
host: 127.0.0.1
dbname: "%database_name%_test"
path: tests/eg_test.db
这是我config.yml
:
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
这是我behat.yml
:
default:
suites:
default:
paths:
features: '%paths.base%/features'
bootstrap: '%paths.base%/features/bootstrap'
contexts:
- FeatureContext: ~
- EwidencjaContext:
userManager: '@fos_user.user_manager'
em: '@doctrine.orm.entity_manager'
packageManager: '@em.package_manager'
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://nginx/app_test.php
goutte: ~
selenium2:
browser: "chrome"
wd_host: http://selenium_chrome:4444/wd/hub
capabilities: { "browserName": "chrome", "browser": "chrome"}
Bex\Behat\ScreenshotExtension:
image_drivers:
local:
screenshot_directory: tests/features/images/
clear_screenshot_directory: true
这是记录我回来尝试登录后进入我的网站。用户是否存在并不重要。所以它不是错误的密码或类似的东西。似乎网站只是不连接到基地。
[2017-03-27 10:22:09] request.INFO:匹配的路由“fos_user_security_check”。 {“route”:“fos_user_security_check”,“route_parameters”:{“_ controller”:“FOS \ UserBundle \ Controller \ SecurityController :: checkAction”,“_ route”:“fos_user_security_check”},“request_uri”:“http://localhost/app_test.php/login_check” “:”POST“} [] [2017-03-27 10:22:10] security.INFO:身份验证请求失败。 {“exception”:“[object](Symfony \ Component \ Security \ Core \ Exception \ AuthenticationServiceException(代码:0):驱动程序中发生异常:SQLSTATE [HY000] [14]无法在/ var/www中打开数据库文件/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php:94,Doctrine \ DBAL \ Exception \ ConnectionException(代码:0):驱动程序中发生异常:SQLSTATE [HY000] [14]无法在/var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php:82,Doctrine \ DBAL \ Driver \ PDOException(代码:14)中打开数据库文件:SQLSTATE [HY000 ] [14]无法在/var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47,PDOException(代码:14):SQLSTATE [HY000] [14]无法打开数据库文件打开数据库文件在/var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)“} [] [2017-03-27 10:22:10] security.DEBUG :身份验证失败,重定向触发。 {“failure_path”:“/ login”} [] [2017-03-27 10:22:10] request.INFO:匹配的路由“fos_user_security_login”。 {“route”:“fos_user_security_login”,“route_parameters”:{“_ controller”:“FOS \ UserBundle \ Controller \ SecurityController :: loginAction”,“_ route”:“fos_user_security_login”},“request_uri”:“http://localhost/app_test.php/login”,“ “:”GET“} [] [2017-03-27 10:22:10] security.INFO:用一个匿名令牌填充TokenStorage。 [] []
这是错误我得到我的网站上,当我尝试从浏览器登录:
认证请求不能因系统问题进行处理。
和错误,当我尝试注册新用户:
在驾驶时发生异常:SQLSTATE [HY000] [14]无法打开数据库文件
我创造了我的SQLite数据库接近标准的MySQL基地即时通讯使用prod。之后我用bin/console doctrine:schema:update --force --env=test
。我的数据库得到了很好的文件mod(-rwxrwxr-x),并被正确的用户和组使用。
This works great!谢谢。我只是不明白一件事。这个default.db是自动生成的。由于它在缓存目录中生病会丢失它,如果生病缓存清除。我怎么能告诉它与我的桌子和灯具生成基地? – Megami
好吧,我发现代码重置behat中的图像数据库。 '/ ** * @ BeforeScenario * * @Given数据库是干净 */ 公共函数theDatabaseIsClean() { EXEC( 'PHP的应用程序/控制台高速缓存:清楚--env =试验'); exec('php app/console doctrine:database:create --env = test --force'); exec('php app/console doctrine:schema:update --env = test --force'); exec('cp tests/features/database/eg_test.db var/cache/test/default.db'); }' – Megami
你可以用Symfony + Behat的方式做到这一点,如下所示:[在symfony的特征上下文文件中的每个behat场景之前加载学说数据装置](http://www.inanzzz.com/index.php/post/ ypah /加载-学说-数据灯具前方的每个-贝哈特-场景中之特征的上下文的文件的-symfony的) – BentCoder