如何在代码接收中检索当前的名称?

时间:2019-06-17 12:24:11

标签: php testing codeception

我想在测试中使用cest名称,但无法检索它。 根据{{​​3}},可以检索函数名称。这对我有用:

 public function tryToTest(UnitTester $I, \Codeception\Scenario $scenario) {
        codecept_debug($scenario->current("name")); // outputs tryToTest

}

如何类似地检索cest类名称?最好不要使用get_class($this)之类的东西。我也想在助手中使用cest名称。

非常感谢您。

1 个答案:

答案 0 :(得分:1)

我自己找到了解决方案。使用辅助类和描述符类中的钩子,可以生成唯一的测试标识符,该标识符看起来很像我要寻找的标识符。该问题的正确密钥似乎是env

    public function _before(\Codeception\TestInterface $test) {
        $id = \Codeception\Test\Descriptor::getTestSignatureUnique($test);
        codecept_debug($id);
    }