简体   繁体   English

测试CakePhp3插件->加载插件错误/缺少类

[英]Testing CakePhp3 plugin -> Error loading plugin / missing class

Actually working on a Bootstrap 3 plugin, everythinks works now. 实际上是在Bootstrap 3插件上工作的,everythinks现在可以工作了。 I want to test everything developping test with php Unit ! 我想用php Unit测试一切开发测试!

But when i call php unit it say that he don't found the class like that : 但是当我打电话给php unit时,他说他没有找到这样的类:

Fatal error : Class 'BsHelpers\\View\\Helper\\BsHelper' not found in C:\\wamp3\\www\\wac_lucien\\BsHelpers\\BsHelpersCakePHP3\\3.2\\plugins\\BsHelpers\\tests\\TestCase\\View\\Helper\\BsHelpersTest.php on line 26 致命错误:在第26行的C:\\ wamp3 \\ www \\ wac_lucien \\ BsHelpers \\ BsHelpersCakePHP3 \\ 3.2 \\ plugins \\ BsHelpers \\ tests \\ TestCase \\ View \\ Helper \\ BsHelpersTest.php中找不到类'BsHelpers \\ View \\ Helper \\ BsHelper'

So after trying to follow exactly the documentation from CakePHP3 i meet the problem at the begenning. 因此,在尝试完全遵循CakePHP3的文档之后,我在一开始遇到了问题。 For now I only got that : 现在我只知道:

<?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()
    {

    }
}

I think problem can be in bootstrap.php. 我认为问题可能出在bootstrap.php中。 The path of the plugin loader can be false but i don't know how to set up... 插件加载程序的路径可能为false,但我不知道如何设置...

Plugin::load('BsHelpers', ['path' => ROOT . DS]);

In the composer.json of my plugin i got : 在我的插件的composer.json中,我得到了:

    "autoload": {
    "psr-4": {
        "App\\": "src",
        "BsHelpers\\": "./plugins/BsHelpers/src",
        "BsHelpers\\Test\\": "./plugins/BsHelpers/tests"
    }
},

I invoke php unit test doing ( in my plugin folder ) 我调用php单元测试(在我的插件文件夹中)

vendor\bin\phpunit

And my phpunit.xml.dist looks like 我的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>

Any idea of why i can't acces my Helper during running my test ? 我为什么在运行测试期间无法访问助手?

Pls guys I really need ideas 伙计们,我真的需要想法

UPDATE 更新

I tried again running tests. 我再次尝试运行测试。 I found the error and change the line, but I don't understand why that was giving issues in tests. 我发现了错误并更改了行,但是我不明白为什么这会给测试带来麻烦。

Initialy I tried to understand CakePHP3 plugins, by working with this plugin from friendsofcake , when i made my plugin (to insert more functionalities) I just copied the composer.json to see the result with my plugin. Initialy我试图理解CakePHP3插件,通过与工作从friendsofcake这个插件 ,当我做了我的插件(插入更多的功能)我刚才复制的composer.json看到与我的插件的结果。 Just forget to change that part. 只是忘了改变那一部分。

So error was in the composer.json of the plugin : 所以错误是在插件的composer.json中:

{
"name": "friendsofcake/bootstrap-ui",
"description": "Twitter Bootstrap 3 support for CakePHP 3",
"type": "cakephp-plugin"
}

I changed the name line with 我用

"name": "lucienleroux/bs-helpers",

And I really don't understand why that solved the problem because nowhere I am setting a name like "lucienleroux/bs-helpers" in my plugin. 而且我真的不明白为什么这可以解决问题,因为在我的插件中没有地方设置“ lucienleroux / bs-helpers”之类的名称。 And in fact it works with any other string like "test/bs_helpers" ... If you understand I am interested in the answer ! 实际上,它可以与其他任何字符串(例如“ test / bs_helpers”)一起使用...如果您了解我对答案的兴趣!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM