Symfony 测试将文件上载到Behat功能文件中的表单
我对编写Behat测试套件非常陌生,目前我正在尝试通过添加测试来充实现有的功能文件,以测试上传的文件 这就是我到目前为止所想到的Symfony 测试将文件上载到Behat功能文件中的表单,symfony,testing,bdd,behat,Symfony,Testing,Bdd,Behat,我对编写Behat测试套件非常陌生,目前我正在尝试通过添加测试来充实现有的功能文件,以测试上传的文件 这就是我到目前为止所想到的 Scenario: Submitting a valid asset form and uploading a file When I submit a asset form with values: | name | type | position | active | file
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\Form接口
我说的对吗?我当前收到一个错误:
无法断言null与预期匹配
“/web/images/product/swatch/default.jpg”
我建议您为将在应用程序根目录中的behat测试中使用的文件创建一个专用文件夹结构,因为测试和测试中使用的文件对于所有开发人员都必须是一致的。我有时看到人们编写测试来上传他们本地桌面上存在的文件:)我的桌面和你的桌面会不同,因此测试失败的原因 结构
football #your application name/root
build
dummy
document
hello.doc
world.xls
image
test.jpg
behat.yml
除了其他常用设置外,还必须定义文件路径
....
....
default:
extensions:
Behat\MinkExtension\Extension:
files_path: %behat.paths.base%/build/dummy/
....
....
小黄瓜场景示例
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."
我建议您为将在应用程序根目录中的behat测试中使用的文件创建一个专用文件夹结构,因为测试和测试中使用的文件对于所有开发人员都必须是一致的。我有时看到人们编写测试来上传他们本地桌面上存在的文件:)我的桌面和你的桌面会不同,因此测试失败的原因 结构
football #your application name/root
build
dummy
document
hello.doc
world.xls
image
test.jpg
behat.yml
除了其他常用设置外,还必须定义文件路径
....
....
default:
extensions:
Behat\MinkExtension\Extension:
files_path: %behat.paths.base%/build/dummy/
....
....
小黄瓜场景示例
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."
简单来说,你的目标是上传文件吗?简单来说,你的目标是上传文件吗?