我是编写Behat测试套件的新手,我目前正在尝试使用添加的测试来充实现有的功能文件,以测试上传的文件。
这是我到目前为止所提出的。
Scenario: Submitting a valid asset form and uploading a file
When I submit a asset form with values:
| name | type | position | active | file |
| St Andrews Release | image | 1 | 1 | /web/images/product/icon/default.jpg |
Then the form should be valid
And the entity form entity should have the following values
| name | type | position | active | file |
| St Andrews Release | image | 1 | 1 | /web/images/product/icon/default.jpg |
Failed asserting that null matches expected '/web/images/product/icon/default.jpg'.
And the entity form entity should be persisted correctly
这是处理场景的方法:
/**
* @When I submit a asset form with values:
*/
public function iSubmitAssetFormWithValues(TableNode $table)
{
$data = $table->getColumnsHash()[0];
$this->form = $this->submitTheForm('crmpicco.asset.type', $this->entity, $data);
}
submitTheForm
方法返回Symfony\Component\Form\FormInterface
。
我是否沿着正确的路线走?我目前收到错误:
声明null匹配预期失败 ' /web/images/product/swatch/default.jpg'
答案 0 :(得分:2)
我建议您为文件创建一个专用的文件夹结构,这些文件将在您的应用程序根目录中用于behat测试,因为测试和测试中使用的文件必须对所有开发人员保持一致。我有时会看到人们编写测试来上传本地桌面上存在的文件:)我的桌面和桌面会有所不同,因此测试会失败。
<强>结构强>
football #your application name/root
build
dummy
document
hello.doc
world.xls
image
test.jpg
<强> behat.yml 强>
除了其他常见设置外,您还必须定义file_path
。
....
....
default:
extensions:
Behat\MinkExtension\Extension:
files_path: %behat.paths.base%/build/dummy/
....
....
Gherkin示例方案
Feature: I can upload a file which is stored in my generic "dummy" folder
Scenario: I can upload image
Given I am on "/"
When I attach the file "image/test.jpg" to "league_flag"
And I press "Submit"
Then I should see "Succeeded."