【问题标题】:PHPUnit Error Class not found during test while trying to put separate folders of classes and tests尝试放置单独的类和测试文件夹时,在测试期间找不到 PHPUnit 错误类
【发布时间】:2021-08-23 19:58:55
【问题描述】:

我有一个与此处解释的答案类似的问题: Creating phpunit.xml file in phpunit

因为我的文件在root/src/foo,我的测试在root/tests/foo

但我就是不能让他们分开工作。他们在同一个文件夹中工作正常。 但我似乎无法将它们分开。

我已经尝试了该问题的解决方案,它显示了一个简单的工作示例 https://github.com/Grawer/starckoverflow-41881997

然而,这对我不起作用,即使我使用了相同的 bootstrap.phpphpunit.xml

.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>

<phpunit
        bootstrap="tests/bootstrap.php"
        colors="true"
>
    <testsuites>
        <testsuite>
            <directory prefix="" suffix="Test.php">./tests/foo/</directory>
        </testsuite>
    </testsuites>
</phpunit>

引导

<?php

include __DIR__ . '/../src/foo/ip_request.php';

【问题讨论】:

    标签: php xml unit-testing phpunit phpstorm


    【解决方案1】:

    已修复!

    我看了一个 youtube 视频,看到有人遇到同样的错误。

    我只在composer.json里面改了下面的代码并更新了

    "autoload": {
        "psr-4": {
          "foo\\": "foo"
        }
      },
    

    psr-4 位于 psr-0,通过该更改,它修复了它。

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 2019-08-18
      相关资源
      最近更新 更多