Php Behat不将其他类自动加载到测试上下文

Php Behat不将其他类自动加载到测试上下文,php,behat,Php,Behat,Behat版本3.0.12,PHP 5.3.3 在显示我的设置之前,我将描述这个问题:我正在创建一个小的测试Behat项目,但是当我尝试在其他文件中创建附加类以拉入上下文文件时,Behat不会自动加载它们。文档说,features/bootstrap中的任何内容都应该自动加载并可用。具体错误如下: Fatal error: Class 'TestObject' not found in /data/drupal7/sites/behat-test/projects/test-project/fe

Behat版本3.0.12,PHP 5.3.3

在显示我的设置之前,我将描述这个问题:我正在创建一个小的测试Behat项目,但是当我尝试在其他文件中创建附加类以拉入上下文文件时,Behat不会自动加载它们。文档说,
features/bootstrap
中的任何内容都应该自动加载并可用。具体错误如下:

Fatal error: Class 'TestObject' not found in /data/drupal7/sites/behat-test/projects/test-project/features/bootstrap/TestContext.php on line 23
在中,教程在一个新的PHP文件中定义了一个类,并轻松地将其引入。在我的版本上尝试同样的方法是行不通的

我有这样的行为设置:

composer.*
projects
vendor
default:
    suites:
        default:
            paths:     [ %paths.base%/features ]
            bootstrap: [ $paths.features%/bootstrap ]
            contexts:  [ TestContext ]
<?php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

/**
 * Behat context class.
 */
class TestContext implements Context
{
    private $test;

    public function __construct()
    {
        $this->test = new TestObject();
    }

    /**
     * @Given I go to the Google homepage
     */
    public function iGoToTheGoogleHomepage()
    {
        throw new PendingException();
    }
}
这是安装Behat的标准结果,除了有一个新文件夹,其中我的各个项目在
project/
中都有自己的文件夹。例如,
project/test\u project

behat.yml
features
    |-- test.feature
    |-- bootstrap
           |-- TestContext.php
           |-- Test.php
我的配置文件,
behat.yml
如下所示:

composer.*
projects
vendor
default:
    suites:
        default:
            paths:     [ %paths.base%/features ]
            bootstrap: [ $paths.features%/bootstrap ]
            contexts:  [ TestContext ]
<?php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

/**
 * Behat context class.
 */
class TestContext implements Context
{
    private $test;

    public function __construct()
    {
        $this->test = new TestObject();
    }

    /**
     * @Given I go to the Google homepage
     */
    public function iGoToTheGoogleHomepage()
    {
        throw new PendingException();
    }
}
TestContext.php
如下所示:

composer.*
projects
vendor
default:
    suites:
        default:
            paths:     [ %paths.base%/features ]
            bootstrap: [ $paths.features%/bootstrap ]
            contexts:  [ TestContext ]
<?php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

/**
 * Behat context class.
 */
class TestContext implements Context
{
    private $test;

    public function __construct()
    {
        $this->test = new TestObject();
    }

    /**
     * @Given I go to the Google homepage
     */
    public function iGoToTheGoogleHomepage()
    {
        throw new PendingException();
    }
}

有什么想法吗?

发现额外的文件需要遵循PSR-0标准-在这种情况下,
TestObject
类需要位于具有相同名称的文件中,例如
TestObject.php

URL不推荐使用。
<?php

final class TestObject {
    private $price = 0;

    public function setPrice($amount) {
        $this->price = $amount;
    }

    public function getPrice() {
        return $this->price;
    }
}