Unverified Commit d551dc62 authored by Sam Williams's avatar Sam Williams Committed by GitHub
Browse files

Merge pull request #34 from Badcow/issue-33

MX::output() throws exception on missing parameters.
parents 56e44569 0c5082c2
......@@ -64,9 +64,19 @@ class MX implements RdataInterface
/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException Throws exception if preference or exchange have not been set.
*/
public function output(): string
{
if (null === $this->preference) {
throw new \InvalidArgumentException('No preference has been set on MX object.');
}
if (null === $this->exchange) {
throw new \InvalidArgumentException('No exchange has been set on MX object.');
}
return $this->preference.' '.$this->exchange;
}
}
......@@ -12,6 +12,7 @@
namespace Badcow\DNS\Tests\Rdata;
use Badcow\DNS\Rdata\MX;
use Badcow\DNS\ResourceRecord;
class MxRdataTest extends \PHPUnit\Framework\TestCase
{
......@@ -36,4 +37,24 @@ class MxRdataTest extends \PHPUnit\Framework\TestCase
$this->assertEquals('42 foo.example.com.', $mx->output());
}
public function testOutputThrowsExceptionWhenMissingPreference()
{
$mx = new MX();
$mx->setExchange('mail.google.com.');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('No preference has been set on MX object.');
$mx->output();
}
public function testOutputThrowsExceptionWhenMissingExchange()
{
$mx = new MX();
$mx->setPreference(15);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('No exchange has been set on MX object.');
$mx->output();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment