当前位置: 首页 > 知识库问答 >
问题:

运行测试时应查找类错误

呼延庆
2023-03-14

我是一个初学者在使用Symfony和我有麻烦测试一个函数我刚刚建立,我有这个错误,当我运行php bin/phpUnit测试/控制器:

App\Tests\Controller\MailControllerTest::testMailIsSentAndContentIsOk

Symfony\Component\Config\Exception\LoaderLoadException:从资源导入服务时,应在文件“C:\wamp64\www\Marketplace\src/Controller\MailController.php”中找到类“App\Controller\MailController”,但未找到!检查与C:\wamp64\www\Marketplace\config/services.yaml中的资源一起使用的名称空间前缀(该名称空间前缀加载在资源“C:\wamp64\www\Marketplace\config/services.yaml”中)。

我试着修复它并寻找修复方法,但毫无帮助。

我有一个要测试的MailController类

<?php

namespace App\Controller;


use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class MailController extends AbstractController
{
public function mail_inscription($destination, $name, \Swift_Mailer $mailer){
//etc etc

类MailControlllerTest.php正在测试邮件功能

<?php

//tests/controller/MailControllerTest.php
namespace App\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class MailControllerTest extends WebTestCase
{
    public function testMailIsSentAndContentIsOk(): void
    {
        $client = static::createClient();
//etc etc

这是它告诉我要看的services.yaml

parameters:

services:
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.


    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

我不知道该怎么办,如果有人得到任何线索,非常感谢。

我的项目结构

共有1个答案

舒阳州
2023-03-14

没关系,只是因为我还了$-

 类似资料:
  • 当我试图从Spring Boot应用程序中调用JUnit测试用例时,我遇到了以下错误: 我在测试类中使用了这个注释。 @RunWith(SpringRunner.class) 在我从项目依赖项添加JUnit库后,它给出了以下错误: 我的Spring启动版本是2.0.4。编辑器是SpringToolSuite。有人能帮我解决这个问题吗? 谢谢

  • 问题内容: 在Eclipse中运行JUnit测试时出现此错误: 尽管我正在使用maven,但我尝试在类路径中添加库,而JUnit库位于POM依赖项中。 我已经尝试清理项目,并使用Eclipse的JUnit插件创建了一个新的JUnit测试用例,但仍然遇到相同的错误。 问题答案: 出现这种情况的原因是,使用时只有源代码正在编译(我使用的是maven 3.1.0,所以我不确定它是否始终如此)。 如果运行

  • 这是一个关于PHP单元测试的问题,给出了一个类NotFound错误。 背景资料 我正在使用Zend Studio 10.5开发Zend Framework 2应用程序。我加载了一些模块,包括和 FedcoUser是具有使用BJYAAuthorize的保护规则的控制器保护的模块: 使用Zend Studio 10.5本机菜单,我为上面的控制器创建了一个测试用例。当我运行它时,我得到以下错误: 我的假

  • 我在一个项目中工作,所以我有下面的代码: 但问题是,我得到了这个错误: 处理命令时发生未知的服务器端错误。原始错误:执行adbexec时出错。原始错误:“command”c:\users\dnkos\appdata\local\android\sdk\platform-tools\adb.exe-p 5037-s emulator-5554 install-r c:\users\dnkos\app

  • 当我尝试运行一个JUnit类时,我得到以下错误: 我怀疑这是POM.xml中的配置问题,但我不确定。顺便说一下,这里是依赖项: http://maven.apache.org/maven-v4_0_0.xsd"

  • 我的项目是一个使用Gradle的Android库项目。当我运行测试时,IntelliJ抱怨以下错误: 但是存在于测试包中。 这是我的建筑。格雷德尔: 我使用的是IntelliJ IDEA13.1.1。 谢了。