Skip to content

Commit 5909c90

Browse files
committed
Use assertStringContainsString when needed
1 parent ee26159 commit 5909c90

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

Tests/Functional/CsrfFormLoginTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public function testFormLoginAndLogoutWithCsrfTokens($config)
3030
$crawler = $client->followRedirect();
3131

3232
$text = $crawler->text();
33-
$this->assertContains('Hello johannes!', $text);
34-
$this->assertContains('You\'re browsing to path "/profile".', $text);
33+
$this->assertStringContainsString('Hello johannes!', $text);
34+
$this->assertStringContainsString('You\'re browsing to path "/profile".', $text);
3535

3636
$logoutLinks = $crawler->selectLink('Log out')->links();
3737
$this->assertCount(2, $logoutLinks);
38-
$this->assertContains('_csrf_token=', $logoutLinks[0]->getUri());
38+
$this->assertStringContainsString('_csrf_token=', $logoutLinks[0]->getUri());
3939
$this->assertSame($logoutLinks[0]->getUri(), $logoutLinks[1]->getUri());
4040

4141
$client->click($logoutLinks[0]);
@@ -57,7 +57,7 @@ public function testFormLoginWithInvalidCsrfToken($config)
5757
$this->assertRedirect($client->getResponse(), '/login');
5858

5959
$text = $client->followRedirect()->text();
60-
$this->assertContains('Invalid CSRF token.', $text);
60+
$this->assertStringContainsString('Invalid CSRF token.', $text);
6161
}
6262

