Skip to content

Commit

Permalink
DncReasonHelper used UnknownDncReasonException when receives unknown …
Browse files Browse the repository at this point in the history
…DNC status ID
  • Loading branch information
hluchas committed Feb 22, 2019
1 parent acf7f9c commit 2323cf1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
16 changes: 16 additions & 0 deletions app/bundles/LeadBundle/Exception/UnknownDncReasonException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* @copyright 2018 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Mautic\LeadBundle\Exception;

class UnknownDncReasonException extends \Exception
{
}
5 changes: 4 additions & 1 deletion app/bundles/LeadBundle/Templating/Helper/DncReasonHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Mautic\LeadBundle\Templating\Helper;

use Mautic\LeadBundle\Entity\DoNotContact;
use Mautic\LeadBundle\Exception\UnknownDncReasonException;
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\Translation\TranslatorInterface;

Expand Down Expand Up @@ -39,6 +40,8 @@ public function __construct(TranslatorInterface $translator)
* @param int $reasonId
*
* @return string
*
* @throws UnknownDncReasonException
*/
public function toText($reasonId)
{
Expand All @@ -56,7 +59,7 @@ public function toText($reasonId)
$reasonKey = 'mautic.lead.event.donotcontact_manual';
break;
default:
throw new \InvalidArgumentException(
throw new UnknownDncReasonException(
sprintf("Unknown DNC reason ID '%c'", $reasonId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Mautic\LeadBundle\Tests\Templating;

use Mautic\LeadBundle\Entity\DoNotContact;
use Mautic\LeadBundle\Exception\UnknownDncReasonException;
use Mautic\LeadBundle\Templating\Helper\DncReasonHelper;
use Symfony\Component\Translation\TranslatorInterface;

Expand Down Expand Up @@ -49,7 +50,7 @@ public function testToText()

$translator = $this->createMock(TranslatorInterface::class);
$dncReasonHelper = new DncReasonHelper($translator);
$this->expectException(\InvalidArgumentException::class);
$this->expectException(UnknownDncReasonException::class);
$dncReasonHelper->toText(999);
}

Expand Down

0 comments on commit 2323cf1

Please sign in to comment.