ParseAddressesTest: split off expectation verification

This commit is contained in:
jrfnl 2021-07-11 16:17:43 +02:00
parent e67ed991e3
commit 8fd56f335e
1 changed files with 18 additions and 11 deletions

View File

@ -36,12 +36,7 @@ final class ParseAddressesTest extends TestCase
{
$parsed = PHPMailer::parseAddresses($addrstr, false);
self::assertIsArray($parsed, 'parseAddresses() did not return an array');
self::assertSame(
$expected,
$parsed,
'The return value from parseAddresses() did not match the expected output'
);
$this->verifyExpectations($parsed, $expected);
}
/**
@ -57,14 +52,26 @@ final class ParseAddressesTest extends TestCase
*/
public function testAddressSplittingImap($addrstr, $expected, $expectedImap = [])
{
$parsed = PHPMailer::parseAddresses($addrstr, true);
self::assertIsArray($parsed, 'parseAddresses() did not return an array');
$parsed = PHPMailer::parseAddresses($addrstr, true);
$expected = empty($expectedImap) ? $expected : $expectedImap;
$this->verifyExpectations($parsed, $expected);
}
/**
* Verify the expectations.
*
* Abstracted out as the same verification needs to be done for every test, just with different data.
*
* @param string $actual The actual function output.
* @param array $expected The expected function output.
*/
protected function verifyExpectations($actual, $expected)
{
self::assertIsArray($actual, 'parseAddresses() did not return an array');
self::assertSame(
$expected,
$parsed,
$actual,
'The return value from parseAddresses() did not match the expected output'
);
}