【发布时间】:2015-08-08 10:39:08
【问题描述】:
Behat 是一个非常好的工具,恕我直言,BDD/TDD/DDD 是 SOLID 编码的基础,但是 ...
我经常看到使用 Behat 的项目具有未经测试的相当复杂的上下文类。
例如:Sylius/TaxonomyContext 或 Sylius/ProductContext
/**
* @Given /^taxonomy "([^""]*)" has following taxons:$/
*/
public function taxonomyHasFollowingTaxons($taxonomyName, TableNode $taxonsTable)
{
$taxonomy = $this->findOneByName('taxonomy', $taxonomyName);
$manager = $this->getEntityManager();
$taxons = array();
foreach ($taxonsTable->getRows() as $node) {
$taxonList = explode('>', $node[0]);
$parent = null;
foreach ($taxonList as $taxonName) {
$taxonName = trim($taxonName);
if (!isset($taxons[$taxonName])) {
/* @var $taxon TaxonInterface */
$taxon = $this->getRepository('taxon')->createNew();
$taxon->setName($taxonName);
$taxons[$taxonName] = $taxon;
}
$taxon = $taxons[$taxonName];
if (null !== $parent) {
$parent->addChild($taxon);
} else {
$taxonomy->addTaxon($taxon);
}
$parent = $taxon;
}
}
$manager->persist($taxonomy);
$manager->flush();
}
这个例子不是“火箭科学”,但它有很多地方是行不通的。 根据我的经验,Behat Contexts 可能会变得相当复杂。
我是否也应该如此“信任”我的上下文并假设它们 100% 正确工作? 或者是否有任何指南/教程如何测试 Behat Contexts?
你是做什么的?你怎么做呢?
【问题讨论】:
-
@aemxdp 在引用其他网站时,指出cross-posting is frowned upon 通常会有所帮助。另请参阅:What goes on Programmers.SE? A guide for Stack Overflow
-
@gnat,哎呀,我是新手,谢谢。
标签: php unit-testing bdd behat