Skip to content

Commit

Permalink
Se inicia un incipiente test
Browse files Browse the repository at this point in the history
  • Loading branch information
gerMdz committed Nov 29, 2021
1 parent cd7196f commit 1e56a16
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 30 deletions.
32 changes: 32 additions & 0 deletions tests/Controller/SecurityControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class SecurityControllerTest extends WebTestCase
{
public function testRegister()
{
$client = static::createClient();
$crawler = $client->request('GET', '/register');

$this->assertResponseIsSuccessful();

$button = $crawler->selectButton('Register');
$form = $button->form();
$form['user_registration_form[firstName]']->setValue('Ryan');
$form['user_registration_form[email]']->setValue(sprintf('foo%s@example.com', rand()));
$form['user_registration_form[plainPassword]']->setValue('space_rocks');
$form['user_registration_form[agreeTerms]']->tick();
$client->submit($form);

$this->assertResponseRedirects();

/* Symfony 4.4:
$this->assertEmailCount(1);
$email = $this->getMailerMessage(0);
$this->assertEmailHeaderSame($email, 'To', 'fabien@symfony.com');
*/
}
}
61 changes: 31 additions & 30 deletions tests/Service/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,63 @@

namespace App\Tests\Service;

use App\Entity\Reservante;
use App\Repository\InvitadoRepository;
use App\Repository\WaitingListRepository;
use App\Service\Handler\Metabase\HandlerMetabase;
use App\Entity\Celebracion;
use App\Entity\User;
use App\Service\Mailer;
use Knp\Snappy\Pdf;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\NamedAddress;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
use Twig\Environment;

class MailerTest extends TestCase
class MailerTest extends KernelTestCase
{
/**
* @throws TransportExceptionInterface
*/
public function testSendWelcomeMessage()
{
$symfonyMailer = $this->createMock(MailerInterface::class);
$symfonyMailer->expects($this->once())
->method('send');
// $pdf = $this->createMock(Pdf::class);

$pdf = $this->createMock(Pdf::class);
$twig = $this->createMock(Environment::class);
$entrypointLookup = $this->createMock(EntrypointLookupInterface::class);
$waitingListRepository = $this->createMock(WaitingListRepository::class);
$repository = $this->createMock(InvitadoRepository::class);
$handlerMetabase = $this->createMock(HandlerMetabase::class);

$reservante = new Reservante();
$user = new User();
$user->setPrimerNombre('Victor');
$user->setEmail('victor@symfonycasts.com');

$reservante->setEmail('uno@dos.com');
$reservante->setNombre('uno');
$mailer = new Mailer($symfonyMailer, $twig, $pdf, $entrypointLookup);
$email = $mailer->sendWelcomeMessage($user);

$mailer = new Mailer($symfonyMailer, $twig, $waitingListRepository, $repository,$handlerMetabase);
$mailer->sendReservaMessageTest($reservante);
// $this->assertTrue(true);
$this->assertSame('Welcome to the Space Bar!', $email->getSubject());
$this->assertCount(1, $email->getTo());
/** @var NamedAddress[] $namedAddresses */
$namedAddresses = $email->getTo();
$this->assertInstanceOf(NamedAddress::class, $namedAddresses[0]);
$this->assertSame('Victor', $namedAddresses[0]->getName());
$this->assertSame('victor@symfonycasts.com', $namedAddresses[0]->getAddress());
}

public function testIntegrationSendAuthorWeeklyReportMessage()
{
self::bootKernel();
$symfonyMailer = $this->createMock(MailerInterface::class);
$symfonyMailer->expects($this->once())
->method('send');
// $pdf = $this->createMock(Pdf::class);
$twig = $this->createMock(Environment::class);
$pdf = self::$container->get(Pdf::class);
$twig = self::$container->get(Environment::class);
$entrypointLookup = $this->createMock(EntrypointLookupInterface::class);
$waitingListRepository = $this->createMock(WaitingListRepository::class);
$repository = $this->createMock(InvitadoRepository::class);
$handlerMetabase = $this->createMock(HandlerMetabase::class);

$reservante = new Reservante();

$reservante->setEmail('uno@dos.com');
$reservante->setNombre('uno');
$user = new User();
$user->setFirstName('Victor');
$user->setEmail('victor@symfonycasts.com');
$article = new Article();
$article->setTitle('Black Holes: Ultimate Party Pooper');

$mailer = new Mailer($symfonyMailer, $twig, $waitingListRepository, $repository,$handlerMetabase);
$mailer->sendReservaMessageTest($reservante);
$mailer = new Mailer($symfonyMailer, $twig, $pdf, $entrypointLookup);
$email = $mailer->sendAuthorWeeklyReportMessage($user, [$article]);
$this->assertCount(1, $email->getAttachments());
}
}

0 comments on commit 1e56a16

Please sign in to comment.