【发布时间】:2017-03-29 08:06:10
【问题描述】:
我有以下目录结构:
composer.json
behat.yml
src
|--AppBundle
|--Features
|--example.feature
|--Context
|--FeatureContext.php
还有下面的behat.yml
default:
autoload:
'': 'src/AppBundle/Features/Context'
suites:
default:
paths: ['src/AppBundle/Features']
contexts:
- FeatureContext:
session: '@session'
# and extensions standard for Symphony
而FeatureContext.php包含
<?php
//namespace AppBundle\Features\Context;
use Behat\Behat\Context\Context;
use Behat\MinkExtension\Context\MinkContext;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends MinkContext implements Context
{ ... }
有注释命名空间。当我运行 behat 时,现在可以正确找到上下文。当我取消注释 namespace 时出现错误:
[Behat\Behat\Context\Exception\ContextNotFoundException]
FeatureContext找不到上下文类,无法使用。
当 FeatureContext.php 中的 namespace 未注释时,如何使其工作?我对 PSR-0 和 PSR-4 不太了解,但如果问题与此有关,我会附加 composer.json 的片段。
"autoload": {
"psr-4": {
"": "src/"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
我正在寻找编码的最佳实践,所以如果我做的不好,我会投票支持适当的建议。
- 我似乎应该在 FeatureContext.php 中有 namespace,不是吗?
- 我似乎不应该在 composer.json 中使用 PSR-0,是吗?
【问题讨论】:
标签: symfony autoload behat psr-4 psr-0