Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit 2eafe87

Browse files
author
Teddy Roncin
committed
✨ (EtuUTTApiTestCase) Added createUser method
Added createUser method. The methods takes 4 parameters : $firstName, $lastName, $login and $role. Role is not mendatory. If not provided, it is defaulted to 'ROLE_USER'. It creates a user according to the parameters, put it in the database, and flush the data. In the future, if necessary, it could be useful to add a parameter to ask if we want to flush the database, because it could maybe be slow if we need to do that a lot.
1 parent 9b8ea5a commit 2eafe87

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

tests/EtuUTTApiTestCase.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ protected function setUp(): void
1919
{
2020
$this->em = $this->getContainer()->get('doctrine')->getManager();
2121
(new ORMPurger($this->em))->purge();
22-
$this->user = new User();
23-
$this->user->setFirstName('test');
24-
$this->user->setLastName('test');
25-
$this->user->setLogin('test');
26-
$this->user->addRole('ROLE_ADMIN');
27-
$this->em->persist($this->user);
28-
$this->em->flush();
22+
$this->user = $this->createUser('test', 'test', 'test', 'ROLE_ADMIN');
2923
}
3024

3125
protected function loadFixtures(Fixture... $fixtures)
@@ -39,4 +33,16 @@ protected function loadFixtures(Fixture... $fixtures)
3933
}
4034
}
4135

36+
protected function createUser(string $firstName, string $lastName, string $login, ?string $role = 'ROLE_USER') : User
37+
{
38+
$user = new User();
39+
$user->setFirstName($firstName);
40+
$user->setLastName($lastName);
41+
$user->setLogin($login);
42+
$user->addRole($role);
43+
$this->em->persist($user);
44+
$this->em->flush();
45+
return $user;
46+
}
47+
4248
}

0 commit comments

Comments
 (0)