PHP:运行“ codeception run wpunit”时

时间:2019-05-12 09:07:22

标签: php autoload psr-4

我最近将composer.json中的自动加载从类列表切换为psr-4。然后在终端中,我在项目根目录(即一个插件目录)中运行了vendor/bin/composer dump-autoload

我的自动加载设置:

"autoload": {
    "psr-4": { "A\\" : "classes/A" }
}

./ classes / A中只有1个类,因此当控制台说它加载了545个类时,这是一个问题。我再次检查了我是否在正确的(插件)文件夹中,而不是在wordpress根目录下。

看来,作曲家正在递归地从以下3个级别开始加载每个wordpress类。我得到了一个错误列表,以下是一些最常见的错误。

owner@G700:/var/www/html/wptest2/wp-content/plugins/fvc$ vendor/bin/codecept run wpunit
Codeception PHP Testing Framework v2.5.6
Powered by PHPUnit 7.5.10 by Sebastian Bergmann and contributors.
Running with seed: 

PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, class 'Utilities' not found in /var/www/html/wptest2/wp-includes/class-wp-hook.php on line 286
PHP Stack trace:
PHP   1. {main}() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/lucatume/wp-browser/src/includes/isolated-install.php:0
PHP   2. activate_plugin() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/lucatume/wp-browser/src/includes/isolated-install.php:210
PHP   3. do_action() /var/www/html/wptest2/wp-admin/includes/plugin.php:660
PHP   4. WP_Hook->do_action() /var/www/html/wptest2/wp-includes/plugin.php:465
PHP   5. WP_Hook->apply_filters() /var/www/html/wptest2/wp-includes/class-wp-hook.php:310
PHP Warning:  require_once(../../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/wptest2/wp-content/plugins/fvc/tests/wpunit/T1Test.php on line 2
PHP Stack trace:
PHP   1. {main}() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/codeception/codeception/codecept:0
PHP   2. Codeception\Application->run() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/codeception/codeception/codecept:43
PHP   3. Codeception\Application->run() /var/www/html/wptest2/wp-content/plugins/fvc/vendor/codeception/codeception/src/Codeception/Application.php:108

这是自动加载错误,对吗?知道我该如何解决吗?

如果这可能是其他原因,我将包括正在运行的测试文件。这是应该使用命令vendor/bin/codecept run wpunit

运行的唯一测试文件。
<?php
require_once("../../vendor/autoload.php");
require_once ('../../classes/A/T1.php');

class T1Test extends \Codeception\TestCase\WPTestCase
{
    public function testAdd() {
      $t1 = new \T1();

      $this->assertEquals(1, 1);

      $sum = $t1->add(5, 2);
      $this->assertEquals(7, $sum, "didn't sum");
    }

}

0 个答案:

没有答案