move recipient number check from list to itself

This commit is contained in:
2022-07-18 13:54:56 +02:00
parent 05ff18d537
commit dc0b680776
4 changed files with 18 additions and 151 deletions

View File

@ -16,18 +16,13 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\Tests\RecipientsList;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\LoggerHandler;
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
use D3\LinkmobilityClient\Tests\ApiTestCase;
use D3\LinkmobilityClient\ValueObject\Recipient;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumber;
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberType;
use libphonenumber\PhoneNumberUtil;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;
use ReflectionException;
use stdClass;
@ -88,22 +83,6 @@ class RecipientsListTest extends ApiTestCase
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getPhoneNumberUtil
*/
public function testGetPhoneNumberUtil()
{
$this->assertInstanceOf(
PhoneNumberUtil::class,
$this->callMethod(
$this->recipientsList,
'getPhoneNumberUtil'
)
);
}
/**
* @test
* @throws ReflectionException
@ -111,15 +90,6 @@ class RecipientsListTest extends ApiTestCase
*/
public function testAddValidNumber()
{
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
->onlyMethods(['parse', 'isValidNumber', 'getNumberType'])
->disableOriginalConstructor()
->getMock();
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
$phoneNumberUtilMock->method('isValidNumber')->willReturn(true);
$phoneNumberUtilMock->method('getNumberType')->willReturn(PhoneNumberType::MOBILE);
/** @var Recipient|MockObject $recipientMock */
$recipientMock = $this->getMockBuilder(Recipient::class)
->onlyMethods(['get', 'getCountryCode'])
@ -128,15 +98,6 @@ class RecipientsListTest extends ApiTestCase
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
$recipientMock->method('getCountryCode')->willReturn($this->phoneCountryFixture);
/** @var RecipientsList|MockObject $recListMock */
$recListMock = $this->getMockBuilder(RecipientsList::class)
->onlyMethods(['getPhoneNumberUtil'])
->setConstructorArgs([$this->recipientsList->getClient()])
->getMock();
$recListMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
$this->recipientsList = $recListMock;
$this->assertCount(
0,
$this->callMethod($this->recipientsList, 'getRecipientsList')
@ -157,96 +118,6 @@ class RecipientsListTest extends ApiTestCase
);
}
/**
* @test
* @throws ReflectionException
* @dataProvider addInvalidNumberDataProvider
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::add
*/
public function testAddInvalidNumber($unparsable, $invalidNumber, $invalidNumberType)
{
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
->onlyMethods(['parse', 'isValidNumber', 'getNumberType'])
->disableOriginalConstructor()
->getMock();
if ($unparsable) {
$phoneNumberUtilMock->method('parse')->willThrowException(new NumberParseException(0, 'message'));
} else {
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
}
$phoneNumberUtilMock->method('isValidNumber')->willReturn(!$invalidNumber);
$phoneNumberUtilMock->method('getNumberType')->willReturn($invalidNumberType ? PhoneNumberType::FIXED_LINE : PhoneNumberType::MOBILE);
/** @var Recipient|MockObject $recipientMock */
$recipientMock = $this->getMockBuilder(Recipient::class)
->onlyMethods(['get', 'getCountryCode'])
->setConstructorArgs([$this->phoneNumberFixture, $this->phoneCountryFixture])
->getMock();
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
$recipientMock->method('getCountryCode')->willReturn($this->phoneCountryFixture);
/** @var LoggerInterface|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(AbstractLogger::class)
->onlyMethods(['info', 'log'])
->getMock();
$loggerMock->expects($this->atLeastOnce())->method('info')->willReturn(true);
/** @var LoggerHandler|MockObject $loggerHandlerMock */
$loggerHandlerMock = $this->getMockBuilder(LoggerHandler::class)
->onlyMethods(['getLogger'])
->getMock();
$loggerHandlerMock->method('getLogger')->willReturn($loggerMock);
/** @var Client|MockObject $clientMock */
$clientMock = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->onlyMethods(['getLoggerHandler'])
->getMock();
$clientMock->method('getLoggerHandler')->willReturn($loggerHandlerMock);
/** @var RecipientsList|MockObject $recListMock */
$recListMock = $this->getMockBuilder(RecipientsList::class)
->onlyMethods(['getPhoneNumberUtil'])
->setConstructorArgs([$clientMock])
->getMock();
$recListMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
$this->recipientsList = $recListMock;
$this->assertCount(
0,
$this->callMethod($this->recipientsList, 'getRecipientsList')
);
$this->assertSame(
$this->recipientsList,
$this->callMethod(
$this->recipientsList,
'add',
[$recipientMock]
)
);
$this->assertCount(
0,
$this->callMethod($this->recipientsList, 'getRecipientsList')
);
}
/**
* @return array[]
*/
public function addInvalidNumberDataProvider(): array
{
return [
'unparsable' => [true, false, false],
'invalid number' => [false, true, false],
'invalid number type' => [false, false, true],
];
}
/**
* @test
* @throws ReflectionException