你有很多選擇,但我只是讓你們兩個現在這樣比較多,你可以做自己的研究:
這是很多人會做:
特性文件:
Scenario: Checking pages and their content
Given I am on "/"
Then I should see "welcome home"
When I am on "/contact"
Then I should see "welcome to contact page"
When I am on "/about-me"
Then I should see "welcome to about me page"
When I am on "/whatever"
Then I should see "welcome to whatever page"
......
......
這是驗證文件的物理存在的另一種選擇:
特性文件:
Scenario: Checking pages and but not their content
Given I am on "/"
Then I should see "welcome home"
And the files below must exist in my project folder:
| file |
| /path/to/my/project/files/contact.tml |
| /path/to/my/project/files/about-me.tml |
| /path/to/my/project/files/whatever.tml |
在你FeatureContext文件:
class FeatureContext extends MinkContext
{
/**
* @When /^the files below must exist in my project folder:$/
*/
public function theFilesBelowMustExistInMyProjectFoder(TableNode $table)
{
foreach ($table->getHash() as $file) {
if (file_exists($file) !== true) {
throw new Exception(sprintf('File "%s" not found', $file));
}
}
}
}
感謝那些非常有意義,現在我有一個想法從哪裏開始 –