Skip to content

Commit 61bbad9

Browse files
authored
Add functional tests for inherited Symfony assertions (#47)
Covers the assertion/getter methods added in Codeception/module-symfony#240 that are available on Symfony 6.4: - DomCrawlerCest: assertSelectorCount, assertAnySelectorTextContains, assertAnySelectorTextSame, assertAnySelectorTextNotContains - MailerCest: getMailerEvents, getMailerMessages, getMailerMessage - MimeCest: assertEmailAddressNotContains, assertEmailSubjectContains, assertEmailSubjectNotContains Browser-history assertions are omitted: they require symfony/browser-kit >= 7.4. Refreshes composer.lock.
1 parent c9d3fc5 commit 61bbad9

4 files changed

Lines changed: 87 additions & 31 deletions

File tree

composer.lock

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Functional/DomCrawlerCest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ public function _before(FunctionalTester $I): void
1313
$I->amOnPage('/test_page');
1414
}
1515

16+
public function assertAnySelectorTextContains(FunctionalTester $I): void
17+
{
18+
$I->assertAnySelectorTextContains('label', 'Example Input', 'A label should contain "Example Input".');
19+
}
20+
21+
public function assertAnySelectorTextNotContains(FunctionalTester $I): void
22+
{
23+
$I->assertAnySelectorTextNotContains('label', 'Nonexistent label text', 'No label should contain this text.');
24+
}
25+
26+
public function assertAnySelectorTextSame(FunctionalTester $I): void
27+
{
28+
$I->assertAnySelectorTextSame('label', 'Username', 'A label should be exactly "Username".');
29+
}
30+
1631
public function assertCheckboxChecked(FunctionalTester $I): void
1732
{
1833
$I->assertCheckboxChecked('exampleCheckbox', 'The checkbox should be checked.');
@@ -38,6 +53,11 @@ public function assertPageTitleSame(FunctionalTester $I): void
3853
$I->assertPageTitleSame('Test Page', 'The page title should be "Test Page".');
3954
}
4055

56+
public function assertSelectorCount(FunctionalTester $I): void
57+
{
58+
$I->assertSelectorCount(3, 'input', 'The test page should contain exactly 3 inputs.');
59+
}
60+
4161
public function assertSelectorExists(FunctionalTester $I): void
4262
{
4363
$I->assertSelectorExists('h1', 'The <h1> element should be present.');

tests/Functional/MailerCest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Tests\Functional;
66

77
use App\Tests\Support\FunctionalTester;
8+
use Symfony\Component\Mime\Email;
89

910
final class MailerCest
1011
{
@@ -15,6 +16,26 @@ public function dontSeeEmailIsSent(FunctionalTester $I)
1516
$I->dontSeeEmailIsSent();
1617
}
1718

19+
public function getMailerEvents(FunctionalTester $I)
20+
{
21+
$I->registerUser('jane_doe@gmail.com', '123456', followRedirects: false);
22+
$I->assertNotEmpty($I->getMailerEvents());
23+
}
24+
25+
public function getMailerMessage(FunctionalTester $I)
26+
{
27+
$I->registerUser('jane_doe@gmail.com', '123456', followRedirects: false);
28+
$I->assertInstanceOf(Email::class, $I->getMailerMessage());
29+
}
30+
31+
public function getMailerMessages(FunctionalTester $I)
32+
{
33+
$I->registerUser('jane_doe@gmail.com', '123456', followRedirects: false);
34+
$messages = $I->getMailerMessages();
35+
$I->assertNotEmpty($messages);
36+
$I->assertInstanceOf(Email::class, $messages[0]);
37+
}
38+
1839
public function grabLastSentEmail(FunctionalTester $I)
1940
{
2041
$I->registerUser('jane_doe@gmail.com', '123456', followRedirects: false);

tests/Functional/MimeCest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public function assertEmailAddressContains(FunctionalTester $I)
1919
$I->assertEmailAddressContains('To', 'jane_doe@example.com');
2020
}
2121

22+
public function assertEmailAddressNotContains(FunctionalTester $I)
23+
{
24+
$I->assertEmailAddressNotContains('To', 'john_doe@example.com');
25+
}
26+
2227
public function assertEmailAttachmentCount(FunctionalTester $I)
2328
{
2429
$I->assertEmailAttachmentCount(1);
@@ -54,6 +59,16 @@ public function assertEmailNotHasHeader(FunctionalTester $I)
5459
$I->assertEmailNotHasHeader('Bcc');
5560
}
5661

62+
public function assertEmailSubjectContains(FunctionalTester $I)
63+
{
64+
$I->assertEmailSubjectContains('Account created successfully');
65+
}
66+
67+
public function assertEmailSubjectNotContains(FunctionalTester $I)
68+
{
69+
$I->assertEmailSubjectNotContains('Password reset');
70+
}
71+
5772
public function assertEmailTextBodyContains(FunctionalTester $I)
5873
{
5974
$I->assertEmailTextBodyContains('Example text body');

0 commit comments

Comments
 (0)