WordPress.org

Make WordPress Core

Changeset 37358


Ignore:
Timestamp:
05/04/16 03:48:46 (15 months ago)
Author:
boonebgorges
Message:

Tests: Introduce reset_phpmailer_instance() function.

This function provides a more convenient method for resetting the
PHPMailer instance than the previous technique of reaching into the global.

Props welcher.
Fixes #36658.

Location:
trunk/tests/phpunit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/mock-mailer.php

    r36594 r37358  
    8585    return $mailer; 
    8686} 
     87 
     88/** 
     89 * Helper method to reset the phpmailer instance. 
     90 * 
     91 * @since 4.6.0 
     92 * 
     93 * @return bool 
     94 */ 
     95function reset_phpmailer_instance() { 
     96    $mailer = tests_retrieve_phpmailer_instance(); 
     97    if ( $mailer && isset( $mailer->mock_sent ) ) { 
     98        unset( $mailer->mock_sent ); 
     99        return true; 
     100    } 
     101 
     102    return false; 
     103} 
  • trunk/tests/phpunit/tests/comment.php

    r36515 r37358  
    1010    public function setUp() { 
    1111        parent::setUp(); 
    12         unset( $GLOBALS['phpmailer']->mock_sent ); 
     12        reset_phpmailer_instance(); 
    1313    } 
    1414 
     
    559559        ) { 
    560560            $email_sent_when_comment_added = true; 
    561             unset( $GLOBALS['phpmailer']->mock_sent ); 
     561            reset_phpmailer_instance(); 
    562562        } else { 
    563563            $email_sent_when_comment_added = false; 
     
    590590            $email_sent_when_comment_approved = false; 
    591591        } 
    592         unset( $GLOBALS['phpmailer']->mock_sent ); 
     592        reset_phpmailer_instance(); 
    593593 
    594594        // Post authors are notified when a new comment is added to their post. 
     
    608608             'test@test.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) { 
    609609            $email_sent_when_comment_added = true; 
    610             unset( $GLOBALS['phpmailer']->mock_sent ); 
     610            reset_phpmailer_instance(); 
    611611        } else { 
    612612            $email_sent_when_comment_added = false; 
  • trunk/tests/phpunit/tests/mail.php

    r37307 r37358  
    77    function setUp() { 
    88        parent::setUp(); 
    9         unset( $GLOBALS['phpmailer']->mock_sent ); 
     9        reset_phpmailer_instance(); 
    1010    } 
    1111 
    1212    function tearDown() { 
    13         unset( $GLOBALS['phpmailer']->mock_sent ); 
     13        reset_phpmailer_instance(); 
    1414        parent::tearDown(); 
    1515    } 
  • trunk/tests/phpunit/tests/user.php

    r37277 r37358  
    10251025     */ 
    10261026    function test_wp_new_user_notification( $notify, $admin_email_sent_expected, $user_email_sent_expected ) { 
    1027         unset( $GLOBALS['phpmailer']->mock_sent ); 
     1027        reset_phpmailer_instance(); 
    10281028 
    10291029        $was_admin_email_sent = false; 
     
    11011101     */ 
    11021102    function test_wp_new_user_notification_old_signature_throws_deprecated_warning_but_sends() { 
    1103         unset( $GLOBALS['phpmailer']->mock_sent ); 
     1103        reset_phpmailer_instance(); 
    11041104 
    11051105        $was_admin_email_sent = false; 
     
    11261126     */ 
    11271127    function test_wp_new_user_notification_old_signature_no_password() { 
    1128         unset( $GLOBALS['phpmailer']->mock_sent ); 
     1128        reset_phpmailer_instance(); 
    11291129 
    11301130        $was_admin_email_sent = false; 
Note: See TracChangeset for help on using the changeset viewer.