Passed
Push — main ( bfbca3...f1aa52 )
by Karl
08:21
created

RegistrationControllerTest::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 16
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace App\Tests;
4
5
use App\Repository\UserRepository;
6
use Doctrine\ORM\EntityManager;
7
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
8
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
9
10
class RegistrationControllerTest extends WebTestCase
11
{
12
    private KernelBrowser $client;
13
    private UserRepository $userRepository;
14
15
    protected function setUp(): void
16
    {
17
        $this->client = static::createClient();
18
19
        // Ensure we have a clean database
20
        $container = static::getContainer();
21
22
        /** @var EntityManager $em */
23
        $em = $container->get('doctrine')->getManager();
24
        $this->userRepository = $container->get(UserRepository::class);
25
26
        foreach ($this->userRepository->findAll() as $user) {
27
            $em->remove($user);
28
        }
29
30
        $em->flush();
31
    }
32
33
    public function testRegister(): void
34
    {
35
        // Register a new user
36
        $this->client->request('GET', '/register');
37
        self::assertResponseIsSuccessful();
38
        self::assertPageTitleContains('Register');
39
40
        $this->client->submitForm('Register', [
41
            'registration_form[email]' => '[email protected]',
42
            'registration_form[plainPassword]' => 'password',
43
            'registration_form[agreeTerms]' => true,
44
        ]);
45
46
        // Ensure the response redirects after submitting the form, the user exists, and is not verified
47
        // self::assertResponseRedirects('/'); @TODO: set the appropriate path that the user is redirected to.
48
        self::assertCount(1, $this->userRepository->findAll());
49
    }
50
}
51