[英]Testing CakePhp3 plugin -> Error loading plugin / missing class
實際上是在Bootstrap 3插件上工作的,everythinks現在可以工作了。 我想用php Unit測試一切開發測試!
但是當我打電話給php unit時,他說他沒有找到這樣的類:
致命錯誤:在第26行的C:\\ wamp3 \\ www \\ wac_lucien \\ BsHelpers \\ BsHelpersCakePHP3 \\ 3.2 \\ plugins \\ BsHelpers \\ tests \\ TestCase \\ View \\ Helper \\ BsHelpersTest.php中找不到類'BsHelpers \\ View \\ Helper \\ BsHelper'
因此,在嘗試完全遵循CakePHP3的文檔之后,我在一開始遇到了問題。 現在我只知道:
<?php
namespace BsHelpers\Test\TestCase\View\Helper;
use BsHelpers\View\Helper\BsHelper;
use Cake\TestSuite\TestCase;
use Cake\View\View;
class BsHelperTest extends TestCase
{
public function setUp()
{
parent::setUp();
$this->View = new View();
$this->Bs = new BsHelper($this->View);
}
public function testBar()
{
}
}
我認為問題可能出在bootstrap.php中。 插件加載程序的路徑可能為false,但我不知道如何設置...
Plugin::load('BsHelpers', ['path' => ROOT . DS]);
在我的插件的composer.json中,我得到了:
"autoload": {
"psr-4": {
"App\\": "src",
"BsHelpers\\": "./plugins/BsHelpers/src",
"BsHelpers\\Test\\": "./plugins/BsHelpers/tests"
}
},
我調用php單元測試(在我的插件文件夾中)
vendor\bin\phpunit
我的phpunit.xml.dist看起來像
<phpunit
colors="true"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
<testsuite name="BsHelpers Test Cases">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
我為什么在運行測試期間無法訪問助手?
伙計們,我真的需要想法
更新
我再次嘗試運行測試。 我發現了錯誤並更改了行,但是我不明白為什么這會給測試帶來麻煩。
Initialy我試圖理解CakePHP3插件,通過與工作從friendsofcake這個插件 ,當我做了我的插件(插入更多的功能)我剛才復制的composer.json看到與我的插件的結果。 只是忘了改變那一部分。
所以錯誤是在插件的composer.json中:
{
"name": "friendsofcake/bootstrap-ui",
"description": "Twitter Bootstrap 3 support for CakePHP 3",
"type": "cakephp-plugin"
}
我用
"name": "lucienleroux/bs-helpers",
而且我真的不明白為什么這可以解決問題,因為在我的插件中沒有地方設置“ lucienleroux / bs-helpers”之類的名稱。 實際上,它可以與其他任何字符串(例如“ test / bs_helpers”)一起使用...如果您了解我對答案的興趣!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.