@@ -445,11 +445,18 @@ public function seeInCurrentRoute($routeName)
445
445
}
446
446
447
447
/**
448
- * Checks if any email were sent by last request
448
+ * Checks if the desired number of emails was sent.
449
+ * If no argument is provided then at least one email must be sent to satisfy the check.
449
450
*
450
- * @throws \LogicException
451
+ * ``` php
452
+ * <?php
453
+ * $I->seeEmailIsSent(2);
454
+ * ?>
455
+ * ```
456
+ *
457
+ * @param null|int $expectedCount
451
458
*/
452
- public function seeEmailIsSent ()
459
+ public function seeEmailIsSent ($ expectedCount = null )
453
460
{
454
461
$ profile = $ this ->getProfile ();
455
462
if (!$ profile ) {
@@ -459,7 +466,38 @@ public function seeEmailIsSent()
459
466
$ this ->fail ('Emails can \'t be tested without SwiftMailer connector ' );
460
467
}
461
468
462
- $ this ->assertGreaterThan (0 , $ profile ->getCollector ('swiftmailer ' )->getMessageCount ());
469
+ if (!is_int ($ expectedCount ) && !is_null ($ expectedCount )) {
470
+ $ this ->fail (sprintf (
471
+ 'The required number of emails must be either an integer or null. "%s" was provided. ' ,
472
+ print_r ($ expectedCount , true )
473
+ ));
474
+ }
475
+
476
+ $ realCount = $ profile ->getCollector ('swiftmailer ' )->getMessageCount ();
477
+ if ($ expectedCount === null ) {
478
+ $ this ->assertGreaterThan (0 , $ realCount );
479
+ } else {
480
+ $ this ->assertEquals (
481
+ $ expectedCount ,
482
+ $ realCount ,
483
+ sprintf (
484
+ 'Expected number of sent emails was %d, but in reality %d %s sent. ' ,
485
+ $ expectedCount ,
486
+ $ realCount ,
487
+ $ realCount === 2 ? 'was ' : 'were '
488
+ )
489
+ );
490
+ }
491
+ }
492
+
493
+ /**
494
+ * Checks that no email was sent. This is an alias for seeEmailIsSent(0).
495
+ *
496
+ * @part email
497
+ */
498
+ public function dontSeeEmailIsSent ()
499
+ {
500
+ $ this ->seeEmailIsSent (0 );
463
501
}
464
502
465
503
/**
0 commit comments