remove setParameter in DIC because of frozen parameter bag
This commit is contained in:
parent
6651d892dd
commit
88571ad8ed
@ -64,14 +64,21 @@ class AdminOrder extends AdminController
|
||||
*/
|
||||
protected function sendMessage(): string
|
||||
{
|
||||
d3GetOxidDIC()->setParameter(Sms::class.'.args.message', $this->getMessageBody());
|
||||
/** @var Sms $sms */
|
||||
$sms = d3GetOxidDIC()->get(Sms::class);
|
||||
$sms = $this->getSms($this->getMessageBody());
|
||||
return $sms->sendOrderMessage($this->item) ?
|
||||
(string) $this->getSuccessSentMessage($sms) :
|
||||
$this->getUnsuccessfullySentMessage($sms);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return Sms
|
||||
*/
|
||||
protected function getSms(string $message): Sms
|
||||
{
|
||||
return oxNew(Sms::class, $message);
|
||||
}
|
||||
|
||||
/*** duplicated code but errors while phpunit coverage run if code is in shared abstract class or trait ***/
|
||||
|
||||
/**
|
||||
@ -120,12 +127,11 @@ class AdminOrder extends AdminController
|
||||
$messageBody = $request->getRequestEscapedParameter('messagebody');
|
||||
|
||||
if (false === is_string($messageBody) || strlen(trim($messageBody)) <= 1) {
|
||||
d3GetOxidDIC()->setParameter(
|
||||
'd3ox.linkmobility.'.InvalidArgumentException::class.'.args.message',
|
||||
/** @var InvalidArgumentException $exc */
|
||||
$exc = oxNew(
|
||||
InvalidArgumentException::class,
|
||||
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
|
||||
);
|
||||
/** @var InvalidArgumentException $exc */
|
||||
$exc = d3GetOxidDIC()->get('d3ox.linkmobility.'.InvalidArgumentException::class);
|
||||
throw $exc;
|
||||
}
|
||||
|
||||
@ -139,9 +145,8 @@ class AdminOrder extends AdminController
|
||||
protected function getSuccessSentMessage(Sms $sms): successfullySentException
|
||||
{
|
||||
$smsCount = $sms->getResponse() ? $sms->getResponse()->getSmsCount() : 0;
|
||||
d3GetOxidDIC()->setParameter(successfullySentException::class.'.args.smscount', $smsCount);
|
||||
/** @var successfullySentException $exc */
|
||||
$exc = d3GetOxidDIC()->get(successfullySentException::class);
|
||||
$exc = oxNew(successfullySentException::class, $smsCount);
|
||||
return $exc;
|
||||
}
|
||||
|
||||
|
@ -66,14 +66,21 @@ class AdminUser extends AdminController
|
||||
*/
|
||||
protected function sendMessage(): string
|
||||
{
|
||||
d3GetOxidDIC()->setParameter(Sms::class.'.args.message', $this->getMessageBody());
|
||||
/** @var Sms $sms */
|
||||
$sms = d3GetOxidDIC()->get(Sms::class);
|
||||
$sms = $this->getSms($this->getMessageBody());
|
||||
return $sms->sendUserAccountMessage($this->item) ?
|
||||
(string) $this->getSuccessSentMessage($sms) :
|
||||
$this->getUnsuccessfullySentMessage($sms);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return Sms
|
||||
*/
|
||||
protected function getSms(string $message): Sms
|
||||
{
|
||||
return oxNew(Sms::class, $message);
|
||||
}
|
||||
|
||||
/*** duplicated code but errors while phpunit coverage run if code is in shared abstract class or trait ***/
|
||||
|
||||
/**
|
||||
@ -122,12 +129,11 @@ class AdminUser extends AdminController
|
||||
$messageBody = $request->getRequestEscapedParameter('messagebody');
|
||||
|
||||
if (false === is_string($messageBody) || strlen(trim($messageBody)) <= 1) {
|
||||
d3GetOxidDIC()->setParameter(
|
||||
'd3ox.linkmobility.'.InvalidArgumentException::class.'.args.message',
|
||||
/** @var InvalidArgumentException $exc */
|
||||
$exc = oxNew(
|
||||
InvalidArgumentException::class,
|
||||
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
|
||||
);
|
||||
/** @var InvalidArgumentException $exc */
|
||||
$exc = d3GetOxidDIC()->get('d3ox.linkmobility.'.InvalidArgumentException::class);
|
||||
throw $exc;
|
||||
}
|
||||
|
||||
@ -141,9 +147,8 @@ class AdminUser extends AdminController
|
||||
protected function getSuccessSentMessage(Sms $sms): successfullySentException
|
||||
{
|
||||
$smsCount = $sms->getResponse() ? $sms->getResponse()->getSmsCount() : 0;
|
||||
d3GetOxidDIC()->setParameter(successfullySentException::class.'.args.smscount', $smsCount);
|
||||
/** @var successfullySentException $exc */
|
||||
$exc = d3GetOxidDIC()->get(successfullySentException::class);
|
||||
$exc = oxNew(successfullySentException::class, $smsCount);
|
||||
return $exc;
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,8 @@ class MessageClient
|
||||
/** @var Configuration $configuration */
|
||||
$configuration = d3GetOxidDIC()->get(Configuration::class);
|
||||
|
||||
d3GetOxidDIC()->setParameter(Client::class.'.args.accesstoken', $configuration->getApiToken());
|
||||
/** @var Client $client */
|
||||
$client = d3GetOxidDIC()->get(Client::class);
|
||||
$client = oxNew(Client::class, $configuration->getApiToken());
|
||||
|
||||
/** @var LoggerHandler $loggerHandler */
|
||||
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
|
||||
|
@ -74,14 +74,21 @@ class MessageSender
|
||||
}
|
||||
|
||||
try {
|
||||
d3GetOxidDIC()->setParameter(Sms::class.'.args.message', $messageBody);
|
||||
/** @var Sms $sms */
|
||||
$sms = d3GetOxidDIC()->get(Sms::class);
|
||||
$sms = $this->getSms($messageBody);
|
||||
$sms->sendOrderMessage($order);
|
||||
} catch (noRecipientFoundException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return Sms
|
||||
*/
|
||||
protected function getSms(string $message): Sms
|
||||
{
|
||||
return oxNew(Sms::class, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Configuration
|
||||
*/
|
||||
|
@ -24,6 +24,7 @@ use D3\Linkmobility4OXID\Application\Model\RequestFactory;
|
||||
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
@ -34,6 +35,7 @@ use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
use libphonenumber\NumberParseException;
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
@ -175,18 +177,13 @@ class Sms extends AbstractMessage
|
||||
* @param Configuration $configuration
|
||||
* @param Client $client
|
||||
* @return SmsRequestInterface
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
*/
|
||||
protected function getRequest(Configuration $configuration, Client $client): SmsRequestInterface
|
||||
{
|
||||
d3GetOxidDIC()->setParameter(RequestFactory::class.'.args.message', $this->getMessage());
|
||||
d3GetOxidDIC()->set(RequestFactory::class.'.args.client', $client);
|
||||
/** @var RequestFactory $requestFactory */
|
||||
$requestFactory = d3GetOxidDIC()->get(RequestFactory::class);
|
||||
|
||||
d3GetOxidDIC()->setParameter(Sender::class.'.args.number', $configuration->getSmsSenderNumber());
|
||||
d3GetOxidDIC()->setParameter(Sender::class.'.args.iso2countrycode', $configuration->getSmsSenderCountry());
|
||||
/** @var Sender $sender */
|
||||
$sender = d3GetOxidDIC()->get(Sender::class);
|
||||
$requestFactory = $this->getRequestFactory($this->getMessage(), $client);
|
||||
$sender = $this->getSender($configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry());
|
||||
|
||||
/** @var SmsRequestInterface $request */
|
||||
$request = $requestFactory->getSmsRequest();
|
||||
@ -197,6 +194,28 @@ class Sms extends AbstractMessage
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param Client $client
|
||||
* @return RequestFactory
|
||||
*/
|
||||
protected function getRequestFactory(string $message, Client $client): RequestFactory
|
||||
{
|
||||
return oxNew(RequestFactory::class, $message, $client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $number
|
||||
* @param string $countryCode
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @return Sender
|
||||
*/
|
||||
protected function getSender(string $number, string $countryCode): Sender
|
||||
{
|
||||
return oxNew(Sender::class, $number, $countryCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecipientsListInterface $recipientsList
|
||||
* @return ResponseInterface
|
||||
|
@ -70,12 +70,7 @@ class OrderRecipients
|
||||
/** @var string $countryId */
|
||||
$countryId = $this->order->getFieldData(trim($countryIdFieldName));
|
||||
$country->load($countryId);
|
||||
|
||||
d3GetOxidDIC()->setParameter(Recipient::class.'.args.number', $content);
|
||||
d3GetOxidDIC()->setParameter(Recipient::class.'.args.iso2countrycode', $country->getFieldData('oxisoalpha2'));
|
||||
/** @var Recipient $recipient */
|
||||
$recipient = d3GetOxidDIC()->get(Recipient::class);
|
||||
return $recipient;
|
||||
return $this->getRecipient($content, $country->getFieldData('oxisoalpha2'));
|
||||
}
|
||||
} catch (NumberParseException|RecipientException $e) {
|
||||
/** @var LoggerHandler $loggerHandler */
|
||||
@ -89,6 +84,18 @@ class OrderRecipients
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @param string $countryCode
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @return Recipient
|
||||
*/
|
||||
protected function getRecipient(string $content, string $countryCode): Recipient
|
||||
{
|
||||
return oxNew(Recipient::class, $content, $countryCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
|
@ -15,15 +15,22 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Model;
|
||||
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
use D3\LinkmobilityClient\SMS\SmsRequestInterface;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use D3\TestingTools\Production\IsMockable;
|
||||
use libphonenumber\NumberParseException;
|
||||
|
||||
class RequestFactory extends \D3\LinkmobilityClient\SMS\RequestFactory
|
||||
{
|
||||
use IsMockable;
|
||||
|
||||
/**
|
||||
* @return SmsRequestInterface
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
*/
|
||||
public function getSmsRequest(): SmsRequestInterface
|
||||
{
|
||||
/** @var Configuration $configuration */
|
||||
@ -33,14 +40,23 @@ class RequestFactory extends \D3\LinkmobilityClient\SMS\RequestFactory
|
||||
/** @var SmsRequestInterface $request */
|
||||
$request = $this->d3CallMockableFunction([\D3\LinkmobilityClient\SMS\RequestFactory::class, 'getSmsRequest']);
|
||||
|
||||
d3GetOxidDIC()->setParameter(Sender::class.'.args.number', $configuration->getSmsSenderNumber());
|
||||
d3GetOxidDIC()->setParameter(Sender::class.'.args.iso2countrycode', $configuration->getSmsSenderCountry());
|
||||
/** @var Sender $sender */
|
||||
$sender = d3GetOxidDIC()->get(Sender::class);
|
||||
$sender = $this->getSender($configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry());
|
||||
$request->setTestMode($configuration->getTestMode())
|
||||
->setSenderAddress($sender)
|
||||
->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL);
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $number
|
||||
* @param string $countryCode
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @return Sender
|
||||
*/
|
||||
protected function getSender(string $number, string $countryCode): Sender
|
||||
{
|
||||
return oxNew(Sender::class, $number, $countryCode);
|
||||
}
|
||||
}
|
||||
|
@ -70,11 +70,7 @@ class UserRecipients
|
||||
/** @var string $countryId */
|
||||
$countryId = $this->user->getFieldData('oxcountryid');
|
||||
$country->load($countryId);
|
||||
d3GetOxidDIC()->setParameter(Recipient::class.'.args.number', $content);
|
||||
d3GetOxidDIC()->setParameter(Recipient::class.'.args.iso2countrycode', $country->getFieldData('oxisoalpha2'));
|
||||
/** @var Recipient $recipient */
|
||||
$recipient = d3GetOxidDIC()->get(Recipient::class);
|
||||
return $recipient;
|
||||
return $this->getRecipient($content, $country->getFieldData('oxisoalpha2'));
|
||||
}
|
||||
} catch (NumberParseException|RecipientException $e) {
|
||||
/** @var LoggerHandler $loggerHandler */
|
||||
@ -88,6 +84,18 @@ class UserRecipients
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @param string $countryCode
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @return Recipient
|
||||
*/
|
||||
protected function getRecipient(string $content, string $countryCode): Recipient
|
||||
{
|
||||
return oxNew(Recipient::class, $content, $countryCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
|
@ -75,18 +75,18 @@ class AdminOrderTest extends AdminSend
|
||||
->onlyMethods(['sendOrderMessage'])
|
||||
->getMock();
|
||||
$smsMock->expects($this->once())->method('sendOrderMessage')->willReturn($canSendItemMessage);
|
||||
d3GetOxidDIC()->set(Sms::class, $smsMock);
|
||||
|
||||
/** @var AdminOrder|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(AdminOrder::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage'])
|
||||
->onlyMethods(['getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage', 'getSms'])
|
||||
->getMock();
|
||||
$sut->method('getMessageBody')->willReturn('messageBodyFixture');
|
||||
$sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage')
|
||||
->willReturn(oxNew(successfullySentException::class, 'expectedReturn'));
|
||||
$sut->expects($this->exactly((int) !$canSendItemMessage))->method('getUnsuccessfullySentMessage')
|
||||
->willReturn('expectedReturn');
|
||||
$sut->method('getSms')->willReturn($smsMock);
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
@ -101,4 +101,27 @@ class AdminOrderTest extends AdminSend
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder::getSms
|
||||
*/
|
||||
public function canGetSms()
|
||||
{
|
||||
/** @var AdminOrder|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(AdminOrder::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Sms::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getSms',
|
||||
['messageFixture']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -305,12 +305,6 @@ class AdminSend extends LMUnitTestCase
|
||||
*/
|
||||
public function canGetSuccessSentMessage($hasResponse)
|
||||
{
|
||||
/** @var successfullySentException|MockObject $successfullySendExceptionMock */
|
||||
$successfullySendExceptionMock = $this->getMockBuilder(successfullySentException::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
d3GetOxidDIC()->set(successfullySentException::class, $successfullySendExceptionMock);
|
||||
|
||||
/** @var Response|MockObject $resonseMock */
|
||||
$resonseMock = $this->getMockBuilder(Response::class)
|
||||
->onlyMethods(['getSmsCount'])
|
||||
@ -332,8 +326,8 @@ class AdminSend extends LMUnitTestCase
|
||||
->onlyMethods(['__construct'])
|
||||
->getMock();
|
||||
|
||||
$this->assertSame(
|
||||
$successfullySendExceptionMock,
|
||||
$this->assertInstanceOf(
|
||||
successfullySentException::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getSuccessSentMessage',
|
||||
|
@ -75,18 +75,18 @@ class AdminUserTest extends AdminSend
|
||||
->onlyMethods(['sendUserAccountMessage'])
|
||||
->getMock();
|
||||
$smsMock->expects($this->once())->method('sendUserAccountMessage')->willReturn($canSendItemMessage);
|
||||
d3GetOxidDIC()->set(Sms::class, $smsMock);
|
||||
|
||||
/** @var AdminUser|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(AdminUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage'])
|
||||
->onlyMethods(['getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage', 'getSms'])
|
||||
->getMock();
|
||||
$sut->method('getMessageBody')->willReturn('messageBodyFixture');
|
||||
$sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage')
|
||||
->willReturn(oxNew(successfullySentException::class, 'expectedReturn'));
|
||||
$sut->expects($this->exactly((int) !$canSendItemMessage))->method('getUnsuccessfullySentMessage')
|
||||
->willReturn('expectedReturn');
|
||||
$sut->method('getSms')->willReturn($smsMock);
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
@ -101,4 +101,27 @@ class AdminUserTest extends AdminSend
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser::getSms
|
||||
*/
|
||||
public function canGetSms()
|
||||
{
|
||||
/** @var AdminUser|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(AdminUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Sms::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getSms',
|
||||
['messageFixture']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ use D3\Linkmobility4OXID\Application\Model\MessageSender;
|
||||
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
||||
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use Hoa\Iterator\Mock;
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
@ -170,7 +171,6 @@ class MessageSenderTest extends LMUnitTestCase
|
||||
$this->throwException(d3GetOxidDIC()->get(noRecipientFoundException::class)) :
|
||||
$this->returnValue(true)
|
||||
);
|
||||
d3GetOxidDIC()->set(Sms::class, $smsMock);
|
||||
|
||||
/** @var Order|MockObject $orderMock */
|
||||
$orderMock = $this->getMockBuilder(Order::class)
|
||||
@ -179,8 +179,9 @@ class MessageSenderTest extends LMUnitTestCase
|
||||
|
||||
/** @var MessageSender|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(MessageSender::class)
|
||||
->onlyMethods(['getConfiguration'])
|
||||
->onlyMethods(['getSms', 'getConfiguration'])
|
||||
->getMock();
|
||||
$sut->method('getSms')->willReturn($smsMock);
|
||||
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
@ -202,6 +203,28 @@ class MessageSenderTest extends LMUnitTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Model\MessageSender::getSms
|
||||
*/
|
||||
public function canGetSms()
|
||||
{
|
||||
/** @var MessageSender|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(MessageSender::class)
|
||||
->getMock();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Sms::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getSms',
|
||||
['messageFixture']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
|
@ -29,6 +29,7 @@ use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||
use D3\LinkmobilityClient\SMS\BinaryRequest;
|
||||
use D3\LinkmobilityClient\SMS\Response;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use Monolog\Logger;
|
||||
use OxidEsales\Eshop\Application\Model\Order;
|
||||
@ -637,6 +638,10 @@ class SmsTest extends LMUnitTestCase
|
||||
*/
|
||||
public function canGetRequest()
|
||||
{
|
||||
/** @var Sender|MockObject $senderMock */
|
||||
$senderMock = $this->getMockBuilder(Sender::class)
|
||||
->getMock();
|
||||
|
||||
/** @var Client|MockObject $clientMock */
|
||||
$clientMock = $this->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()
|
||||
@ -644,7 +649,11 @@ class SmsTest extends LMUnitTestCase
|
||||
|
||||
/** @var Configuration|MockObject $configurationMock */
|
||||
$configurationMock = $this->getMockBuilder(Configuration::class)
|
||||
->onlyMethods(['getSmsSenderNumber', 'getSmsSenderCountry'])
|
||||
->getMock();
|
||||
$configurationMock->method('getSmsSenderNumber')->willReturn('01512 3456789');
|
||||
$configurationMock->method('getSmsSenderCountry')->willReturn('DE');
|
||||
|
||||
|
||||
/** @var BinaryRequest|MockObject $binaryRequestMock */
|
||||
$binaryRequestMock = $this->getMockBuilder(BinaryRequest::class)
|
||||
@ -657,12 +666,15 @@ class SmsTest extends LMUnitTestCase
|
||||
->onlyMethods(['getSmsRequest'])
|
||||
->getMock();
|
||||
$requestFactoryMock->method('getSmsRequest')->willReturn($binaryRequestMock);
|
||||
d3GetOxidDIC()->set(RequestFactory::class, $requestFactoryMock);
|
||||
|
||||
/** @var Sms|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(Sms::class)
|
||||
->onlyMethods(['getRequestFactory', 'getSender', 'getMessage'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$sut->method('getRequestFactory')->willReturn($requestFactoryMock);
|
||||
$sut->method('getSender')->willReturn($senderMock);
|
||||
$sut->method('getMessage')->willReturn('messageFixture');
|
||||
|
||||
$this->assertSame(
|
||||
$binaryRequestMock,
|
||||
@ -674,6 +686,57 @@ class SmsTest extends LMUnitTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms::getRequestFactory
|
||||
*/
|
||||
public function canGetRequestFactory()
|
||||
{
|
||||
/** @var Client|MockObject $clientMock */
|
||||
$clientMock = $this->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var Sms|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(Sms::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
RequestFactory::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getRequestFactory',
|
||||
['messageFixture', $clientMock]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms::getSender
|
||||
*/
|
||||
public function canGetSender()
|
||||
{
|
||||
/** @var Sms|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(Sms::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Sender::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getSender',
|
||||
['01512 3456789', 'DE']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $submitSuccessful
|
||||
|
@ -130,7 +130,6 @@ class OrderRecipientsTest extends LMUnitTestCase
|
||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
d3GetOxidDIC()->set(Recipient::class, $recipientMock);
|
||||
|
||||
/** @var Country|MockObject $countryMock */
|
||||
$countryMock = $this->getMockBuilder(Country::class)
|
||||
@ -158,8 +157,10 @@ class OrderRecipientsTest extends LMUnitTestCase
|
||||
|
||||
/** @var OrderRecipients|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(OrderRecipients::class)
|
||||
->onlyMethods(['getRecipient'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$sut->method('getRecipient')->willReturn($recipientMock);
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
@ -191,6 +192,29 @@ class OrderRecipientsTest extends LMUnitTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Model\OrderRecipients::getRecipient
|
||||
*/
|
||||
public function canGetRecipient()
|
||||
{
|
||||
/** @var OrderRecipients|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(OrderRecipients::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Recipient::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getRecipient',
|
||||
['01512 3456789', 'DE']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $configuredFields
|
||||
|
@ -50,7 +50,6 @@ class RequestFactoryTest extends LMUnitTestCase
|
||||
$senderMock = $this->getMockBuilder(Sender::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
d3GetOxidDIC()->set(Sender::class, $senderMock);
|
||||
|
||||
/** @var TextRequest|MockObject $textRequestMock */
|
||||
$textRequestMock = $this->getMockBuilder(TextRequest::class)
|
||||
@ -60,9 +59,10 @@ class RequestFactoryTest extends LMUnitTestCase
|
||||
/** @var RequestFactory|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(RequestFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['d3CallMockableFunction'])
|
||||
->onlyMethods(['d3CallMockableFunction', 'getSender'])
|
||||
->getMock();
|
||||
$sut->method('d3CallMockableFunction')->willReturn($textRequestMock);
|
||||
$sut->method('getSender')->willReturn($senderMock);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
SmsRequestInterface::class,
|
||||
@ -72,4 +72,27 @@ class RequestFactoryTest extends LMUnitTestCase
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Model\RequestFactory::getSender
|
||||
*/
|
||||
public function canGetSender()
|
||||
{
|
||||
/** @var RequestFactory|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(RequestFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Sender::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getSender',
|
||||
['01512 3456789', 'DE']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,6 @@ class UserRecipientsTest extends LMUnitTestCase
|
||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
d3GetOxidDIC()->set(Recipient::class, $recipientMock);
|
||||
|
||||
/** @var Country|MockObject $countryMock */
|
||||
$countryMock = $this->getMockBuilder(Country::class)
|
||||
@ -158,8 +157,10 @@ class UserRecipientsTest extends LMUnitTestCase
|
||||
|
||||
/** @var UserRecipients|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(UserRecipients::class)
|
||||
->onlyMethods(['getRecipient'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$sut->method('getRecipient')->willReturn($recipientMock);
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
@ -191,6 +192,29 @@ class UserRecipientsTest extends LMUnitTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Linkmobility4OXID\Application\Model\UserRecipients::getRecipient
|
||||
*/
|
||||
public function canGetRecipient()
|
||||
{
|
||||
/** @var UserRecipients|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(UserRecipients::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Recipient::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getRecipient',
|
||||
['01512 3456789', 'DE']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $configuredFields
|
||||
|
Loading…
Reference in New Issue
Block a user