From 807a80b4a6bb634b4e7aae67e64ab52b61ddceeb Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 24 Jun 2021 15:11:16 +0200 Subject: [PATCH] SetWordWrapTest: reorganize to use data providers * Maintains the same test code and test cases. * Removes code duplication. * Makes it easier to add additional test cases in the future. --- test/PHPMailer/SetWordWrapTest.php | 53 +++++++++++++++--------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/test/PHPMailer/SetWordWrapTest.php b/test/PHPMailer/SetWordWrapTest.php index ab8de9ad..8612c0b0 100644 --- a/test/PHPMailer/SetWordWrapTest.php +++ b/test/PHPMailer/SetWordWrapTest.php @@ -22,46 +22,47 @@ final class SetWordWrapTest extends PreSendTestCase { /** - * Word-wrap an ASCII message. + * Test word-wrapping a message. + * + * @dataProvider dataWordWrap + * + * @param string $message The message to use. + * @param string $subjectSuffix Subject suffix to use. */ - public function testWordWrap() + public function testWordWrap($message, $subjectSuffix) { $this->Mail->WordWrap = 40; - $my_body = str_repeat( - 'Here is the main body of this message. It should ' . - 'be quite a few lines. It should be wrapped at ' . - '40 characters. Make sure that it is. ', - 10 - ); + $my_body = str_repeat($message, 10); $nBodyLen = strlen($my_body); $my_body .= "\n\nThis is the above body length: " . $nBodyLen; $this->Mail->Body = $my_body; - $this->Mail->Subject .= ': Wordwrap'; + $this->Mail->Subject .= ': ' . $subjectSuffix; $this->buildBody(); self::assertTrue($this->Mail->preSend(), $this->Mail->ErrorInfo); } /** - * Word-wrap a multibyte message. + * Data provider. + * + * @return array */ - public function testWordWrapMultibyte() + public function dataWordWrap() { - $this->Mail->WordWrap = 40; - $my_body = str_repeat( - '飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 ' . - '飛飛兒樂 團光茫兒樂 團光茫飛兒樂 團光飛兒樂 團光茫飛兒樂 團光茫兒樂 團光茫 ' . - '飛兒樂 團光茫飛兒樂 團飛兒樂 團光茫光茫飛兒樂 團光茫. ', - 10 - ); - $nBodyLen = strlen($my_body); - $my_body .= "\n\nThis is the above body length: " . $nBodyLen; - - $this->Mail->Body = $my_body; - $this->Mail->Subject .= ': Wordwrap multibyte'; - - $this->buildBody(); - self::assertTrue($this->Mail->preSend(), $this->Mail->ErrorInfo); + return [ + 'ascii message' => [ + 'message' => 'Here is the main body of this message. It should ' . + 'be quite a few lines. It should be wrapped at ' . + '40 characters. Make sure that it is. ', + 'subjectSuffix' => 'Wordwrap', + ], + 'multibyte message' => [ + 'message' => '飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 ' . + '飛飛兒樂 團光茫兒樂 團光茫飛兒樂 團光飛兒樂 團光茫飛兒樂 團光茫兒樂 團光茫 ' . + '飛兒樂 團光茫飛兒樂 團飛兒樂 團光茫光茫飛兒樂 團光茫. ', + 'subjectSuffix' => 'Wordwrap multibyte', + ], + ]; } }