1
votes

I'm a beginner in using symfony and i'm having trouble to test a function I just built, i have this error when I run php bin/phpunit tests/controller :

App\Tests\Controller\MailControllerTest::testMailIsSentAndContentIsOk

Symfony\Component\Config\Exception\LoaderLoadException: Expected to find class "App\Controller\MailController" in file "C:\wamp64\www\Marketplace\src/Controller\MailController.php" while importing services from resource "../src/*", but it was not found! Check the namespace prefix used with the resource in C:\wamp64\www\Marketplace\config/services.yaml (which is loaded in resource "C:\wamp64\www\Marketplace\config/services.yaml").

I tried fixing it and looking for a fix but it didn't help at all.

I have the class MailController which I want to test

<?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

the class MailControllerTest.php which is testing the mailing function

<?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

and here is the services.yaml which it's telling me to look at

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']

I don't know what to do, if anyone got any leads, thanks a lot.

structure of my project

1
So, is the MailController class where Symfony expects it to be or not?El_Vanja
i think so, i will post an image with the structureLittle-kinder

1 Answers

0
votes

nevermind it was just because I had return $this->render(...); at the end xD sorry for bothering you