我正在嘗試將一堆助手自動加載到測驗套件中。助手位于測驗套件之外的檔案夾中,希望我可以在需要時在多個專案中重用它們。
這幾乎就是我所擁有的:
- helpers
- TestHelper.php
- tests
- _data
- _output
- _support
- _generated
- Helper
- Integration.php
- IntegrationTester.php
- integration
- bootstrap.php
- integration.suite.yml
- vendor
- codeception.yml
這是引導檔案
// bootstrap.php
<?php
\Codeception\Util\Autoload::addNamespace( "awesome\helpers", __DIR__ . "../helpers" );
這是全域組態檔:
// codeception.yml
bootstrap: bootstrap.php
namespace: main
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
這是集成套件的組態檔:
// integration.suite.yml
actor: IntegrationTester
modules:
enabled:
- \awesome\helpers\TestHelper
- \main\Helper\Integration
這是測驗助手:
<?php
namespace awesome\helpers;
class TestHelper extends \Codeception\Module{
public function sayHello() {
return "Hello";
}
}
一旦我這樣做codecept run,我就會收到以下錯誤:
模塊 \awesome\helpers\TestHelper 無法找到和加載
我沒有發布任何測驗,因為它無關緊要,在執行任何測驗之前都會引發錯誤,因為它是配置問題。
據我了解,全域組態檔應該在運行測驗之前運行引導檔案,并且引導檔案中的 Autoload 類應該在awesome\helpers命名空間中加載幫助程式,但這顯然不會發生。我究竟做錯了什么?
uj5u.com熱心網友回復:
我認為你犯了一個經典的錯誤并且/之前錯過了,..所以你設定了路徑tests../helpers。
改變
\Codeception\Util\Autoload::addNamespace( "awesome\helpers", __DIR__ . "../helpers" );
到
\Codeception\Util\Autoload::addNamespace( "awesome\helpers", __DIR__ . "/../helpers" );
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/461966.html
上一篇:獲取前2個單詞和符號
