预期在运行测试时会发现类错误

时间:2020-03-11 22:19:59

标签: php symfony

我是使用symfony的初学者,我无法测试刚刚构建的功能,当我运行php bin / phpunit tests / controller时出现此错误:

App\Tests\Controller\MailControllerTest::testMailIsSentAndContentIsOk

Symfony \ Component \ Config \ Exception \ LoaderLoadException:从资源”导入服务时,预期在文件“ C:\ wamp64 \ www \ Marketplace \ src / Controller \ MailController.php”中找到类“ App \ Controller \ MailController” ../src/*“,但找不到!在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

正在测试邮件功能的MailControllerTest.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']

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

structure of my project

1 个答案:

答案 0 :(得分:0)

没关系只是因为我已经返回了$ this-> render(...);最后xD很抱歉打扰您

相关问题