Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CentralNic
Badcow-DNS
Commits
d551dc62
Unverified
Commit
d551dc62
authored
May 06, 2019
by
Sam Williams
Committed by
GitHub
May 06, 2019
Browse files
Merge pull request #34 from Badcow/issue-33
MX::output() throws exception on missing parameters.
parents
56e44569
0c5082c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/Rdata/MX.php
View file @
d551dc62
...
...
@@ -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
;
}
}
tests/Rdata/MxRdataTest.php
View file @
d551dc62
...
...
@@ -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
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment