Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
11 / 11
44.44% covered (danger)
44.44%
4 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MailTestController
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
11 / 11
44.44% covered (danger)
44.44%
4 / 9
100.00% covered (success)
100.00%
2 / 2
12.17
100.00% covered (success)
100.00%
1 / 1
 buildForm
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 mailTest
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
10 / 10
37.50% covered (danger)
37.50%
3 / 8
100.00% covered (success)
100.00%
1 / 1
11.10
1<?php
2
3namespace App\Controller\Admin;
4
5use App\Application;
6use App\Entity\MailTest;
7use App\Parameter;
8use App\Security\Action;
9use App\Service\Mail;
10use Symfony\Component\Form\Extension\Core\Type\TextType;
11use Symfony\Component\Form\FormInterface;
12use Symfony\Component\HttpFoundation\Request;
13use Symfony\Component\HttpFoundation\Response;
14use Symfony\Component\Routing\Attribute\Route;
15use Throwable;
16
17#[Route('/admin/mailtest')]
18class MailTestController extends BaseAdminController
19{
20    /**
21     * @return FormInterface<mixed>
22     */
23    protected function buildForm(MailTest $mailTest): FormInterface
24    {
25        // Create the form with
26        $builder = $this->createFormBuilder($mailTest)
27            ->add('adresse', TextType::class);
28
29        return $builder->getForm();
30    }
31
32    #[Route('', name: 'admin_mail_test')]
33    public function mailTest(Request $request, Mail $mail, Application $application, Parameter $parameter): Response
34    {
35        $this->denyAccessUnlessGranted(Action::ADMIN_MAIL_TEST);
36        $mailTest = new MailTest();
37        $form = $this->buildForm($mailTest);
38        $form->handleRequest($request);
39        if ($form->isSubmitted() && $form->isValid()) {
40            try {
41                $mail->sendMail(
42                    $mailTest->getAdresse() . '@mydomain.com',
43                    "Test envoi d'email",
44                    'Ce mail est un test'
45                );
46                $this->addFlash('success', 'Le mail a été envoyé');
47
48                return $this->redirectToRoute('admin_mail_test');
49            } catch (Throwable $e) {
50                $this->addFlash(
51                    'danger',
52                    "Le mail n'a pas été envoyé, l'erreur suivante a été détectée : " . $e->getMessage()
53                );
54            }
55        }
56        if ('prod' === $application->getServerType()) {
57            $info = 'Attention, le mail sera réelement envoyé à cette adresse saisie !';
58        } else {
59            $info = "Attention, le mail sera redirigé à l'adresse suivante : " . $parameter->smtpRedirectMailTo;
60        }
61
62        return $this->render('admin/mail_test.html.twig', [
63            'form' => $form,
64            'info' => $info,
65        ]);
66    }
67}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

MailTestController->buildForm
23    protected function buildForm(MailTest $mailTest): FormInterface
24    {
25        // Create the form with
26        $builder = $this->createFormBuilder($mailTest)
27            ->add('adresse', TextType::class);
28
29        return $builder->getForm();
30    }
MailTestController->mailTest
33    public function mailTest(Request $request, Mail $mail, Application $application, Parameter $parameter): Response
34    {
35        $this->denyAccessUnlessGranted(Action::ADMIN_MAIL_TEST);
36        $mailTest = new MailTest();
37        $form = $this->buildForm($mailTest);
38        $form->handleRequest($request);
39        if ($form->isSubmitted() && $form->isValid()) {
39        if ($form->isSubmitted() && $form->isValid()) {
39        if ($form->isSubmitted() && $form->isValid()) {
40            try {
41                $mail->sendMail(
42                    $mailTest->getAdresse() . '@mydomain.com',
43                    "Test envoi d'email",
44                    'Ce mail est un test'
45                );
46                $this->addFlash('success', 'Le mail a été envoyé');
47
48                return $this->redirectToRoute('admin_mail_test');
49            } catch (Throwable $e) {
50                $this->addFlash(
51                    'danger',
52                    "Le mail n'a pas été envoyé, l'erreur suivante a été détectée : " . $e->getMessage()
53                );
54            }
55        }
56        if ('prod' === $application->getServerType()) {
56        if ('prod' === $application->getServerType()) {
56        if ('prod' === $application->getServerType()) {
57            $info = 'Attention, le mail sera réelement envoyé à cette adresse saisie !';
59            $info = "Attention, le mail sera redirigé à l'adresse suivante : " . $parameter->smtpRedirectMailTo;
60        }
61
62        return $this->render('admin/mail_test.html.twig', [
62        return $this->render('admin/mail_test.html.twig', [
63            'form' => $form,
64            'info' => $info,
65        ]);
66    }