Behat Api 测试似乎正在冲击开发环境(开发缓存文件夹已创建,并且它使用开发数据库)。
它毫无问题地创建了测试数据库并添加了数据(FeatureContext 中的 BeforeScenario 方法)。
我的设置如下:
有一个 app_test.php 前端 Controller 。
default:
formatters:
pretty: true
autoload:
'': %paths.base%/app/features/bootstrap
suites:
app_suite:
type: symfony_bundle
bundle: AppBundle
contexts:
- AppBundle\Features\Context\FeatureContext:
parameters:
base_url: http://mysite.dev
mink_session: default
mink_javascript_session: selenium2
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
sessions:
default:
symfony2: ~
这个:http://www.forouzani.com/installing-behat-mink-and-selenium2-in-symfony2.html以前可能使用过 behat 2,但我现在使用的是 behat 3,所以它似乎没有按预期工作!
谢谢
最佳答案
如果你按照下面的步骤还是不行,我有空的时候会逐步给你举个例子。
更新 composer.json
"require": {
"php": ">=5.4",
"behat/behat": "3.0.14",
"behat/behat-bundle": "1.0.0",
"behat/symfony2-extension": "2.0.0",
"behat/mink": "1.6.0",
"behat/mink-extension": "2.0.1",
"behat/mink-browserkit-driver": "1.2.0",
"behat/mink-goutte-driver": "1.1.0",
"behat/mink-selenium2-driver": "1.2.0"
},
运行 Composer
php composer.phar update
创建 behat.yml 文件。
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://behat-three.local/app_test.php
browser_name: firefox
sessions:
goutte: # fast, CLI, browser, no javascript support
goutte: ~
selenium2: # fast, CLI, opens up a browser
selenium2: ~
symfony2: # bleeding fast, CLI, no browser
symfony2: ~
suites:
test_suite:
type: symfony_bundle
bundle: SiteMainBundle
mink_session: selenium2
contexts:
- Site\MainBundle\Features\Context\FeatureContext:
output_path: build/behat/output
screen_shot_path: build/behat/screenshot
开始创建相关文件和 fodlers 以使用。
php bin/behat --init --suite=test_suite
然后确保您有 app_test.php
并更新 AppKernel
行。
# your_project/web/app_test.php
$kernel = new AppKernel('test', true);
然后用它自己的设置创建 config_test.yml
,比如。
# your_project/app/config/config_test.yml
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
storage_id: session.storage.mock_file
profiler:
collect: false
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
doctrine:
dbal:
connections:
hello:
driver: pdo_sqlite
path: %kernel.cache_dir%/test_hello.db
关于symfony - 使用 Symfony2 的 Behat 3,使用开发环境的 api 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29016902/