首页 > 解决方案 > SilverStripe Behat 抛出错误:在 null 上调用成员函数 manage() (Behat\Testwork\Call\Exception\FatalThrowableError)

问题描述

我正在从事 SilverStripe 项目。我正在使用 Behat 为我的应用程序编写行为测试。但是当我运行测试时,我在控制台中遇到错误。以下是我为我的项目设置 Behat 的方式。

我创建了一个具有以下定义的功能文件

Feature: ls
    In order to see the directory structure
    As a UNIX user
    I need to be able to list the current directory's contents

    Scenario: List 2 files in a directory
        Given I am in a directory "test"
        And I have a file named "foo"
        And I have a file named "bar"
        When I run "ls"
        Then I should get:
            """
            bar
            foo
            """

这是我的测试课

class FeatureContext extends SilverStripeContext
{
    /**
     * @Given I am in a directory :arg1
     */
    public function iAmInADirectory($arg1)
    {
        return new PendingException();
    }

    /**
     * @Given I have a file named :arg1
     */
    public function iHaveAFileNamed($arg1)
    {
        return new PendingException();
    }

    /**
     * @When I run :arg1
     */
    public function iRun($arg1)
    {
        return new PendingException();
    }

    /**
     * @Then I should get:
     */
    public function iShouldGet(PyStringNode $string)
    {
        assertEquals(1, 1);
    }
}

当我运行测试时,我在控制台中收到以下抱怨。

 ┌─ @BeforeScenario # SilverStripe\Framework\Tests\Behaviour\FeatureContext::before()
  │
  ╳  Fatal error: Call to a member function manage() on null (Behat\Testwork\Call\Exception\FatalThrowableError)
  │

我的代码有什么问题,如何摆脱该错误?

标签: unit-testingsilverstripebehatsilverstripe-4

解决方案


推荐阅读