6363
/**
@@ -76,8 +76,8 @@ public function testFormLoginWithCustomTargetPath($config)
7676
$this->assertRedirect($client->getResponse(), '/foo');
7777

7878
$text = $client->followRedirect()->text();
79-
$this->assertContains('Hello johannes!', $text);
80-
$this->assertContains('You\'re browsing to path "/foo".', $text);
79+
$this->assertStringContainsString('Hello johannes!', $text);
80+
$this->assertStringContainsString('You\'re browsing to path "/foo".', $text);
8181
}
8282

8383
/**
@@ -97,8 +97,8 @@ public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
9797
$this->assertRedirect($client->getResponse(), '/protected-resource');
9898

9999
$text = $client->followRedirect()->text();
100-
$this->assertContains('Hello johannes!', $text);
101-
$this->assertContains('You\'re browsing to path "/protected-resource".', $text);
100+
$this->assertStringContainsString('Hello johannes!', $text);
101+
$this->assertStringContainsString('You\'re browsing to path "/protected-resource".', $text);
102102
}
103103

104104
public function getConfigs()

Tests/Functional/FormLoginTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function testFormLogin($config)
2828
$this->assertRedirect($client->getResponse(), '/profile');
2929

3030
$text = $client->followRedirect()->text();
31-
$this->assertContains('Hello johannes!', $text);
32-
$this->assertContains('You\'re browsing to path "/profile".', $text);
31+
$this->assertStringContainsString('Hello johannes!', $text);
32+
$this->assertStringContainsString('You\'re browsing to path "/profile".', $text);
3333
}
3434

3535
/**
@@ -49,8 +49,8 @@ public function testFormLogout($config)
4949
$crawler = $client->followRedirect();
5050
$text = $crawler->text();
5151

52-
$this->assertContains('Hello johannes!', $text);
53-
$this->assertContains('You\'re browsing to path "/profile".', $text);
52+
$this->assertStringContainsString('Hello johannes!', $text);
53+
$this->assertStringContainsString('You\'re browsing to path "/profile".', $text);
5454

5555
$logoutLinks = $crawler->selectLink('Log out')->links();
5656
$this->assertCount(6, $logoutLinks);
@@ -81,8 +81,8 @@ public function testFormLoginWithCustomTargetPath($config)
8181
$this->assertRedirect($client->getResponse(), '/foo');
8282

8383
$text = $client->followRedirect()->text();
84-
$this->assertContains('Hello johannes!', $text);
85-
$this->assertContains('You\'re browsing to path "/foo".', $text);
84+
$this->assertStringContainsString('Hello johannes!', $text);
85+
$this->assertStringContainsString('You\'re browsing to path "/foo".', $text);
8686
}
8787

8888
/**
@@ -102,8 +102,8 @@ public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
102102
$this->assertRedirect($client->getResponse(), '/protected_resource');
103103

104104
$text = $client->followRedirect()->text();
105-
$this->assertContains('Hello johannes!', $text);
106-
$this->assertContains('You\'re browsing to path "/protected_resource".', $text);
105+
$this->assertStringContainsString('Hello johannes!', $text);
106+
$this->assertStringContainsString('You\'re browsing to path "/protected_resource".', $text);
107107
}
108108

109109
public function getConfigs()

Tests/Functional/UserPasswordEncoderCommandTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testEncodeNoPasswordNoInteraction()
4949
'command' => 'security:encode-password',
5050
], ['interactive' => false]);
5151

52-
$this->assertContains('[ERROR] The password must not be empty.', $this->passwordEncoderCommandTester->getDisplay());
52+
$this->assertStringContainsString('[ERROR] The password must not be empty.', $this->passwordEncoderCommandTester->getDisplay());
5353
$this->assertEquals($statusCode, 1);
5454
}
5555

@@ -62,7 +62,7 @@ public function testEncodePasswordBcrypt()
6262
], ['interactive' => false]);
6363

6464
$output = $this->passwordEncoderCommandTester->getDisplay();
65-
$this->assertContains('Password encoding succeeded', $output);
65+
$this->assertStringContainsString('Password encoding succeeded', $output);
6666

6767
$encoder = new BCryptPasswordEncoder(17);
6868
preg_match('# Encoded password\s{1,}([\w+\/$.]+={0,2})\s+#', $output, $matches);
@@ -83,7 +83,7 @@ public function testEncodePasswordArgon2i()
8383
], ['interactive' => false]);
8484

8585
$output = $this->passwordEncoderCommandTester->getDisplay();
86-
$this->assertContains('Password encoding succeeded', $output);
86+
$this->assertStringContainsString('Password encoding succeeded', $output);
8787

8888
$encoder = new Argon2iPasswordEncoder();
8989
preg_match('# Encoded password\s+(\$argon2id?\$[\w,=\$+\/]+={0,2})\s+#', $output, $matches);
@@ -100,7 +100,7 @@ public function testEncodePasswordPbkdf2()
100100
], ['interactive' => false]);
101101

102102
$output = $this->passwordEncoderCommandTester->getDisplay();
103-
$this->assertContains('Password encoding succeeded', $output);
103+
$this->assertStringContainsString('Password encoding succeeded', $output);
104104

105105
$encoder = new Pbkdf2PasswordEncoder('sha512', true, 1000);
106106
preg_match('# Encoded password\s{1,}([\w+\/]+={0,2})\s+#', $output, $matches);
@@ -119,9 +119,9 @@ public function testEncodePasswordOutput()
119119
], ['interactive' => false]
120120
);
121121

122-
$this->assertContains('Password encoding succeeded', $this->passwordEncoderCommandTester->getDisplay());
123-
$this->assertContains(' Encoded password p@ssw0rd', $this->passwordEncoderCommandTester->getDisplay());
124-
$this->assertContains(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay());
122+
$this->assertStringContainsString('Password encoding succeeded', $this->passwordEncoderCommandTester->getDisplay());
123+
$this->assertStringContainsString(' Encoded password p@ssw0rd', $this->passwordEncoderCommandTester->getDisplay());
124+
$this->assertStringContainsString(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay());
125125
}
126126

127127
public function testEncodePasswordEmptySaltOutput()
@@ -133,9 +133,9 @@ public function testEncodePasswordEmptySaltOutput()
133133
'--empty-salt' => true,
134134
]);
135135

136-
$this->assertContains('Password encoding succeeded', $this->passwordEncoderCommandTester->getDisplay());
137-
$this->assertContains(' Encoded password p@ssw0rd', $this->passwordEncoderCommandTester->getDisplay());
138-
$this->assertNotContains(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay());
136+
$this->assertStringContainsString('Password encoding succeeded', $this->passwordEncoderCommandTester->getDisplay());
137+
$this->assertStringContainsString(' Encoded password p@ssw0rd', $this->passwordEncoderCommandTester->getDisplay());
138+
$this->assertStringNotContainsString(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay());
139139
}
140140

141141
public function testEncodePasswordBcryptOutput()
@@ -146,7 +146,7 @@ public function testEncodePasswordBcryptOutput()
146146
'user-class' => 'Custom\Class\Bcrypt\User',
147147
], ['interactive' => false]);
148148

149-
$this->assertNotContains(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay());
149+
$this->assertStringNotContainsString(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay());
150150
}
151151

152152
public function testEncodePasswordArgon2iOutput()
@@ -162,7 +162,7 @@ public function testEncodePasswordArgon2iOutput()
162162
'user-class' => 'Custom\Class\Argon2i\User',
163163
], ['interactive' => false]);
164164

165-
$this->assertNotContains(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay());
165+
$this->assertStringNotContainsString(' Generated salt ', $this->passwordEncoderCommandTester->getDisplay());
166166
}
167167

168168
public function testEncodePasswordNoConfigForGivenUserClass()
@@ -185,7 +185,7 @@ public function testEncodePasswordAsksNonProvidedUserClass()
185185
'password' => 'password',
186186
], ['decorated' => false]);
187187

188-
$this->assertContains(<<<EOTXT
188+
$this->assertStringContainsString(<<<EOTXT
189189
For which user class would you like to encode a password? [Custom\Class\Bcrypt\User]:
190190
[0] Custom\Class\Bcrypt\User
191191
[1] Custom\Class\Pbkdf2\User
@@ -202,7 +202,7 @@ public function testNonInteractiveEncodePasswordUsesFirstUserClass()
202202
'password' => 'password',
203203
], ['interactive' => false]);
204204

205-
$this->assertContains('Encoder used Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder', $this->passwordEncoderCommandTester->getDisplay());
205+
$this->assertStringContainsString('Encoder used Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder', $this->passwordEncoderCommandTester->getDisplay());
206206
}
207207

208208
public function testThrowsExceptionOnNoConfiguredEncoders()
@@ -240,7 +240,7 @@ public function testLegacy()
240240
'password' => 'password',
241241
], ['interactive' => false]);
242242

243-
$this->assertContains('Encoder used Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder', $tester->getDisplay());
243+
$this->assertStringContainsString('Encoder used Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder', $tester->getDisplay());
244244
}
245245

246246
protected function setUp()

0 commit comments

Comments
 (0)