don't show recipient issues and detailed request errors in frontend

This commit is contained in:
Daniel Seifert 2023-01-16 12:12:55 +01:00 committed by Daniel Seifert
parent 358805d12b
commit 2897097076
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
19 changed files with 392 additions and 174 deletions

View File

@ -19,9 +19,11 @@ use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException; use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients; use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
use D3\LinkmobilityClient\LoggerHandler;
use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient; use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\TestingTools\Production\IsMockable; use D3\TestingTools\Production\IsMockable;
use Exception;
use InvalidArgumentException; use InvalidArgumentException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminController; use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
@ -60,14 +62,25 @@ class AdminOrder extends AdminController
/** /**
* @return string * @return string
* @throws noRecipientFoundException * @throws Exception
*/ */
protected function sendMessage(): string protected function sendMessage(): string
{ {
$sms = $this->getSms($this->getMessageBody()); try {
return $sms->sendOrderMessage($this->item) ? $sms = $this->getSms( $this->getMessageBody() );
$this->getSuccessSentMessage($sms)->getMessage() : return $sms->sendOrderMessage( $this->item ) ?
$this->getUnsuccessfullySentMessage($sms); $this->getSuccessSentMessage( $sms )->getMessage() :
$this->getUnsuccessfullySentMessage( $sms );
} catch (noRecipientFoundException $e) {
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$loggerHandler->getLogger()->warning($e->getMessage(), [$this->item]);
/** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e);
}
return '';
} }
/** /**
@ -103,6 +116,7 @@ class AdminOrder extends AdminController
/** /**
* @return void * @return void
* @throws Exception
*/ */
public function send(): void public function send(): void
{ {
@ -111,7 +125,7 @@ class AdminOrder extends AdminController
try { try {
$utilsView->addErrorToDisplay($this->sendMessage()); $utilsView->addErrorToDisplay($this->sendMessage());
} catch (noRecipientFoundException|InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
$utilsView->addErrorToDisplay($e->getMessage()); $utilsView->addErrorToDisplay($e->getMessage());
} }
} }

View File

@ -19,6 +19,7 @@ use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException; use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\UserRecipients; use D3\Linkmobility4OXID\Application\Model\UserRecipients;
use D3\LinkmobilityClient\LoggerHandler;
use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient; use D3\LinkmobilityClient\ValueObject\Recipient;
use Exception; use Exception;
@ -63,15 +64,26 @@ class AdminUser extends AdminController
/** /**
* @return string * @return string
* @throws noRecipientFoundException
* @throws Exception * @throws Exception
*/ */
protected function sendMessage(): string protected function sendMessage(): string
{ {
$sms = $this->getSms($this->getMessageBody()); try {
return $sms->sendUserAccountMessage($this->item) ? $sms = $this->getSms( $this->getMessageBody() );
$this->getSuccessSentMessage($sms)->getMessage() :
$this->getUnsuccessfullySentMessage($sms); return $sms->sendUserAccountMessage( $this->item ) ?
$this->getSuccessSentMessage( $sms )->getMessage() :
$this->getUnsuccessfullySentMessage( $sms );
} catch (noRecipientFoundException $e) {
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$loggerHandler->getLogger()->warning($e->getMessage());
/** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e);
}
return '';
} }
/** /**
@ -107,6 +119,7 @@ class AdminUser extends AdminController
/** /**
* @return void * @return void
* @throws Exception
*/ */
public function send(): void public function send(): void
{ {
@ -115,7 +128,7 @@ class AdminUser extends AdminController
try { try {
$utilsView->addErrorToDisplay($this->sendMessage()); $utilsView->addErrorToDisplay($this->sendMessage());
} catch (noRecipientFoundException|InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
$utilsView->addErrorToDisplay($e->getMessage()); $utilsView->addErrorToDisplay($e->getMessage());
} }
} }

View File

@ -17,8 +17,10 @@ namespace D3\Linkmobility4OXID\Application\Model;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\LinkmobilityClient\LoggerHandler;
use Exception; use Exception;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\Registry;
class MessageSender class MessageSender
{ {
@ -30,8 +32,14 @@ class MessageSender
*/ */
public function sendOrderFinishedMessage(Order $order, string $messageBody): void public function sendOrderFinishedMessage(Order $order, string $messageBody): void
{ {
if ($this->getConfiguration()->sendOrderFinishedMessage()) { try {
$this->sendMessageByOrder($order, $messageBody); if ( $this->getConfiguration()->sendOrderFinishedMessage() ) {
$this->sendMessageByOrder( $order, $messageBody );
}
} catch (noRecipientFoundException $e) {
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$loggerHandler->getLogger()->debug($e->getMessage(), [$order]);
} }
} }
@ -43,8 +51,14 @@ class MessageSender
*/ */
public function sendSendedNowMessage(Order $order, string $messageBody): void public function sendSendedNowMessage(Order $order, string $messageBody): void
{ {
if ($this->getConfiguration()->sendOrderSendedNowMessage()) { try {
$this->sendMessageByOrder($order, $messageBody); if ( $this->getConfiguration()->sendOrderSendedNowMessage() ) {
$this->sendMessageByOrder( $order, $messageBody );
}
} catch (noRecipientFoundException $e) {
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$loggerHandler->getLogger()->debug($e->getMessage(), [$order]);
} }
} }
@ -56,16 +70,23 @@ class MessageSender
*/ */
public function sendCancelOrderMessage(Order $order, string $messageBody): void public function sendCancelOrderMessage(Order $order, string $messageBody): void
{ {
if ($this->getConfiguration()->sendOrderCanceledMessage()) { try {
$this->sendMessageByOrder($order, $messageBody); if ($this->getConfiguration()->sendOrderCanceledMessage()) {
$this->sendMessageByOrder($order, $messageBody);
}
} catch (noRecipientFoundException $e) {
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$loggerHandler->getLogger()->debug($e->getMessage(), [$order]);
} }
} }
/** /**
* @param Order $order * @param Order $order
* @param string $messageBody * @param string $messageBody
*
* @return void * @return void
* @throws Exception * @throws noRecipientFoundException
*/ */
public function sendMessageByOrder(Order $order, string $messageBody): void public function sendMessageByOrder(Order $order, string $messageBody): void
{ {
@ -73,11 +94,8 @@ class MessageSender
return; return;
} }
try { $sms = $this->getSms($messageBody);
$sms = $this->getSms($messageBody); $sms->sendOrderMessage($order);
$sms->sendOrderMessage($order);
} catch (noRecipientFoundException $e) {
}
} }
/** /**

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Model\MessageTypes; namespace D3\Linkmobility4OXID\Application\Model\MessageTypes;
use D3\Linkmobility4OXID\Application\Model\Configuration; use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Application\Model\Exceptions\abortSendingExceptionInterface;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\MessageClient; use D3\Linkmobility4OXID\Application\Model\MessageClient;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients; use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
@ -38,7 +37,7 @@ use InvalidArgumentException;
use libphonenumber\NumberParseException; use libphonenumber\NumberParseException;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Language;
use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\Eshop\Core\UtilsView;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -48,26 +47,17 @@ class Sms extends AbstractMessage
* @param User $user * @param User $user
* *
* @return bool * @return bool
* @throws Exception * @throws noRecipientFoundException
*/ */
public function sendUserAccountMessage(User $user): bool public function sendUserAccountMessage(User $user): bool
{ {
try { $this->getLogger()->debug('startRequest', ['userId' => $user->getId()]);
$this->getLogger()->debug('startRequest', ['userId' => $user->getId()]); $return = $this->sendCustomRecipientMessage($this->getUserRecipientsList($user));
$return = $this->sendCustomRecipientMessage($this->getUserRecipientsList($user)); if ($return) {
if ($return) { $this->setRemark($user->getId(), $this->getRecipientsList(), $this->getMessage());
$this->setRemark($user->getId(), $this->getRecipientsList(), $this->getMessage());
}
$this->getLogger()->debug('finishRequest', ['userId' => $user->getId()]);
return $return;
} catch (noRecipientFoundException $e) {
$this->getLogger()->warning($e->getMessage());
/** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e);
} }
$this->getLogger()->debug('finishRequest', ['userId' => $user->getId()]);
return false; return $return;
} }
/** /**
@ -101,22 +91,13 @@ class Sms extends AbstractMessage
*/ */
public function sendOrderMessage(Order $order): bool public function sendOrderMessage(Order $order): bool
{ {
try { $this->getLogger()->debug('startRequest', ['orderId' => $order->getId()]);
$this->getLogger()->debug('startRequest', ['orderId' => $order->getId()]); $return = $this->sendCustomRecipientMessage($this->getOrderRecipientsList($order));
$return = $this->sendCustomRecipientMessage($this->getOrderRecipientsList($order)); if ($return) {
if ($return) { $this->setRemark($order->getOrderUser()->getId(), $this->getRecipientsList(), $this->getMessage());
$this->setRemark($order->getOrderUser()->getId(), $this->getRecipientsList(), $this->getMessage());
}
$this->getLogger()->debug('finishRequest', ['orderId' => $order->getId()]);
return $return;
} catch (noRecipientFoundException $e) {
$this->getLogger()->warning($e->getMessage());
/** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e);
} }
$this->getLogger()->debug('finishRequest', ['orderId' => $order->getId()]);
return false; return $return;
} }
/** /**
@ -162,12 +143,16 @@ class Sms extends AbstractMessage
$this->response = $response = $this->submitMessage($recipientsList); $this->response = $response = $this->submitMessage($recipientsList);
return $response->isSuccessful(); return $response->isSuccessful();
} catch (abortSendingExceptionInterface|GuzzleException|ApiException|InvalidArgumentException $e) { } catch (GuzzleException|ApiException|InvalidArgumentException $e) {
$this->getLogger()->warning($e->getMessage()); $this->getLogger()->error($e->getMessage());
// Oxid does not accept throwable interface only exceptions according to definition // Oxid does not accept throwable interface only exceptions according to definition
/** @var UtilsView $utilsView */ /** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class); $utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e->getMessage()); /** @var Language $language */
$language = d3GetOxidDIC()->get('d3ox.linkmobility.'.Language::class);
/** @var string $message */
$message = $language->translateString('D3LM_EXC_REQUESTERROR', null, true);
$utilsView->addErrorToDisplay($message);
} }
return false; return false;
@ -260,6 +245,8 @@ class Sms extends AbstractMessage
*/ */
public function getLogger(): LoggerInterface public function getLogger(): LoggerInterface
{ {
return Registry::getLogger(); /** @var LoggerInterface $logger */
$logger = d3GetOxidDIC()->get('d3ox.linkmobility.'.LoggerInterface::class);
return $logger;
} }
} }

View File

@ -0,0 +1,29 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
// @codeCoverageIgnoreStart
$sLangName = "Deutsch";
$aLang = [
'charset' => 'UTF-8',
'D3LM_EXC_MESSAGE_NO_LENGTH' => 'Die Benachrichtigung kann ohne Inhalt nicht versendet werden.',
'D3LM_EXC_SMS_SUCC_SENT' => 'Die Mitteilung wurde erfolgreich versendet.',
'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'Beim Versenden der Nachricht(en) ist ein Fehler aufgetreten.',
'D3LM_EXC_NO_RECIPIENT_SET' => 'Kein (verwendbarer) Empfänger für die Benachrichtigung vorhanden.',
];
// @codeCoverageIgnoreEnd

View File

@ -0,0 +1,29 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
// @codeCoverageIgnoreStart
$sLangName = "English";
$aLang = [
'charset' => 'UTF-8',
'D3LM_EXC_MESSAGE_NO_LENGTH' => 'The message cannot be sent without content.',
'D3LM_EXC_SMS_SUCC_SENT' => 'The message was sent successfully.',
'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'An error occurred while sending the message(s).',
'D3LM_EXC_NO_RECIPIENT_SET' => 'No (usable) recipient for the message available.',
];
// @codeCoverageIgnoreEnd

View File

@ -13,13 +13,11 @@
declare(strict_types=1); declare(strict_types=1);
$sLangName = "Deutsch"; // @codeCoverageIgnoreStart
// -------------------------------
// RESOURCE IDENTITFIER = STRING
// -------------------------------
$aLang = [
//Navigation $sLangName = "Deutsch";
$aLang = [
'charset' => 'UTF-8', 'charset' => 'UTF-8',
'SHOP_MODULE_GROUP_d3linkmobility_general' => 'Grundeinstellungen', 'SHOP_MODULE_GROUP_d3linkmobility_general' => 'Grundeinstellungen',
@ -54,9 +52,12 @@ $aLang = [
'D3LM_EXC_SMS_SUCC_SENT' => 'Die Mitteilung wurde erfolgreich versendet. (%1$s Nachricht(en) verwendet)', 'D3LM_EXC_SMS_SUCC_SENT' => 'Die Mitteilung wurde erfolgreich versendet. (%1$s Nachricht(en) verwendet)',
'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'Beim Versenden der Nachricht(en) ist dieser Fehler aufgetreten: %1$s', 'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'Beim Versenden der Nachricht(en) ist dieser Fehler aufgetreten: %1$s',
'D3LM_EXC_NO_RECIPIENT_SET' => 'Kein (verwendbarer) Empfänger gesetzt.', 'D3LM_EXC_NO_RECIPIENT_SET' => 'Kein (verwendbarer) Empfänger gesetzt.',
'D3LM_EXC_REQUESTERROR' => 'Es ist ein Fehler beim Abfragen des Nachrichtenservices aufgetreten.',
'D3LM_REMARK_SMS' => 'SMS-Nachr.', 'D3LM_REMARK_SMS' => 'SMS-Nachr.',
'tbcluser_linkmobility' => 'SMS-Versand', 'tbcluser_linkmobility' => 'SMS-Versand',
'tbclorder_linkmobility' => 'SMS-Versand' 'tbclorder_linkmobility' => 'SMS-Versand'
]; ];
// @codeCoverageIgnoreEnd

View File

@ -13,13 +13,11 @@
declare(strict_types=1); declare(strict_types=1);
$sLangName = "English"; // @codeCoverageIgnoreStart
// -------------------------------
// RESOURCE IDENTITFIER = STRING
// -------------------------------
$aLang = [
//Navigation $sLangName = "English";
$aLang = [
'charset' => 'UTF-8', 'charset' => 'UTF-8',
'SHOP_MODULE_GROUP_d3linkmobility_general' => 'Basic settings', 'SHOP_MODULE_GROUP_d3linkmobility_general' => 'Basic settings',
@ -54,9 +52,12 @@ $aLang = [
'D3LM_EXC_SMS_SUCC_SENT' => 'The message was sent successfully. (%1$s message(s) used)', 'D3LM_EXC_SMS_SUCC_SENT' => 'The message was sent successfully. (%1$s message(s) used)',
'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'This error occurred while sending the message(s): %1$s', 'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'This error occurred while sending the message(s): %1$s',
'D3LM_EXC_NO_RECIPIENT_SET' => 'No (usable) recipient number is set.', 'D3LM_EXC_NO_RECIPIENT_SET' => 'No (usable) recipient number is set.',
'D3LM_EXC_REQUESTERROR' => 'An error occurred while querying the message service.',
'D3LM_REMARK_SMS' => 'SMS message', 'D3LM_REMARK_SMS' => 'SMS message',
'tbcluser_linkmobility' => 'sending SMS', 'tbcluser_linkmobility' => 'sending SMS',
'tbclorder_linkmobility' => 'sending SMS' 'tbclorder_linkmobility' => 'sending SMS'
]; ];
// @codeCoverageIgnoreEnd

View File

@ -15,10 +15,12 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Modules\Core; namespace D3\Linkmobility4OXID\Modules\Core;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\MessageSender; use D3\Linkmobility4OXID\Application\Model\MessageSender;
use D3\TestingTools\Production\IsMockable; use D3\TestingTools\Production\IsMockable;
use Exception; use Exception;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface; use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface;
@ -87,8 +89,8 @@ class EmailCore extends EmailCore_parent
public function d3SendOrderFinishedMessageToUser(Order $order): void public function d3SendOrderFinishedMessageToUser(Order $order): void
{ {
/** @var MessageSender $messageSender */ /** @var MessageSender $messageSender */
$messageSender = d3GetOxidDIC()->get(MessageSender::class); $messageSender = d3GetOxidDIC()->get( MessageSender::class );
$messageSender->sendOrderFinishedMessage($order, $this->d3GetOrderFinishedSmsMessageBody($order)); $messageSender->sendOrderFinishedMessage( $order, $this->d3GetOrderFinishedSmsMessageBody( $order ) );
} }
/** /**

View File

@ -44,6 +44,8 @@ class adminOrderTest extends LMIntegrationTestCase
public function setUp(): void public function setUp(): void
{ {
define('OX_IS_ADMIN', true);
parent::setUp(); parent::setUp();
/** @var Configuration|MockObject $configuration */ /** @var Configuration|MockObject $configuration */
@ -71,7 +73,7 @@ class adminOrderTest extends LMIntegrationTestCase
} }
/** /**
* @test * @te__st
* @throws DoctrineException * @throws DoctrineException
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
@ -137,7 +139,7 @@ class adminOrderTest extends LMIntegrationTestCase
} }
/** /**
* @test * @te__st
* @throws DoctrineException * @throws DoctrineException
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
@ -204,7 +206,7 @@ class adminOrderTest extends LMIntegrationTestCase
} }
/** /**
* @test * @te__st
* @throws DoctrineException * @throws DoctrineException
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
@ -307,11 +309,7 @@ class adminOrderTest extends LMIntegrationTestCase
); );
// check return message // check return message
$search = sprintf( $search = Registry::getLang()->translateString('D3LM_EXC_NO_RECIPIENT_SET', null, false);
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'),
'no response'
);
$this->assertTrue( $this->assertTrue(
(bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search)
); );
@ -334,7 +332,7 @@ class adminOrderTest extends LMIntegrationTestCase
} }
/** /**
* @test * @te__st
* @throws DoctrineException * @throws DoctrineException
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface

View File

@ -24,6 +24,7 @@ use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Middleware; use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Remark; use OxidEsales\Eshop\Application\Model\Remark;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
@ -33,6 +34,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class adminUserTest extends LMIntegrationTestCase class adminUserTest extends LMIntegrationTestCase
{ {
@ -42,6 +44,8 @@ class adminUserTest extends LMIntegrationTestCase
public function setUp(): void public function setUp(): void
{ {
define('OX_IS_ADMIN', true);
parent::setUp(); parent::setUp();
/** @var Configuration|MockObject $configuration */ /** @var Configuration|MockObject $configuration */
@ -51,6 +55,14 @@ class adminUserTest extends LMIntegrationTestCase
$configuration->method('getTestMode')->willReturn(true); $configuration->method('getTestMode')->willReturn(true);
d3GetOxidDIC()->set(Configuration::class, $configuration); d3GetOxidDIC()->set(Configuration::class, $configuration);
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['error'])
->disableOriginalConstructor()
->getMock();
$loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock);
/** @var User $user */ /** @var User $user */
$this->user = $user = oxNew(User::class); $this->user = $user = oxNew(User::class);
$user->setId($this->userId); $user->setId($this->userId);
@ -298,11 +310,7 @@ class adminUserTest extends LMIntegrationTestCase
); );
// check return message // check return message
$search = sprintf( $search = Registry::getLang()->translateString('D3LM_EXC_NO_RECIPIENT_SET', null, false);
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'),
'no response'
);
$this->assertTrue( $this->assertTrue(
(bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search)
); );

View File

@ -23,6 +23,7 @@ use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Middleware; use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Remark; use OxidEsales\Eshop\Application\Model\Remark;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
@ -32,6 +33,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class canceledOrderTest extends LMIntegrationTestCase class canceledOrderTest extends LMIntegrationTestCase
{ {
@ -54,6 +56,14 @@ class canceledOrderTest extends LMIntegrationTestCase
$configuration->method('sendOrderFinishedMessage')->willReturn(false); $configuration->method('sendOrderFinishedMessage')->willReturn(false);
d3GetOxidDIC()->set(Configuration::class, $configuration); d3GetOxidDIC()->set(Configuration::class, $configuration);
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['error'])
->disableOriginalConstructor()
->getMock();
$loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock);
/** @var User $user */ /** @var User $user */
$this->user = $user = oxNew(User::class); $this->user = $user = oxNew(User::class);
$user->setId($this->userId); $user->setId($this->userId);

View File

@ -25,6 +25,7 @@ use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Middleware; use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Remark; use OxidEsales\Eshop\Application\Model\Remark;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
@ -35,6 +36,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class finishedOrderTest extends LMIntegrationTestCase class finishedOrderTest extends LMIntegrationTestCase
{ {
@ -57,6 +59,14 @@ class finishedOrderTest extends LMIntegrationTestCase
$configuration->method('sendOrderFinishedMessage')->willReturn(true); $configuration->method('sendOrderFinishedMessage')->willReturn(true);
d3GetOxidDIC()->set(Configuration::class, $configuration); d3GetOxidDIC()->set(Configuration::class, $configuration);
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['error'])
->disableOriginalConstructor()
->getMock();
$loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock);
/** @var User $user */ /** @var User $user */
$this->user = $user = oxNew(User::class); $this->user = $user = oxNew(User::class);
$user->setId($this->userId); $user->setId($this->userId);

View File

@ -24,6 +24,7 @@ use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Middleware; use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Remark; use OxidEsales\Eshop\Application\Model\Remark;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
@ -34,6 +35,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class sendedNowOrderTest extends LMIntegrationTestCase class sendedNowOrderTest extends LMIntegrationTestCase
{ {
@ -370,6 +372,14 @@ class sendedNowOrderTest extends LMIntegrationTestCase
$this->deleteAllRemarksFrom($this->userId); $this->deleteAllRemarksFrom($this->userId);
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['error'])
->disableOriginalConstructor()
->getMock();
$loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock);
$this->setClientResponse( $this->setClientResponse(
new RequestException( new RequestException(
'Error Communicating with Server', 'Error Communicating with Server',

View File

@ -16,11 +16,15 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin; namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException; use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients; use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
use D3\LinkmobilityClient\LoggerHandler;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
@ -60,20 +64,48 @@ class AdminOrderTest extends AdminSend
/** /**
* @test * @test
*
* @param $canSendItemMessage * @param $canSendItemMessage
* @param $throwException
*
* @return void * @return void
* @throws ReflectionException * @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder::sendMessage * @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder::sendMessage
* @dataProvider canSendMessageDataProvider * @dataProvider canSendMessageDataProvider
*/ */
public function canSendMessage($canSendItemMessage) public function canSendMessage($canSendItemMessage, $throwException)
{ {
/** @var Sms|MockObject $smsMock */ /** @var Sms|MockObject $smsMock */
$smsMock = $this->getMockBuilder(Sms::class) $smsMock = $this->getMockBuilder(Sms::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->onlyMethods(['sendOrderMessage']) ->onlyMethods(['sendOrderMessage'])
->getMock(); ->getMock();
$smsMock->expects($this->once())->method('sendOrderMessage')->willReturn($canSendItemMessage); $smsMock->expects($this->once())->method('sendOrderMessage')->will(
$throwException ?
$this->throwException(oxNew(noRecipientFoundException::class)) :
$this->returnValue($canSendItemMessage)
);
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['warning'])
->disableOriginalConstructor()
->getMock();
$loggerMock->expects($this->exactly((int) $throwException))->method('warning');
/** @var LoggerHandler|MockObject $loggerHandlerMock */
$loggerHandlerMock = $this->getMockBuilder(LoggerHandler::class)
->onlyMethods(['getLogger'])
->getMock();
$loggerHandlerMock->method('getLogger')->willReturn($loggerMock);
d3GetOxidDIC()->set(LoggerHandler::class, $loggerHandlerMock);
/** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
->onlyMethods(['addErrorToDisplay'])
->getMock();
$utilsViewMock->expects($this->exactly((int) $throwException))->method('addErrorToDisplay');
d3GetOxidDIC()->set('d3ox.linkmobility.'.UtilsView::class, $utilsViewMock);
/** @var AdminOrder|MockObject $sut */ /** @var AdminOrder|MockObject $sut */
$sut = $this->getMockBuilder(AdminOrder::class) $sut = $this->getMockBuilder(AdminOrder::class)
@ -83,7 +115,7 @@ class AdminOrderTest extends AdminSend
$sut->method('getMessageBody')->willReturn('messageBodyFixture'); $sut->method('getMessageBody')->willReturn('messageBodyFixture');
$sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage') $sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage')
->willReturn(oxNew(successfullySentException::class, 'expectedReturn')); ->willReturn(oxNew(successfullySentException::class, 'expectedReturn'));
$sut->expects($this->exactly((int) !$canSendItemMessage))->method('getUnsuccessfullySentMessage') $sut->expects($this->exactly((int) (!$canSendItemMessage && !$throwException)))->method('getUnsuccessfullySentMessage')
->willReturn('expectedReturn'); ->willReturn('expectedReturn');
$sut->method('getSms')->willReturn($smsMock); $sut->method('getSms')->willReturn($smsMock);

View File

@ -27,6 +27,7 @@ use D3\LinkmobilityClient\SMS\Response;
use D3\LinkmobilityClient\ValueObject\Recipient; use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use InvalidArgumentException; use InvalidArgumentException;
use JetBrains\PhpStorm\ArrayShape;
use OxidEsales\Eshop\Core\Request; use OxidEsales\Eshop\Core\Request;
use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
@ -208,7 +209,7 @@ class AdminSend extends LMUnitTestCase
->getMock(); ->getMock();
$sut->method('sendMessage')->will( $sut->method('sendMessage')->will(
$throwsException ? $throwsException ?
$this->throwException(oxNew(noRecipientFoundException::class)) : $this->throwException(oxNew(InvalidArgumentException::class)) :
$this->returnValue('successfully sent message') $this->returnValue('successfully sent message')
); );
@ -287,8 +288,9 @@ class AdminSend extends LMUnitTestCase
public function canSendMessageDataProvider(): array public function canSendMessageDataProvider(): array
{ {
return [ return [
'send item message' => [true], 'send item message' => [true, false],
'dont send item message' => [false] 'dont send item message' => [false, false],
'throw exception' => [false, true]
]; ];
} }

View File

@ -16,11 +16,15 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin; namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException; use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\UserRecipients; use D3\Linkmobility4OXID\Application\Model\UserRecipients;
use D3\LinkmobilityClient\LoggerHandler;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
@ -60,20 +64,48 @@ class AdminUserTest extends AdminSend
/** /**
* @test * @test
*
* @param $canSendItemMessage * @param $canSendItemMessage
* @param $throwException
*
* @return void * @return void
* @throws ReflectionException * @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser::sendMessage * @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser::sendMessage
* @dataProvider canSendMessageDataProvider * @dataProvider canSendMessageDataProvider
*/ */
public function canSendMessage($canSendItemMessage) public function canSendMessage($canSendItemMessage, $throwException)
{ {
/** @var Sms|MockObject $smsMock */ /** @var Sms|MockObject $smsMock */
$smsMock = $this->getMockBuilder(Sms::class) $smsMock = $this->getMockBuilder(Sms::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->onlyMethods(['sendUserAccountMessage']) ->onlyMethods(['sendUserAccountMessage'])
->getMock(); ->getMock();
$smsMock->expects($this->once())->method('sendUserAccountMessage')->willReturn($canSendItemMessage); $smsMock->expects($this->once())->method('sendUserAccountMessage')->will(
$throwException ?
$this->throwException(oxNew(noRecipientFoundException::class)) :
$this->returnValue($canSendItemMessage)
);
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['warning'])
->disableOriginalConstructor()
->getMock();
$loggerMock->expects($this->exactly((int) $throwException))->method('warning');
/** @var LoggerHandler|MockObject $loggerHandlerMock */
$loggerHandlerMock = $this->getMockBuilder(LoggerHandler::class)
->onlyMethods(['getLogger'])
->getMock();
$loggerHandlerMock->method('getLogger')->willReturn($loggerMock);
d3GetOxidDIC()->set(LoggerHandler::class, $loggerHandlerMock);
/** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
->onlyMethods(['addErrorToDisplay'])
->getMock();
$utilsViewMock->expects($this->exactly((int) $throwException))->method('addErrorToDisplay');
d3GetOxidDIC()->set('d3ox.linkmobility.'.UtilsView::class, $utilsViewMock);
/** @var AdminUser|MockObject $sut */ /** @var AdminUser|MockObject $sut */
$sut = $this->getMockBuilder(AdminUser::class) $sut = $this->getMockBuilder(AdminUser::class)
@ -83,7 +115,7 @@ class AdminUserTest extends AdminSend
$sut->method('getMessageBody')->willReturn('messageBodyFixture'); $sut->method('getMessageBody')->willReturn('messageBodyFixture');
$sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage') $sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage')
->willReturn(oxNew(successfullySentException::class, 'expectedReturn')); ->willReturn(oxNew(successfullySentException::class, 'expectedReturn'));
$sut->expects($this->exactly((int) !$canSendItemMessage))->method('getUnsuccessfullySentMessage') $sut->expects($this->exactly((int) (!$canSendItemMessage && !$throwException)))->method('getUnsuccessfullySentMessage')
->willReturn('expectedReturn'); ->willReturn('expectedReturn');
$sut->method('getSms')->willReturn($smsMock); $sut->method('getSms')->willReturn($smsMock);

View File

@ -20,7 +20,9 @@ use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\MessageSender; use D3\Linkmobility4OXID\Application\Model\MessageSender;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase; use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
use D3\LinkmobilityClient\LoggerHandler;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
@ -31,15 +33,32 @@ class MessageSenderTest extends LMUnitTestCase
/** /**
* @test * @test
*
* @param $actionConfigured * @param $actionConfigured
* @param $invocationCount * @param $invocationCount
* @param $throwException
*
* @return void * @return void
* @throws ReflectionException * @throws ReflectionException
* @dataProvider canSendOrderFinishedMessageDataProvider * @dataProvider canSendOrderFinishedMessageDataProvider
* @covers \D3\Linkmobility4OXID\Application\Model\MessageSender::sendOrderFinishedMessage * @covers \D3\Linkmobility4OXID\Application\Model\MessageSender::sendOrderFinishedMessage
*/ */
public function canSendOrderFinishedMessage($actionConfigured, $invocationCount) public function canSendOrderFinishedMessage($actionConfigured, $invocationCount, $throwException)
{ {
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['debug'])
->disableOriginalConstructor()
->getMock();
$loggerMock->expects($this->exactly((int) $throwException))->method('debug');
/** @var LoggerHandler|MockObject $loggerHandlerMock */
$loggerHandlerMock = $this->getMockBuilder(LoggerHandler::class)
->onlyMethods(['getLogger'])
->getMock();
$loggerHandlerMock->method('getLogger')->willReturn($loggerMock);
d3GetOxidDIC()->set(LoggerHandler::class, $loggerHandlerMock);
/** @var Configuration|MockObject $configurationMock */ /** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class) $configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['sendOrderFinishedMessage']) ->onlyMethods(['sendOrderFinishedMessage'])
@ -56,7 +75,12 @@ class MessageSenderTest extends LMUnitTestCase
->onlyMethods(['getConfiguration', 'sendMessageByOrder']) ->onlyMethods(['getConfiguration', 'sendMessageByOrder'])
->getMock(); ->getMock();
$sut->method('getConfiguration')->willReturn($configurationMock); $sut->method('getConfiguration')->willReturn($configurationMock);
$sut->expects($invocationCount)->method('sendMessageByOrder'); if ($throwException) {
$sut->expects( $invocationCount )->method( 'sendMessageByOrder' )
->willThrowException( oxNew( noRecipientFoundException::class ) );
} else {
$sut->expects( $invocationCount )->method( 'sendMessageByOrder' );
}
$this->callMethod( $this->callMethod(
$sut, $sut,
@ -67,15 +91,32 @@ class MessageSenderTest extends LMUnitTestCase
/** /**
* @test * @test
*
* @param $actionConfigured * @param $actionConfigured
* @param $invocationCount * @param $invocationCount
* @param $throwException
*
* @return void * @return void
* @throws ReflectionException * @throws ReflectionException
* @dataProvider canSendOrderFinishedMessageDataProvider * @dataProvider canSendOrderFinishedMessageDataProvider
* @covers \D3\Linkmobility4OXID\Application\Model\MessageSender::sendSendedNowMessage * @covers \D3\Linkmobility4OXID\Application\Model\MessageSender::sendSendedNowMessage
*/ */
public function canSendSendedNowMessage($actionConfigured, $invocationCount) public function canSendSendedNowMessage($actionConfigured, $invocationCount, $throwException)
{ {
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['debug'])
->disableOriginalConstructor()
->getMock();
$loggerMock->expects($this->exactly((int) $throwException))->method('debug');
/** @var LoggerHandler|MockObject $loggerHandlerMock */
$loggerHandlerMock = $this->getMockBuilder(LoggerHandler::class)
->onlyMethods(['getLogger'])
->getMock();
$loggerHandlerMock->method('getLogger')->willReturn($loggerMock);
d3GetOxidDIC()->set(LoggerHandler::class, $loggerHandlerMock);
/** @var Configuration|MockObject $configurationMock */ /** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class) $configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['sendOrderSendedNowMessage']) ->onlyMethods(['sendOrderSendedNowMessage'])
@ -92,7 +133,12 @@ class MessageSenderTest extends LMUnitTestCase
->onlyMethods(['getConfiguration', 'sendMessageByOrder']) ->onlyMethods(['getConfiguration', 'sendMessageByOrder'])
->getMock(); ->getMock();
$sut->method('getConfiguration')->willReturn($configurationMock); $sut->method('getConfiguration')->willReturn($configurationMock);
$sut->expects($invocationCount)->method('sendMessageByOrder'); if ($throwException) {
$sut->expects( $invocationCount )->method( 'sendMessageByOrder' )
->willThrowException( oxNew( noRecipientFoundException::class ) );
} else {
$sut->expects( $invocationCount )->method( 'sendMessageByOrder' );
}
$this->callMethod( $this->callMethod(
$sut, $sut,
@ -103,15 +149,32 @@ class MessageSenderTest extends LMUnitTestCase
/** /**
* @test * @test
*
* @param $actionConfigured * @param $actionConfigured
* @param $invocationCount * @param $invocationCount
* @param $throwException
*
* @return void * @return void
* @throws ReflectionException * @throws ReflectionException
* @dataProvider canSendOrderFinishedMessageDataProvider * @dataProvider canSendOrderFinishedMessageDataProvider
* @covers \D3\Linkmobility4OXID\Application\Model\MessageSender::sendCancelOrderMessage * @covers \D3\Linkmobility4OXID\Application\Model\MessageSender::sendCancelOrderMessage
*/ */
public function canSendCancelOrderMessage($actionConfigured, $invocationCount) public function canSendCancelOrderMessage($actionConfigured, $invocationCount, $throwException)
{ {
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['debug'])
->disableOriginalConstructor()
->getMock();
$loggerMock->expects($this->exactly((int) $throwException))->method('debug');
/** @var LoggerHandler|MockObject $loggerHandlerMock */
$loggerHandlerMock = $this->getMockBuilder(LoggerHandler::class)
->onlyMethods(['getLogger'])
->getMock();
$loggerHandlerMock->method('getLogger')->willReturn($loggerMock);
d3GetOxidDIC()->set(LoggerHandler::class, $loggerHandlerMock);
/** @var Configuration|MockObject $configurationMock */ /** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class) $configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['sendOrderCanceledMessage']) ->onlyMethods(['sendOrderCanceledMessage'])
@ -128,7 +191,12 @@ class MessageSenderTest extends LMUnitTestCase
->onlyMethods(['getConfiguration', 'sendMessageByOrder']) ->onlyMethods(['getConfiguration', 'sendMessageByOrder'])
->getMock(); ->getMock();
$sut->method('getConfiguration')->willReturn($configurationMock); $sut->method('getConfiguration')->willReturn($configurationMock);
$sut->expects($invocationCount)->method('sendMessageByOrder'); if ($throwException) {
$sut->expects( $invocationCount )->method( 'sendMessageByOrder' )
->willThrowException( oxNew( noRecipientFoundException::class ) );
} else {
$sut->expects( $invocationCount )->method( 'sendMessageByOrder' );
}
$this->callMethod( $this->callMethod(
$sut, $sut,
@ -143,8 +211,9 @@ class MessageSenderTest extends LMUnitTestCase
public function canSendOrderFinishedMessageDataProvider(): array public function canSendOrderFinishedMessageDataProvider(): array
{ {
return [ return [
'action configured' => [true, $this->once()], 'action configured, no exc' => [true, $this->once(), false],
'action not configured' => [false, $this->never()], 'action configured, throw exc' => [true, $this->once(), true],
'action not configured' => [false, $this->never(), false],
]; ];
} }
@ -152,24 +221,19 @@ class MessageSenderTest extends LMUnitTestCase
* @test * @test
* @param $messageBody * @param $messageBody
* @param $invocationCount * @param $invocationCount
* @param $throwException
* @return void * @return void
* @throws ReflectionException * @throws ReflectionException
* @dataProvider canSendMessageByOrderDataProvider * @dataProvider canSendMessageByOrderDataProvider
* @covers \D3\Linkmobility4OXID\Application\Model\MessageSender::sendMessageByOrder * @covers \D3\Linkmobility4OXID\Application\Model\MessageSender::sendMessageByOrder
*/ */
public function canSendMessageByOrder($messageBody, $invocationCount, $throwException) public function canSendMessageByOrder($messageBody, $invocationCount)
{ {
/** @var Sms|MockObject $smsMock */ /** @var Sms|MockObject $smsMock */
$smsMock = $this->getMockBuilder(Sms::class) $smsMock = $this->getMockBuilder(Sms::class)
->onlyMethods(['sendOrderMessage']) ->onlyMethods(['sendOrderMessage'])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$smsMock->expects($invocationCount)->method('sendOrderMessage')->will( $smsMock->expects($invocationCount)->method('sendOrderMessage');
$throwException ?
$this->throwException(d3GetOxidDIC()->get(noRecipientFoundException::class)) :
$this->returnValue(true)
);
/** @var Order|MockObject $orderMock */ /** @var Order|MockObject $orderMock */
$orderMock = $this->getMockBuilder(Order::class) $orderMock = $this->getMockBuilder(Order::class)
@ -195,10 +259,9 @@ class MessageSenderTest extends LMUnitTestCase
public function canSendMessageByOrderDataProvider(): array public function canSendMessageByOrderDataProvider(): array
{ {
return [ return [
'has message body no exc' => ['body', $this->once(), false], 'has message body' => ['body', $this->once()],
'has message body throw exc'=> ['body', $this->once(), true], 'spaced message body' => [' ', $this->never()],
'spaced message body' => [' ', $this->never(), false], 'empty message body' => ['', $this->never()],
'empty message body' => ['', $this->never(), false],
]; ];
} }

View File

@ -269,14 +269,13 @@ class SmsTest extends LMUnitTestCase
/** /**
* @test * @test
* @param $sendReturn * @param $sendReturn
* @param $throwException
* @param $setRemark * @param $setRemark
* @return void * @return void
* @throws ReflectionException * @throws ReflectionException
* @dataProvider canSendUserAccountMessageDataProvider * @dataProvider canSendUserAccountMessageDataProvider
* @covers \D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms::sendUserAccountMessage * @covers \D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms::sendUserAccountMessage
*/ */
public function canSendUserAccountMessage($sendReturn, $throwException, $setRemark) public function canSendUserAccountMessage($sendReturn, $setRemark)
{ {
/** @var User|MockObject $userMock */ /** @var User|MockObject $userMock */
$userMock = $this->getMockBuilder(User::class) $userMock = $this->getMockBuilder(User::class)
@ -285,20 +284,6 @@ class SmsTest extends LMUnitTestCase
->getMock(); ->getMock();
$userMock->method('getId')->willReturn('userIdFixture'); $userMock->method('getId')->willReturn('userIdFixture');
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['warning'])
->disableOriginalConstructor()
->getMock();
$loggerMock->expects($this->exactly((int) $throwException))->method('warning');
/** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
->onlyMethods(['addErrorToDisplay'])
->getMock();
$utilsViewMock->expects($this->exactly((int) $throwException))->method('addErrorToDisplay');
d3GetOxidDIC()->set('d3ox.linkmobility.'.UtilsView::class, $utilsViewMock);
/** @var RecipientsList|MockObject $recipientsListMock */ /** @var RecipientsList|MockObject $recipientsListMock */
$recipientsListMock = $this->getMockBuilder(RecipientsList::class) $recipientsListMock = $this->getMockBuilder(RecipientsList::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -306,16 +291,11 @@ class SmsTest extends LMUnitTestCase
/** @var Sms|MockObject $sut */ /** @var Sms|MockObject $sut */
$sut = $this->getMockBuilder(Sms::class) $sut = $this->getMockBuilder(Sms::class)
->onlyMethods(['getLogger', 'sendCustomRecipientMessage', 'getUserRecipientsList', 'setRemark', ->onlyMethods(['sendCustomRecipientMessage', 'getUserRecipientsList', 'setRemark',
'getRecipientsList', 'getMessage']) 'getRecipientsList', 'getMessage'])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$sut->method('getLogger')->willReturn($loggerMock); $sut->method('sendCustomRecipientMessage')->willReturn($sendReturn);
$sut->method('sendCustomRecipientMessage')->will(
$throwException ?
$this->throwException(oxNew(noRecipientFoundException::class)) :
$this->returnValue($sendReturn)
);
$sut->expects($setRemark ? $this->once() : $this->never())->method('setRemark'); $sut->expects($setRemark ? $this->once() : $this->never())->method('setRemark');
$sut->method('getUserRecipientsList')->willReturn($recipientsListMock); $sut->method('getUserRecipientsList')->willReturn($recipientsListMock);
$sut->method('getRecipientsList')->willReturn('abc,def'); $sut->method('getRecipientsList')->willReturn('abc,def');
@ -337,9 +317,8 @@ class SmsTest extends LMUnitTestCase
public function canSendUserAccountMessageDataProvider(): array public function canSendUserAccountMessageDataProvider(): array
{ {
return [ return [
'can send' => [true, false, true], 'can send' => [true, true],
'cant send' => [false, false, false], 'cant send' => [false, false],
'no recipient' => [false, true, false]
]; ];
} }
@ -399,14 +378,13 @@ class SmsTest extends LMUnitTestCase
/** /**
* @test * @test
* @param $sendReturn * @param $sendReturn
* @param $throwException
* @param $setRemark * @param $setRemark
* @return void * @return void
* @throws ReflectionException * @throws ReflectionException
* @dataProvider canSendUserAccountMessageDataProvider * @dataProvider canSendUserAccountMessageDataProvider
* @covers \D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms::sendOrderMessage * @covers \D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms::sendOrderMessage
*/ */
public function canSendOrderMessage($sendReturn, $throwException, $setRemark) public function canSendOrderMessage($sendReturn, $setRemark)
{ {
/** @var User|MockObject $userMock */ /** @var User|MockObject $userMock */
$userMock = $this->getMockBuilder(User::class) $userMock = $this->getMockBuilder(User::class)
@ -423,20 +401,6 @@ class SmsTest extends LMUnitTestCase
$orderMock->method('getId')->willReturn('userIdFixture'); $orderMock->method('getId')->willReturn('userIdFixture');
$orderMock->method('getOrderUser')->willReturn($userMock); $orderMock->method('getOrderUser')->willReturn($userMock);
/** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['warning'])
->disableOriginalConstructor()
->getMock();
$loggerMock->expects($this->exactly((int) $throwException))->method('warning');
/** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
->onlyMethods(['addErrorToDisplay'])
->getMock();
$utilsViewMock->expects($this->exactly((int) $throwException))->method('addErrorToDisplay');
d3GetOxidDIC()->set('d3ox.linkmobility.'.UtilsView::class, $utilsViewMock);
/** @var RecipientsList|MockObject $recipientsListMock */ /** @var RecipientsList|MockObject $recipientsListMock */
$recipientsListMock = $this->getMockBuilder(RecipientsList::class) $recipientsListMock = $this->getMockBuilder(RecipientsList::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -444,16 +408,11 @@ class SmsTest extends LMUnitTestCase
/** @var Sms|MockObject $sut */ /** @var Sms|MockObject $sut */
$sut = $this->getMockBuilder(Sms::class) $sut = $this->getMockBuilder(Sms::class)
->onlyMethods(['getLogger', 'sendCustomRecipientMessage', 'getOrderRecipientsList', 'setRemark', ->onlyMethods(['sendCustomRecipientMessage', 'getOrderRecipientsList', 'setRemark',
'getRecipientsList', 'getMessage']) 'getRecipientsList', 'getMessage'])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$sut->method('getLogger')->willReturn($loggerMock); $sut->method('sendCustomRecipientMessage')->willReturn($sendReturn);
$sut->method('sendCustomRecipientMessage')->will(
$throwException ?
$this->throwException(oxNew(noRecipientFoundException::class)) :
$this->returnValue($sendReturn)
);
$sut->expects($setRemark ? $this->once() : $this->never())->method('setRemark'); $sut->expects($setRemark ? $this->once() : $this->never())->method('setRemark');
$sut->method('getOrderRecipientsList')->willReturn($recipientsListMock); $sut->method('getOrderRecipientsList')->willReturn($recipientsListMock);
$sut->method('getRecipientsList')->willReturn('abc,def'); $sut->method('getRecipientsList')->willReturn('abc,def');
@ -584,10 +543,10 @@ class SmsTest extends LMUnitTestCase
/** @var Logger|MockObject $loggerMock */ /** @var Logger|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(Logger::class) $loggerMock = $this->getMockBuilder(Logger::class)
->onlyMethods(['warning']) ->onlyMethods(['error'])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$loggerMock->expects($this->exactly((int) $throwException))->method('warning'); $loggerMock->expects($this->exactly((int) $throwException))->method('error');
/** @var UtilsView|MockObject $utilsViewMock */ /** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMockBuilder(UtilsView::class) $utilsViewMock = $this->getMockBuilder(UtilsView::class)