测试CakePhp3插件->;加载插件时出错/缺少类


Testing CakePhp3 plugin -> Error loading plugin / missing class

实际上正在开发Bootstrap 3插件,现在一切都可以了。我想用php单元测试所有开发测试!

但当我调用php单元时,它说他没有找到这样的类:

致命错误:类"BsHelpers''View''Helper''BsHelper"在C:''wamp3''www''wac_lucien''BsHelpers''BsHelpersCakePHP3''3.2''plugins''BsHelpers''tests''TestCase''View''Helper''BsHelpers Test.php的第26行中找不到

因此,在尝试完全遵循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中。插件加载程序的路径可能是错误的,但我不知道如何设置。。。

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>

知道为什么我在运行测试时不能访问助手吗?

伙计们,我真的需要想法

更新

我再次尝试运行测试。我发现了错误并更改了行,但我不明白为什么这会在测试中出现问题。

最初,我试图理解CakePHP3插件,通过使用来自friendsofke的这个插件,当我制作插件时(为了插入更多功能),我只是复制了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")配合使用。。。如果你明白的话,我对答案很感兴趣!