get sender address type only if sender is set
This commit is contained in:
parent
bd9c3e6c03
commit
f1eae3bd87
@ -465,10 +465,55 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @dataProvider setGetSenderAddressTypeDataProvider
|
||||||
*/
|
*/
|
||||||
public function setGetSenderAddressTypeTest()
|
public function testSetGetSenderAddressType($hasSender, $addressType, $expected)
|
||||||
{
|
{
|
||||||
$this->checkGetterSetter('fixture', 'setSenderAddressType', 'getSenderAddressType');
|
/** @var Request|MockObject $request */
|
||||||
|
$request = $this->getMockBuilder($this->testClassName)
|
||||||
|
->setConstructorArgs([$this->request->getMessage(), $this->request->getClient()])
|
||||||
|
->onlyMethods(['getSenderAddress'])
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
if ($hasSender) {
|
||||||
|
/** @var Sender|MockObject $senderMock */
|
||||||
|
$senderMock = $this->getMockBuilder( Sender::class )
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->onlyMethods(['get'])
|
||||||
|
->getMock();
|
||||||
|
$senderMock->method('get')->willReturn('fixture');
|
||||||
|
$request->method('getSenderAddress')->willReturn($senderMock);
|
||||||
|
} else {
|
||||||
|
$request->method('getSenderAddress')->willReturn(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
Request::class,
|
||||||
|
$this->callMethod(
|
||||||
|
$request,
|
||||||
|
'setSenderAddressType',
|
||||||
|
[$addressType]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$expected,
|
||||||
|
$this->callMethod(
|
||||||
|
$request,
|
||||||
|
'getSenderAddressType'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function setGetSenderAddressTypeDataProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'has no sender' => [false, 'fixture', null],
|
||||||
|
'has sender and address type' => [true, 'fixture', 'fixture'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,4 +24,6 @@ class ExceptionMessages
|
|||||||
public const INVALID_RECIPIENT_PHONE = 'invalid recipient phone number';
|
public const INVALID_RECIPIENT_PHONE = 'invalid recipient phone number';
|
||||||
|
|
||||||
public const NOT_A_MOBILE_NUMBER = 'not a mobile number';
|
public const NOT_A_MOBILE_NUMBER = 'not a mobile number';
|
||||||
|
|
||||||
|
public const DEBUG_NOSENDERORCOUNTRYCODE= 'no sender number or sender country code defined, use fallback to account default';
|
||||||
}
|
}
|
||||||
|
21
src/Exceptions/NoSenderDefinedException.php
Normal file
21
src/Exceptions/NoSenderDefinedException.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?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\LinkmobilityClient\Exceptions;
|
||||||
|
|
||||||
|
class NoSenderDefinedException extends LinkmobilityException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -465,7 +465,7 @@ abstract class Request implements RequestInterface
|
|||||||
*/
|
*/
|
||||||
public function getSenderAddressType()
|
public function getSenderAddressType()
|
||||||
{
|
{
|
||||||
return $this->senderAddressType;
|
return $this->getSenderAddress() && $this->getSenderAddress()->get() ? $this->senderAddressType : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +17,9 @@ namespace D3\LinkmobilityClient\ValueObject;
|
|||||||
|
|
||||||
use Assert\Assert;
|
use Assert\Assert;
|
||||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||||
|
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
|
||||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||||
|
use D3\LinkmobilityClient\LoggerHandler;
|
||||||
use libphonenumber\NumberParseException;
|
use libphonenumber\NumberParseException;
|
||||||
use libphonenumber\PhoneNumberFormat;
|
use libphonenumber\PhoneNumberFormat;
|
||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
@ -31,8 +33,13 @@ class Sender extends StringValueObject
|
|||||||
* @throws RecipientException
|
* @throws RecipientException
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
*/
|
*/
|
||||||
public function __construct(string $number, string $iso2CountryCode)
|
public function __construct(string $number = null, string $iso2CountryCode = null)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
if ( is_null( $number ) || is_null( $iso2CountryCode ) ) {
|
||||||
|
throw new NoSenderDefinedException();
|
||||||
|
}
|
||||||
|
|
||||||
Assert::that( $iso2CountryCode )->string()->length( 2 );
|
Assert::that( $iso2CountryCode )->string()->length( 2 );
|
||||||
|
|
||||||
$phoneUtil = $this->getPhoneNumberUtil();
|
$phoneUtil = $this->getPhoneNumberUtil();
|
||||||
@ -45,6 +52,11 @@ class Sender extends StringValueObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct( $number );
|
parent::__construct( $number );
|
||||||
|
} catch (NoSenderDefinedException $e) {
|
||||||
|
LoggerHandler::getInstance()->getLogger()->debug(
|
||||||
|
ExceptionMessages::DEBUG_NOSENDERORCOUNTRYCODE
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,12 +66,4 @@ class Sender extends StringValueObject
|
|||||||
{
|
{
|
||||||
return PhoneNumberUtil::getInstance();
|
return PhoneNumberUtil::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getFormatted()
|
|
||||||
{
|
|
||||||
return parent::getFormatted();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user