add DI services
Cette révision appartient à :
Parent
c1f088985a
révision
f21293084e
@ -23,16 +23,14 @@
|
||||
"require": {
|
||||
"php": "^7.1 || ^8.0",
|
||||
"oxid-esales/oxideshop-ce": "6.7 - 6.13",
|
||||
"d3/linkmobility-php-client": "^1.2.0 || ^2.0.0"
|
||||
"d3/linkmobility-php-client": "^1.2.0 || ^2.0.0",
|
||||
"d3/oxid-dic-handler": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"oxid-esales/oxideshop-ce": "~6.10.0",
|
||||
"friendsofphp/php-cs-fixer": "^2.19",
|
||||
"phpstan/phpstan": "^1.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"d3/modcfg": "^5.3.7.0 || ^6.0"
|
||||
},
|
||||
"extra": {
|
||||
"oxideshop": {
|
||||
"source-directory": "/src",
|
||||
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
|
||||
|
||||
use D3\DIContainerHandler\d3DicHandler;
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
||||
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
||||
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
|
||||
@ -35,8 +36,9 @@ class AdminOrder extends AdminSendController
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->item = $this->d3GetMockableOxNewObject(Order::class);
|
||||
$this->itemRecipients = $this->d3GetMockableOxNewObject(OrderRecipients::class, $this->item);
|
||||
$this->item = d3DicHandler::getInstance()->get('d3ox.linkmobility.'.Order::class);
|
||||
d3DicHandler::getInstance()->set(OrderRecipients::class.'.args.order', $this->item);
|
||||
$this->itemRecipients = d3DicHandler::getInstance()->get(OrderRecipients::class);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@ -46,7 +48,9 @@ class AdminOrder extends AdminSendController
|
||||
*/
|
||||
protected function sendMessage(): string
|
||||
{
|
||||
$sms = $this->d3GetMockableOxNewObject(Sms::class, $this->getMessageBody());
|
||||
d3DicHandler::getInstance()->setParameter(Sms::class.'.args.message', $this->getMessageBody());
|
||||
/** @var Sms $sms */
|
||||
$sms = d3DicHandler::getInstance()->get(Sms::class);
|
||||
return $sms->sendOrderMessage($this->item) ?
|
||||
(string) $this->getSuccessSentMessage($sms) :
|
||||
$this->getUnsuccessfullySentMessage($sms);
|
||||
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
|
||||
|
||||
use D3\DIContainerHandler\d3DicHandler;
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
|
||||
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
||||
@ -61,9 +62,12 @@ abstract class AdminSendController extends AdminController
|
||||
try {
|
||||
return $this->itemRecipients->getSmsRecipient();
|
||||
} catch (noRecipientFoundException $e) {
|
||||
/** @var string $message */
|
||||
$message = $this->d3GetMockableRegistryObject(Language::class)->translateString($e->getMessage());
|
||||
$this->d3GetMockableRegistryObject(UtilsView::class)->addErrorToDisplay($message);
|
||||
/** @var Language $lang */
|
||||
$lang = d3DicHandler::getInstance()->get('d3ox.linkmobility.'.Language::class);
|
||||
$message = $lang->translateString($e->getMessage());
|
||||
/** @var UtilsView $utilsView */
|
||||
$utilsView = d3DicHandler::getInstance()->get('d3ox.linkmobility.'.UtilsView::class);
|
||||
$utilsView->addErrorToDisplay($message);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -74,7 +78,8 @@ abstract class AdminSendController extends AdminController
|
||||
*/
|
||||
public function send(): void
|
||||
{
|
||||
$utilsView = $this->d3GetMockableRegistryObject(UtilsView::class);
|
||||
/** @var UtilsView $utilsView */
|
||||
$utilsView = d3DicHandler::getInstance()->get('d3ox.linkmobility.'.UtilsView::class);
|
||||
|
||||
try {
|
||||
$utilsView->addErrorToDisplay($this->sendMessage());
|
||||
@ -89,14 +94,18 @@ abstract class AdminSendController extends AdminController
|
||||
*/
|
||||
protected function getMessageBody(): string
|
||||
{
|
||||
$messageBody = $this->d3GetMockableRegistryObject(Request::class)
|
||||
->getRequestEscapedParameter('messagebody');
|
||||
/** @var Request $request */
|
||||
$request = d3DicHandler::getInstance()->get('d3ox.linkmobility.'.Request::class);
|
||||
$messageBody = $request->getRequestEscapedParameter('messagebody');
|
||||
|
||||
if (false === is_string($messageBody) || strlen(trim($messageBody)) <= 1) {
|
||||
throw $this->d3GetMockableOxNewObject(
|
||||
InvalidArgumentException::class,
|
||||
d3DicHandler::getInstance()->setParameter(
|
||||
'd3ox.linkmobility.'.InvalidArgumentException::class.'.args.message',
|
||||
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
|
||||
);
|
||||
/** @var InvalidArgumentException $exc */
|
||||
$exc = d3DicHandler::getInstance()->get('d3ox.linkmobility.'.InvalidArgumentException::class);
|
||||
throw $exc;
|
||||
}
|
||||
|
||||
return $messageBody;
|
||||
@ -115,7 +124,10 @@ abstract class AdminSendController extends AdminController
|
||||
protected function getSuccessSentMessage(Sms $sms): successfullySentException
|
||||
{
|
||||
$smsCount = $sms->getResponse() ? $sms->getResponse()->getSmsCount() : 0;
|
||||
return $this->d3GetMockableOxNewObject(successfullySentException::class, $smsCount);
|
||||
d3DicHandler::getInstance()->setParameter(successfullySentException::class.'.args.smscount', $smsCount);
|
||||
/** @var successfullySentException $exc */
|
||||
$exc = d3DicHandler::getInstance()->get(successfullySentException::class);
|
||||
return $exc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
|
||||
|
||||
use D3\DIContainerHandler\d3DicHandler;
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
||||
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
||||
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
|
||||
@ -38,8 +39,9 @@ class AdminUser extends AdminSendController
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->item = $this->d3GetMockableOxNewObject(User::class);
|
||||
$this->itemRecipients = $this->d3GetMockableOxNewObject(UserRecipients::class, $this->item);
|
||||
$this->item = d3DicHandler::getInstance()->get('d3ox.linkmobility.'.User::class);
|
||||
d3DicHandler::getInstance()->set(UserRecipients::class.".args.user", $this->item);
|
||||
$this->itemRecipients = d3DicHandler::getInstance()->get(UserRecipients::class);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@ -49,8 +51,9 @@ class AdminUser extends AdminSendController
|
||||
*/
|
||||
protected function sendMessage(): string
|
||||
{
|
||||
d3DicHandler::getInstance()->setParameter(Sms::class.'.args.message', $this->getMessageBody());
|
||||
/** @var Sms $sms */
|
||||
$sms = $this->d3GetMockableOxNewObject(Sms::class, $this->getMessageBody());
|
||||
$sms = d3DicHandler::getInstance()->get(Sms::class);
|
||||
return $sms->sendUserAccountMessage($this->item) ?
|
||||
(string) $this->getSuccessSentMessage($sms) :
|
||||
$this->getUnsuccessfullySentMessage($sms);
|
||||
|
55
src/Config/linkmobility4oxid.yaml
Fichier normal
55
src/Config/linkmobility4oxid.yaml
Fichier normal
@ -0,0 +1,55 @@
|
||||
# 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
|
||||
|
||||
parameters:
|
||||
D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms.args.message:
|
||||
D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException.args.smscount:
|
||||
|
||||
services:
|
||||
_defaults:
|
||||
autowire: false
|
||||
public: true
|
||||
|
||||
D3\Linkmobility4OXID\Application\Model\OrderRecipients:
|
||||
class: D3\Linkmobility4OXID\Application\Model\OrderRecipients
|
||||
factory: 'oxNew'
|
||||
shared: false
|
||||
arguments:
|
||||
- D3\Linkmobility4OXID\Application\Model\OrderRecipients
|
||||
- '@D3\Linkmobility4OXID\Application\Model\OrderRecipients.args.order'
|
||||
D3\Linkmobility4OXID\Application\Model\OrderRecipients.args.order:
|
||||
synthetic: true
|
||||
shared: false
|
||||
|
||||
D3\Linkmobility4OXID\Application\Model\UserRecipients:
|
||||
class: D3\Linkmobility4OXID\Application\Model\UserRecipients
|
||||
factory: 'oxNew'
|
||||
shared: false
|
||||
arguments:
|
||||
- D3\Linkmobility4OXID\Application\Model\UserRecipients
|
||||
- '@D3\Linkmobility4OXID\Application\Model\UserRecipients.args.user'
|
||||
D3\Linkmobility4OXID\Application\Model\UserRecipients.args.user:
|
||||
synthetic: true
|
||||
shared: false
|
||||
|
||||
D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms:
|
||||
class: D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms
|
||||
factory: 'oxNew'
|
||||
shared: false
|
||||
arguments:
|
||||
- D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms
|
||||
- '%D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms.args.message%'
|
||||
|
||||
D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException:
|
||||
class: D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException
|
||||
factory: 'oxNew'
|
||||
shared: false
|
||||
arguments:
|
||||
- D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException
|
||||
- '%D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException.args.smscount%'
|
51
src/Config/oxid.yaml
Fichier normal
51
src/Config/oxid.yaml
Fichier normal
@ -0,0 +1,51 @@
|
||||
# This Software is the property of Data Development and is protected
|
||||
# by copyright law - it is NOT Freeware.
|
||||
#
|
||||
# Any unauthorized use of this software without a valid license
|
||||
# is a violation of the license agreement and will be prosecuted by
|
||||
# civil and criminal law.
|
||||
#
|
||||
# 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
|
||||
|
||||
services:
|
||||
_defaults:
|
||||
autowire: false
|
||||
public: true
|
||||
|
||||
# lang
|
||||
d3ox.linkmobility.OxidEsales\Eshop\Core\Language:
|
||||
class: 'OxidEsales\Eshop\Core\Session'
|
||||
factory:
|
||||
- 'OxidEsales\Eshop\Core\Registry'
|
||||
- 'getLang'
|
||||
shared: true
|
||||
|
||||
# UtilsView
|
||||
d3ox.linkmobility.OxidEsales\Eshop\Core\UtilsView:
|
||||
class: 'OxidEsales\Eshop\Core\UtilsView'
|
||||
factory:
|
||||
- 'OxidEsales\Eshop\Core\Registry'
|
||||
- 'get'
|
||||
arguments:
|
||||
- 'OxidEsales\Eshop\Core\UtilsView'
|
||||
shared: true
|
||||
|
||||
# Order
|
||||
d3ox.linkmobility.OxidEsales\Eshop\Application\Model\Order:
|
||||
class: 'OxidEsales\Eshop\Application\Model\Order'
|
||||
factory: 'oxNew'
|
||||
arguments:
|
||||
- 'OxidEsales\Eshop\Application\Model\Order'
|
||||
shared: false
|
||||
|
||||
# User
|
||||
d3ox.linkmobility.OxidEsales\Eshop\Application\Model\User:
|
||||
class: 'OxidEsales\Eshop\Application\Model\User'
|
||||
factory: 'oxNew'
|
||||
arguments:
|
||||
- 'OxidEsales\Eshop\Application\Model\User'
|
||||
shared: false
|
29
src/Config/php.yaml
Fichier normal
29
src/Config/php.yaml
Fichier normal
@ -0,0 +1,29 @@
|
||||
# This Software is the property of Data Development and is protected
|
||||
# by copyright law - it is NOT Freeware.
|
||||
#
|
||||
# Any unauthorized use of this software without a valid license
|
||||
# is a violation of the license agreement and will be prosecuted by
|
||||
# civil and criminal law.
|
||||
#
|
||||
# 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
|
||||
|
||||
parameters:
|
||||
d3ox.linkmobility.InvalidArgumentException.args.message:
|
||||
|
||||
services:
|
||||
_defaults:
|
||||
autowire: false
|
||||
public: true
|
||||
|
||||
# InvalidArgumentException
|
||||
d3ox.linkmobility.InvalidArgumentException:
|
||||
class: InvalidArgumentException
|
||||
factory: 'oxNew'
|
||||
arguments:
|
||||
- InvalidArgumentException
|
||||
- '%d3ox.linkmobility.InvalidArgumentException.args.message%'
|
||||
shared: false
|
16
src/Config/services.yaml
Fichier normal
16
src/Config/services.yaml
Fichier normal
@ -0,0 +1,16 @@
|
||||
# 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
|
||||
|
||||
imports:
|
||||
- { resource: php.yaml }
|
||||
- { resource: oxid.yaml }
|
||||
- { resource: linkmobility4oxid.yaml }
|
||||
|
||||
|
||||
|
@ -13,6 +13,13 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Linkmobility4OXID\Modules {
|
||||
|
||||
use D3\DIContainerHandler\definitionFileContainer;
|
||||
|
||||
class LinkmobilityServices_parent extends definitionFileContainer {}
|
||||
}
|
||||
|
||||
namespace D3\Linkmobility4OXID\Modules\Application\Model {
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
|
25
src/Modules/LinkmobilityServices.php
Fichier normal
25
src/Modules/LinkmobilityServices.php
Fichier normal
@ -0,0 +1,25 @@
|
||||
<?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);
|
||||
|
||||
namespace D3\Linkmobility4OXID\Modules;
|
||||
|
||||
class LinkmobilityServices extends LinkmobilityServices_parent
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->addYamlDefinitions('d3/linkmobility/Config/services.yaml');
|
||||
}
|
||||
}
|
@ -13,10 +13,12 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use D3\DIContainerHandler\definitionFileContainer;
|
||||
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
|
||||
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
|
||||
use D3\Linkmobility4OXID\Modules\Application\Model\OrderModel;
|
||||
use D3\Linkmobility4OXID\Modules\Core\EmailCore;
|
||||
use D3\Linkmobility4OXID\Modules\LinkmobilityServices;
|
||||
use D3\Linkmobility4OXID\Setup\Events;
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
use OxidEsales\Eshop\Core\Email;
|
||||
@ -41,8 +43,9 @@ $aModule = [
|
||||
'email' => 'support@shopmodule.com',
|
||||
'url' => 'https://www.oxidmodule.com/',
|
||||
'extend' => [
|
||||
Email::class => EmailCore::class,
|
||||
Order::class => OrderModel::class
|
||||
Email::class => EmailCore::class,
|
||||
Order::class => OrderModel::class,
|
||||
definitionFileContainer::class => LinkmobilityServices::class
|
||||
],
|
||||
'controllers' => [
|
||||
'd3linkmobility_user' => AdminUser::class,
|
||||
|
@ -15,11 +15,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin;
|
||||
|
||||
use D3\DIContainerHandler\d3DicHandler;
|
||||
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
|
||||
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
||||
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
@ -33,6 +33,33 @@ class AdminOrderTest extends AdminSend
|
||||
protected $itemClass = Order::class;
|
||||
protected $itemRecipientClass = OrderRecipients::class;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder::__construct
|
||||
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminSendController::__construct
|
||||
*/
|
||||
public function canConstruct()
|
||||
{
|
||||
/** @var Order|MockObject $itemMock */
|
||||
$itemMock = $this->getMockBuilder($this->itemClass)
|
||||
->onlyMethods(['load'])
|
||||
->getMock();
|
||||
$itemMock->method('load')->willReturn(true);
|
||||
d3DicHandler::getInstance()->set('d3ox.linkmobility.'.Order::class, $itemMock);
|
||||
|
||||
$sut = parent::canConstruct();
|
||||
|
||||
$this->assertSame(
|
||||
$itemMock,
|
||||
$this->getValue(
|
||||
$sut,
|
||||
'item'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $canSendItemMessage
|
||||
@ -49,23 +76,13 @@ class AdminOrderTest extends AdminSend
|
||||
->onlyMethods(['sendOrderMessage'])
|
||||
->getMock();
|
||||
$smsMock->expects($this->once())->method('sendOrderMessage')->willReturn($canSendItemMessage);
|
||||
d3DicHandler::getInstance()->set(Sms::class, $smsMock);
|
||||
|
||||
/** @var AdminOrder|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(AdminOrder::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['d3GetMockableOxNewObject', 'getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage'])
|
||||
->onlyMethods(['getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage'])
|
||||
->getMock();
|
||||
$sut->method('d3GetMockableOxNewObject')->willReturnCallback(
|
||||
function () use ($smsMock) {
|
||||
$args = func_get_args();
|
||||
switch ($args[0]) {
|
||||
case Sms::class:
|
||||
return $smsMock;
|
||||
default:
|
||||
return call_user_func_array("oxNew", $args);
|
||||
}
|
||||
}
|
||||
);
|
||||
$sut->method('getMessageBody')->willReturn('messageBodyFixture');
|
||||
$sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage')
|
||||
->willReturn(oxNew(successfullySentException::class, 'expectedReturn'));
|
||||
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin;
|
||||
|
||||
use D3\DIContainerHandler\d3DicHandler;
|
||||
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
|
||||
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
||||
@ -22,20 +23,18 @@ use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
|
||||
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
||||
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
|
||||
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
|
||||
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
|
||||
use D3\LinkmobilityClient\SMS\Response;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use InvalidArgumentException;
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Request;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use OxidEsales\TestingLibrary\UnitTestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class AdminSend extends UnitTestCase
|
||||
class AdminSend extends LMUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
@ -44,20 +43,11 @@ class AdminSend extends UnitTestCase
|
||||
protected $itemRecipientClass;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @return AdminOrder|MockObject
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder::__construct
|
||||
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser::__construct
|
||||
*/
|
||||
public function canConstruct()
|
||||
{
|
||||
/** @var Order|MockObject $itemMock */
|
||||
$itemMock = $this->getMockBuilder($this->itemClass)
|
||||
->onlyMethods(['load'])
|
||||
->getMock();
|
||||
$itemMock->method('load')->willReturn(true);
|
||||
|
||||
/** @var Recipient|MockObject $recipientMock */
|
||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||
->disableOriginalConstructor()
|
||||
@ -66,19 +56,8 @@ class AdminSend extends UnitTestCase
|
||||
/** @var AdminOrder|MockObject $sut */
|
||||
$sut = $this->getMockBuilder($this->subjectUnderTestClass)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['d3GetMockableOxNewObject', 'getEditObjectId', 'getRecipientFromCurrentItem'])
|
||||
->onlyMethods(['getEditObjectId', 'getRecipientFromCurrentItem'])
|
||||
->getMock();
|
||||
$sut->method('d3GetMockableOxNewObject')->willReturnCallback(
|
||||
function () use ($itemMock) {
|
||||
$args = func_get_args();
|
||||
switch ($args[0]) {
|
||||
case Order::class:
|
||||
return $itemMock;
|
||||
default:
|
||||
return call_user_func_array("oxNew", $args);
|
||||
}
|
||||
}
|
||||
);
|
||||
$sut->method('getEditObjectId')->willReturn('editObjId');
|
||||
$sut->method('getRecipientFromCurrentItem')->willReturn($recipientMock);
|
||||
|
||||
@ -87,14 +66,6 @@ class AdminSend extends UnitTestCase
|
||||
'__construct'
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
$itemMock,
|
||||
$this->getValue(
|
||||
$sut,
|
||||
'item'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
$this->itemRecipientClass,
|
||||
$this->getValue(
|
||||
@ -111,6 +82,8 @@ class AdminSend extends UnitTestCase
|
||||
['recipient']
|
||||
)
|
||||
);
|
||||
|
||||
return $sut;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,6 +148,8 @@ class AdminSend extends UnitTestCase
|
||||
->onlyMethods(['addErrorToDisplay'])
|
||||
->getMock();
|
||||
$utilsViewMock->expects($this->once())->method('addErrorToDisplay');
|
||||
d3DicHandler::getInstance()->set('d3ox.linkmobility.'.UtilsView::class, $utilsViewMock);
|
||||
|
||||
/** @var OrderRecipients|MockObject $itemRecipientsMock */
|
||||
$itemRecipientsMock = $this->getMockBuilder($this->itemRecipientClass)
|
||||
->disableOriginalConstructor()
|
||||
@ -183,35 +158,14 @@ class AdminSend extends UnitTestCase
|
||||
$itemRecipientsMock->method('getSmsRecipient')->willThrowException(
|
||||
oxNew(noRecipientFoundException::class)
|
||||
);
|
||||
d3DicHandler::getInstance()->set(OrderRecipients::class, $itemRecipientsMock);
|
||||
d3DicHandler::getInstance()->set(UserRecipients::class, $itemRecipientsMock);
|
||||
|
||||
/** @var AdminOrder|AdminUser|MockObject $sut */
|
||||
$sut = $this->getMockBuilder($this->subjectUnderTestClass)
|
||||
->onlyMethods(['d3GetMockableOxNewObject', 'd3GetMockableRegistryObject'])
|
||||
->onlyMethods(['__construct'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$sut->method('d3GetMockableOxNewObject')->willReturnCallback(
|
||||
function () use ($itemRecipientsMock) {
|
||||
$args = func_get_args();
|
||||
switch ($args[0]) {
|
||||
case OrderRecipients::class:
|
||||
case UserRecipients::class:
|
||||
return $itemRecipientsMock;
|
||||
default:
|
||||
return call_user_func_array("oxNew", $args);
|
||||
}
|
||||
}
|
||||
);
|
||||
$sut->method('d3GetMockableRegistryObject')->willReturnCallback(
|
||||
function () use ($utilsViewMock) {
|
||||
$args = func_get_args();
|
||||
switch ($args[0]) {
|
||||
case UtilsView::class:
|
||||
return $utilsViewMock;
|
||||
default:
|
||||
return Registry::get($args[0]);
|
||||
}
|
||||
}
|
||||
);
|
||||
$this->setValue(
|
||||
$sut,
|
||||
'item',
|
||||
@ -247,23 +201,13 @@ class AdminSend extends UnitTestCase
|
||||
->onlyMethods(['addErrorToDisplay'])
|
||||
->getMock();
|
||||
$utilsViewMock->expects($this->once())->method('addErrorToDisplay');
|
||||
d3DicHandler::getInstance()->set('d3ox.linkmobility.'.UtilsView::class, $utilsViewMock);
|
||||
|
||||
/** @var AdminOrder|AdminUser|MockObject $sut */
|
||||
$sut = $this->getMockBuilder($this->subjectUnderTestClass)
|
||||
->onlyMethods(['d3GetMockableRegistryObject', 'sendMessage'])
|
||||
->onlyMethods(['sendMessage'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$sut->method('d3GetMockableRegistryObject')->willReturnCallback(
|
||||
function () use ($utilsViewMock) {
|
||||
$args = func_get_args();
|
||||
switch ($args[0]) {
|
||||
case UtilsView::class:
|
||||
return $utilsViewMock;
|
||||
default:
|
||||
return Registry::get($args[0]);
|
||||
}
|
||||
}
|
||||
);
|
||||
$sut->method('sendMessage')->will(
|
||||
$throwsException ?
|
||||
$this->throwException(oxNew(noRecipientFoundException::class)) :
|
||||
@ -305,23 +249,13 @@ class AdminSend extends UnitTestCase
|
||||
->onlyMethods(['getRequestEscapedParameter'])
|
||||
->getMock();
|
||||
$requestMock->method('getRequestEscapedParameter')->willReturn($message);
|
||||
d3DicHandler::getInstance()->set('d3ox.linkmobility.'.Request::class, $requestMock);
|
||||
|
||||
/** @var AdminOrder|AdminUser|MockObject $sut */
|
||||
$sut = $this->getMockBuilder($this->subjectUnderTestClass)
|
||||
->onlyMethods(['d3GetMockableRegistryObject'])
|
||||
->onlyMethods(['__construct'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$sut->method('d3GetMockableRegistryObject')->willReturnCallback(
|
||||
function () use ($requestMock) {
|
||||
$args = func_get_args();
|
||||
switch ($args[0]) {
|
||||
case Request::class:
|
||||
return $requestMock;
|
||||
default:
|
||||
return Registry::get($args[0]);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if ($expectException) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
@ -375,6 +309,7 @@ class AdminSend extends UnitTestCase
|
||||
$successfullySendExceptionMock = $this->getMockBuilder(successfullySentException::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
d3DicHandler::getInstance()->set(successfullySentException::class, $successfullySendExceptionMock);
|
||||
|
||||
/** @var Response|MockObject $resonseMock */
|
||||
$resonseMock = $this->getMockBuilder(Response::class)
|
||||
@ -394,19 +329,8 @@ class AdminSend extends UnitTestCase
|
||||
/** @var AdminOrder|AdminUser|MockObject $sut */
|
||||
$sut = $this->getMockBuilder($this->subjectUnderTestClass)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['d3GetMockableOxNewObject'])
|
||||
->onlyMethods(['__construct'])
|
||||
->getMock();
|
||||
$sut->method('d3GetMockableOxNewObject')->willReturnCallback(
|
||||
function () use ($successfullySendExceptionMock) {
|
||||
$args = func_get_args();
|
||||
switch ($args[0]) {
|
||||
case successfullySentException::class:
|
||||
return $successfullySendExceptionMock;
|
||||
default:
|
||||
return call_user_func_array("oxNew", $args);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
$successfullySendExceptionMock,
|
||||
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin;
|
||||
|
||||
use D3\DIContainerHandler\d3DicHandler;
|
||||
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
|
||||
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
|
||||
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
||||
@ -32,12 +33,38 @@ class AdminUserTest extends AdminSend
|
||||
protected $itemClass = User::class;
|
||||
protected $itemRecipientClass = UserRecipients::class;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser::__construct
|
||||
*/
|
||||
public function canConstruct()
|
||||
{
|
||||
/** @var User|MockObject $itemMock */
|
||||
$itemMock = $this->getMockBuilder($this->itemClass)
|
||||
->onlyMethods(['load'])
|
||||
->getMock();
|
||||
$itemMock->method('load')->willReturn(true);
|
||||
d3DicHandler::getInstance()->set('d3ox.linkmobility.'.User::class, $itemMock);
|
||||
|
||||
$sut = parent::canConstruct();
|
||||
|
||||
$this->assertSame(
|
||||
$itemMock,
|
||||
$this->getValue(
|
||||
$sut,
|
||||
'item'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $canSendItemMessage
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder::sendMessage
|
||||
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser::sendMessage
|
||||
* @dataProvider canSendMessageDataProvider
|
||||
*/
|
||||
public function canSendMessage($canSendItemMessage)
|
||||
@ -48,23 +75,13 @@ class AdminUserTest extends AdminSend
|
||||
->onlyMethods(['sendUserAccountMessage'])
|
||||
->getMock();
|
||||
$smsMock->expects($this->once())->method('sendUserAccountMessage')->willReturn($canSendItemMessage);
|
||||
d3DicHandler::getInstance()->set(Sms::class, $smsMock);
|
||||
|
||||
/** @var AdminUser|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(AdminUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['d3GetMockableOxNewObject', 'getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage'])
|
||||
->onlyMethods(['getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage'])
|
||||
->getMock();
|
||||
$sut->method('d3GetMockableOxNewObject')->willReturnCallback(
|
||||
function () use ($smsMock) {
|
||||
$args = func_get_args();
|
||||
switch ($args[0]) {
|
||||
case Sms::class:
|
||||
return $smsMock;
|
||||
default:
|
||||
return call_user_func_array("oxNew", $args);
|
||||
}
|
||||
}
|
||||
);
|
||||
$sut->method('getMessageBody')->willReturn('messageBodyFixture');
|
||||
$sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage')
|
||||
->willReturn(oxNew(successfullySentException::class, 'expectedReturn'));
|
||||
|
60
src/tests/unit/LMUnitTestCase.php
Fichier normal
60
src/tests/unit/LMUnitTestCase.php
Fichier normal
@ -0,0 +1,60 @@
|
||||
<?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);
|
||||
|
||||
namespace D3\Linkmobility4OXID\tests\unit;
|
||||
|
||||
use D3\DIContainerHandler\d3DicHandler;
|
||||
use OxidEsales\TestingLibrary\UnitTestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class LMUnitTestCase extends UnitTestCase
|
||||
{
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
d3DicHandler::getUncompiledInstance();
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
d3DicHandler::removeInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $serviceName
|
||||
* @param $serviceMock
|
||||
*
|
||||
* @return MockObject
|
||||
*/
|
||||
protected function getContainerMock($serviceName, $serviceMock)
|
||||
{
|
||||
$container = $this->getMockBuilder(ContainerInterface::class)
|
||||
->onlyMethods(['get', 'has'])
|
||||
->getMock();
|
||||
$container->expects($this->any())
|
||||
->method('get')
|
||||
->with($this->equalTo($serviceName))
|
||||
->will($this->returnValue($serviceMock));
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
50
src/tests/unit/Modules/LinkMobilityServicesTest.php
Fichier normal
50
src/tests/unit/Modules/LinkMobilityServicesTest.php
Fichier normal
@ -0,0 +1,50 @@
|
||||
<?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);
|
||||
|
||||
namespace D3\Linkmobility4OXID\tests\unit\Modules;
|
||||
|
||||
use D3\Linkmobility4OXID\Modules\LinkmobilityServices;
|
||||
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class LinkMobilityServicesTest extends LMUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Modules\LinkmobilityServices::__construct
|
||||
*/
|
||||
public function canConstruct()
|
||||
{
|
||||
/** @var LinkmobilityServices|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(LinkmobilityServices::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['addYamlDefinitions'])
|
||||
->getMock();
|
||||
$sut->expects($this->atLeastOnce())->method('addYamlDefinitions')->with(
|
||||
$this->identicalTo('d3/linkmobility/Config/services.yaml')
|
||||
);
|
||||
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'__construct'
|
||||
);
|
||||
}
|
||||
}
|
Chargement…
Référencer dans un nouveau ticket
Block a user