Skip to content

Commit 936a62b

Browse files
committed
Add registerUser helper
1 parent 6b01ba3 commit 936a62b

File tree

5 files changed

+24
-72
lines changed

5 files changed

+24
-72
lines changed

tests/Functional/BrowserCest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,7 @@ public function seePageRedirectsTo(FunctionalTester $I)
135135

136136
public function submitSymfonyForm(FunctionalTester $I)
137137
{
138-
$I->amOnPage('/register');
139-
$I->submitSymfonyForm('registration_form', [
140-
'[email]' => '[email protected]',
141-
'[password]' => '123456',
142-
'[agreeTerms]' => true,
143-
]);
138+
$I->registerUser('[email protected]', '123456', followRedirects: true);
144139
$I->seeInRepository(User::class, [
145140
'email' => '[email protected]',
146141
]);

tests/Functional/EventsCest.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,13 @@ public function seeEventListenerIsCalled(FunctionalTester $I)
8080

8181
public function seeOrphanEvent(FunctionalTester $I)
8282
{
83-
$I->amOnPage('/register');
84-
$I->stopFollowingRedirects();
85-
$I->submitSymfonyForm('registration_form', [
86-
'[email]' => '[email protected]',
87-
'[password]' => '123456',
88-
'[agreeTerms]' => true,
89-
]);
83+
$I->registerUser('[email protected]', '123456', followRedirects: false);
9084
$I->seeOrphanEvent(UserRegisteredEvent::class);
9185
}
9286

9387
public function seeEvent(FunctionalTester $I)
9488
{
95-
$I->amOnPage('/register');
96-
$I->stopFollowingRedirects();
97-
$I->submitSymfonyForm('registration_form', [
98-
'[email]' => '[email protected]',
99-
'[password]' => '123456',
100-
'[agreeTerms]' => true,
101-
]);
89+
$I->registerUser('[email protected]', '123456', followRedirects: false);
10290
$I->seeEvent(UserRegisteredEvent::class);
10391
$I->seeEvent(KernelEvents::REQUEST, KernelEvents::FINISH_REQUEST);
10492
try {

tests/Functional/FormCest.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,20 @@ public function assertNoFormValue(FunctionalTester $I)
2222

2323
public function dontSeeFormErrors(FunctionalTester $I)
2424
{
25-
$I->amOnPage('/register');
26-
$I->submitSymfonyForm('registration_form', [
27-
'[email]' => '[email protected]',
28-
'[password]' => '123456',
29-
'[agreeTerms]' => true,
30-
]);
25+
$I->registerUser('[email protected]', '123456', followRedirects: true);
3126
$I->dontSeeFormErrors();
3227
}
3328

3429
public function seeFormErrorMessage(FunctionalTester $I)
3530
{
36-
$I->amOnPage('/register');
37-
$I->submitSymfonyForm('registration_form', [
38-
'[email]' => '[email protected]',
39-
'[password]' => '123456',
40-
'[agreeTerms]' => true,
41-
]);
31+
$I->registerUser('[email protected]', '123456', followRedirects: true);
4232
$I->seeFormErrorMessage('email');
4333
$I->seeFormErrorMessage('email', 'There is already an account with this email');
4434
}
4535

4636
public function seeFormErrorMessages(FunctionalTester $I)
4737
{
48-
$I->amOnPage('/register');
49-
$I->submitSymfonyForm('registration_form', [
50-
'[email]' => '[email protected]',
51-
'[password]' => '123',
52-
'[agreeTerms]' => true,
53-
]);
38+
$I->registerUser('[email protected]', '123', followRedirects: true);
5439

5540
// Only with the names of the fields
5641
$I->seeFormErrorMessages(['email', 'password']);
@@ -66,12 +51,7 @@ public function seeFormErrorMessages(FunctionalTester $I)
6651

6752
public function seeFormHasErrors(FunctionalTester $I)
6853
{
69-
$I->amOnPage('/register');
70-
$I->submitSymfonyForm('registration_form', [
71-
'[email]' => '[email protected]',
72-
'[password]' => '123456',
73-
'[agreeTerms]' => true,
74-
]);
54+
$I->registerUser('[email protected]', '123456', followRedirects: true);
7555
// There is already an account with this email
7656
$I->seeFormHasErrors();
7757
}

tests/Functional/MailerCest.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,30 @@ final class MailerCest
1010
{
1111
public function dontSeeEmailIsSent(FunctionalTester $I)
1212
{
13-
$I->amOnPage('/register');
14-
$I->stopFollowingRedirects();
15-
$I->submitSymfonyForm('registration_form', [
16-
'[email]' => '[email protected]',
17-
'[password]' => '123456',
18-
'[agreeTerms]' => true,
19-
]);
13+
$I->registerUser('[email protected]', '123456', followRedirects: false);
2014
// There is already an account with this email
2115
$I->dontSeeEmailIsSent();
2216
}
2317

2418
public function grabLastSentEmail(FunctionalTester $I)
2519
{
26-
$I->amOnPage('/register');
27-
$I->stopFollowingRedirects();
28-
$I->submitSymfonyForm('registration_form', [
29-
'[email]' => '[email protected]',
30-
'[password]' => '123456',
31-
'[agreeTerms]' => true,
32-
]);
20+
$I->registerUser('[email protected]', '123456', followRedirects: false);
3321
$email = $I->grabLastSentEmail();
3422
$address = $email->getTo()[0];
3523
$I->assertSame('[email protected]', $address->getAddress());
3624
}
3725

3826
public function grabSentEmails(FunctionalTester $I)
3927
{
40-
$I->amOnPage('/register');
41-
$I->stopFollowingRedirects();
42-
$I->submitSymfonyForm('registration_form', [
43-
'[email]' => '[email protected]',
44-
'[password]' => '123456',
45-
'[agreeTerms]' => true,
46-
]);
28+
$I->registerUser('[email protected]', '123456', followRedirects: false);
4729
$emails = $I->grabSentEmails();
4830
$address = $emails[0]->getTo()[0];
4931
$I->assertSame('[email protected]', $address->getAddress());
5032
}
5133

5234
public function seeEmailIsSent(FunctionalTester $I)
5335
{
54-
$I->amOnPage('/register');
55-
$I->stopFollowingRedirects();
56-
$I->submitSymfonyForm('registration_form', [
57-
'[email]' => '[email protected]',
58-
'[password]' => '123456',
59-
'[agreeTerms]' => true,
60-
]);
36+
$I->registerUser('[email protected]', '123456', followRedirects: false);
6137
$I->seeEmailIsSent();
6238
}
6339
}

tests/Support/FunctionalTester.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,17 @@
99
class FunctionalTester extends Actor
1010
{
1111
use _generated\FunctionalTesterActions;
12+
13+
public function registerUser(string $email, string $password, bool $followRedirects): void
14+
{
15+
$this->amOnPage('/register');
16+
if (!$followRedirects) {
17+
$this->stopFollowingRedirects();
18+
}
19+
$this->submitSymfonyForm('registration_form', [
20+
'[email]' => $email,
21+
'[password]' => $password,
22+
'[agreeTerms]' => true,
23+
]);
24+
}
1225
}

0 commit comments

Comments
 (0)