【问题标题】:Namespaces not working with Symfony and Composer命名空间不适用于 Symfony 和 Composer
【发布时间】:2019-06-27 22:29:16
【问题描述】:

我一定是错过了什么;我正在尝试运行一些测试,但由于命名空间,从未找到这些类。

这是我的结构。

-app
    -tests
        -Unit
            -TestInterface.php
            -common
                -MyTest.php

这是我的 TestInterface.php:

namespace App\Tests\Unit;


interface TestInterface
{

}

这是我的 MyTest.php:

namespace App\Tests\Unit\common;

use App\Tests\Unit\TestInterface;

class MyTest implements TestInterface
{

}

这里是composer.json的相关部分:

  "autoload": {
    "psr-4": {
      "App\\": "src/",
      "spec\\": "spec/"
    }
  },
  "autoload-dev": {
    "psr-4": {
      "App\\Tests\\": "tests/"
    }
  },

这是错误:

PHP Fatal error:  Interface 'App\Tests\Unit\TestInterface' not found

我在这里错过了什么?

【问题讨论】:

标签: php composer-php autoload


【解决方案1】:

回答自己,代码没问题。

我正在从 another.phar 加载 PHPUnit。通过 composer 安装 PHPUnit:

composer require --dev phpunit/phpunit ^8

并从 ./bin 中使用它,效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-11
    • 2014-01-24
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 2020-04-19
    相关资源
    最近更新 更多