Skip to content

Commit

Permalink
DKIMTest::testDKIMSignOpenSSLNotAvailable(): fix the test
Browse files Browse the repository at this point in the history
As things were, the `DKIMTest::testDKIMSignOpenSSLNotAvailable()` could not pass as the `DKIMTest` class sets the `USE_EXCEPTIONS` class constant to `true`, which means the method would fail on an exception.

As this test is specifically about testing the behaviour when exceptions are _disabled_, the test needs to be in its own test class, which sets `USE_EXCEPTIONS` to `false`.

That should allow the test to run properly and to pass.
  • Loading branch information
jrfnl committed Sep 11, 2024
1 parent 10f76cd commit 78146fb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
15 changes: 0 additions & 15 deletions test/PHPMailer/DKIMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,6 @@ public function testDKIMSigningMail()
self::assertTrue($this->Mail->send(), 'DKIM signed mail via mail() failed');
}

/**
* Verify behaviour of the DKIM_Sign method when Open SSL is not available.
*
* @covers \PHPMailer\PHPMailer\PHPMailer::DKIM_Sign
*/
public function testDKIMSignOpenSSLNotAvailable()
{
if (extension_loaded('openssl')) {
$this->markTestSkipped('Test requires OpenSSL *not* to be available');
}

$signature = $this->Mail->DKIM_Sign('foo');
self::assertSame('', $signature);
}

/**
* Verify behaviour of the DKIM_Sign method when Open SSL is not available and exceptions is enabled.
*
Expand Down
47 changes: 47 additions & 0 deletions test/PHPMailer/DKIMWithoutExceptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* PHPMailer - PHP email transport unit tests.
* PHP version 5.5.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Andy Prevost
* @copyright 2012 - 2020 Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html GNU Lesser General Public License
*/

namespace PHPMailer\Test\PHPMailer;

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\Test\TestCase;

/**
* Test DKIM signing functionality.
*
* @group dkim
*/
final class DKIMWithoutExceptionsTest extends TestCase
{
/**
* Whether or not to initialize the PHPMailer object to throw exceptions.
*
* @var bool|null
*/
const USE_EXCEPTIONS = false;

/**
* Verify behaviour of the DKIM_Sign method when Open SSL is not available and exceptions is disabled.
*
* @covers \PHPMailer\PHPMailer\PHPMailer::DKIM_Sign
*/
public function testDKIMSignOpenSSLNotAvailable()
{
if (extension_loaded('openssl')) {
$this->markTestSkipped('Test requires OpenSSL *not* to be available');
}

$signature = $this->Mail->DKIM_Sign('foo');
self::assertSame('', $signature);
}
}

0 comments on commit 78146fb

Please sign in to comment.