???????Behat
?????????????ù?????????????????????Behat???????????ls_project??????????????
????$ ./vendor/behat/behat/bin/behat
?????????????????У??????????????
$ behat
????: ls
??????????????
??????UNIX???
?????????г????????????
????: ?г????е?2?????    # features/ls.feature:7
???? ????"test"????
???? ???????"foo"???
?? ???????"bar"???
?? ??????"ls"??
??? ???????
"""
bar
foo
"""
1 scenario (1 undefined)
5 steps (5 undefined)
0m0.54s (9.96Mb)
--- FeatureContext has missing steps. Define them with these snippets:
/**
* @Given ????:arg1????
*/
public function woZaiMuLuZhong($arg1)
{
throw new PendingException();
}
/**
* @Given ???????:arg1???
*/
public function zheGeMuLuYouWenJian($arg1)
{
throw new PendingException();
}
/**
* @When ??????:arg1??
*/
public function woYunXingHou($arg1)
{
throw new PendingException();
}
/**
* @Then ???????
*/
public function woNengKanDao(PyStringNode $string)
{
throw new PendingException();
}
?????????趨??
????Behat??????????features/ls.feature?????????????????????????С???????????и???Behat??“????????”test”????”??????????????????????????????????Behat?????????????????е????仰?????????????????????????“????”??????????Behat????????????????????????????????????????????????壺
/**
* @Given ????:arg1????
*/
public function woZaiMuLuZhong($arg1)
{
throw new PendingException();
}
?????Behat????????? features/bootstrap/FeatureContent.php?У????????$arg1?$dir??
<?php
use BehatBehatContextContext;
use BehatBehatContextSnippetAcceptingContext;
use BehatGherkinNodePyStringNode;
use BehatGherkinNodeTableNode;
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context?? SnippetAcceptingContext
{
/**
* @Given ????:dir????
*/
public function woZaiMuLuZhong($dir)
{
if (!file_exists($dir)) {
mkdir($dir);
}
chdir($dir);
}
}
???????????Behat???????????????????е?????磺”test”?????$dir????????????????????????????????????????С?
???????????????FeatureContent.php????μ?3?????裺
<?php
use BehatBehatContextContext;
use BehatBehatContextSnippetAcceptingContext;
use BehatGherkinNodePyStringNode;
use BehatGherkinNodeTableNode;
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context?? SnippetAcceptingContext
{
/**
* @Given ????:dir????
*/
public function woZaiMuLuZhong($dir)
{
if (!file_exists($dir)) {
mkdir($dir);
}
chdir($dir);
}
/**
* @Given ???????:file???
*/
public function zheGeMuLuYouWenJian($file)
{
touch($file);
}
/**
* @When ??????:command??
*/
public function woYunXingHou($command)
{
exec($command?? $output);
$this->output = trim(implode(" "?? $output));
}
/**
* @Then ???????
*/
public function woNengKanDao(PyStringNode $string)
{
if ((string) $string !== $this->output) {
throw new Exception(
"Actual output is: " . $this->output
);
}
}
}
????????????е???????——?????????????????????????????”””????????????????軀?????磺$string????????????????????(string)$string????$string->getRaw()???????????????????
?????????????????????????е???裬???????Behat??
$ ./vendor/behat/behat/bin/behat
????: ls
??????????????
??????UNIX???
?????????г????????????
????: ?г????е?2?????    # features/ls.feature:7
???? ????"test"????  # FeatureContext::woZaiMuLuZhong()
???? ???????"foo"??? # FeatureContext::zheGeMuLuYouWenJian()
?? ???????"bar"??? # FeatureContext::zheGeMuLuYouWenJian()
?? ??????"ls"??      # FeatureContext::woYunXingHou()
??? ???????         # FeatureContext::woNengKanDao()
"""
bar
foo
"""
1 scenario (1 passed)
5 steps (5 passed)
0m0.56s (10.06Mb)
??????????Behat????????в???——?????μ?????????2????????????ls?????????????????????????
??????????????????????????????????衣
????Behat??????
???????????? behat —init??????????????????????
????.
?????????? features
?????????? bootstrap
?????????? FeatureContext.php
????2 directories?? 1 file
?????κκ?Behat?й?????????features??????????????????????
????features/ - Behat??????????е? *.feature???
????features/bootstrap - ????????????е?*.php?????????κβ???????????????
????features/bootstrap/FeatureContext.php - ??????????????????豻??е?????????
????features??????
??????????????????????????????????????????????????????Gherkin??????????????????????????Щ????????
???????*.feature??????????????“????”????ls??????????????????
?????????????ù????“????”???????????????????????????????壻
???????????????????????г??????????????????????????????????????
???????????????“????”??“?籾”???????????????????????????????
??????????????е???裬???????“????”??“??”??“???”??“????”??“????”??Щ?????????????Behat?????Щ????????????????????e?????????????μ??????
??????????“ Writing Features - Gherkin Language ”
????steps??????
??????????????У??????????Behat??“???”????????????????????????Behat??????????????????????????κο?????ж????????????PHPUnit????
???????????κ???????????????Behat?????“???”???
??????????“ Defining Reusable Actions - Step Definitions ”
????????????FeatureContent
????Behat?????????????????????????????????????????????е???????衣????????????????????蹲?????????????????????????????????????