add tests for some classes
This commit is contained in:
164
Tests/ValueObject/RecipientTest.php
Normal file
164
Tests/ValueObject/RecipientTest.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class RecipientTest extends ApiTestCase
|
||||
{
|
||||
/** @var Recipient */
|
||||
public $recipient;
|
||||
|
||||
private $phoneNumberFixture = '01527565839';
|
||||
private $phoneCountryFixture = 'DE';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws NumberParseException
|
||||
*/
|
||||
public function setUp():void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->recipient = new Recipient($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->recipient);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws NumberParseException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||
->onlyMethods(['parse', 'format'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
|
||||
$phoneNumberUtilMock->method('format')->willReturn('+491527565839');
|
||||
|
||||
/** @var Recipient|MockObject $recipientMock */
|
||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||
->onlyMethods(['getPhoneNumberUtil'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$recipientMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
||||
$recipientMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||
|
||||
$this->assertSame(
|
||||
'491527565839',
|
||||
$this->callMethod(
|
||||
$recipientMock,
|
||||
'get'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
$this->phoneCountryFixture,
|
||||
$this->callMethod(
|
||||
$recipientMock,
|
||||
'getCountryCode'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @param $number
|
||||
* @param $country
|
||||
* @param $validNumber
|
||||
* @param $expectedException
|
||||
*
|
||||
* @return void
|
||||
* @throws NumberParseException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
*/
|
||||
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
||||
{
|
||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||
->onlyMethods(['parse', 'format', 'isValidNumber'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
if ($number === 'abc') {
|
||||
$phoneNumberUtilMock->method( 'parse' )->willThrowException(new NumberParseException(0, 'message'));
|
||||
} else {
|
||||
$phoneNumberUtilMock->method( 'parse' )->willReturn( new PhoneNumber() );
|
||||
}
|
||||
$phoneNumberUtilMock->method('format')->willReturn($number);
|
||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn($validNumber);
|
||||
|
||||
/** @var Recipient|MockObject $recipientMock */
|
||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||
->onlyMethods(['getPhoneNumberUtil'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$recipientMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
||||
|
||||
$this->expectException($expectedException);
|
||||
$recipientMock->__construct($number, $country);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
|
||||
'invalid country code' => [$this->phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
||||
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
||||
'invalid number' => ['abc', 'DE', false, NumberParseException::class]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetPhoneNumberUtil()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
PhoneNumberUtil::class,
|
||||
$this->callMethod(
|
||||
$this->recipient,
|
||||
'getPhoneNumberUtil'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
159
Tests/ValueObject/SenderTest.php
Normal file
159
Tests/ValueObject/SenderTest.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class SenderTest extends ApiTestCase
|
||||
{
|
||||
/** @var Sender */
|
||||
public $sender;
|
||||
|
||||
private $phoneNumberFixture = '015792300219';
|
||||
private $phoneCountryFixture = 'DE';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
*/
|
||||
public function setUp():void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->sender = new Sender( $this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||
->onlyMethods(['parse', 'format', 'isValidNumber'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
|
||||
$phoneNumberUtilMock->method('format')->willReturn('4915792300219');
|
||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn(true);
|
||||
|
||||
/** @var Sender|MockObject $senderMock */
|
||||
$senderMock = $this->getMockBuilder(Sender::class)
|
||||
->onlyMethods(['getPhoneNumberUtil'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
||||
$senderMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||
|
||||
$this->assertSame(
|
||||
'4915792300219',
|
||||
$this->callMethod(
|
||||
$senderMock,
|
||||
'get'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $number
|
||||
* @param $country
|
||||
* @param $validNumber
|
||||
* @param $expectedException
|
||||
*
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
*/
|
||||
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
||||
{
|
||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||
->onlyMethods(['parse', 'format', 'isValidNumber'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
if ($number === 'abc') {
|
||||
$phoneNumberUtilMock->method( 'parse' )->willThrowException(new NumberParseException(0, 'message'));
|
||||
} else {
|
||||
$phoneNumberUtilMock->method( 'parse' )->willReturn( new PhoneNumber() );
|
||||
}
|
||||
$phoneNumberUtilMock->method('format')->willReturn($number);
|
||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn($validNumber);
|
||||
|
||||
/** @var Sender|MockObject $senderMock */
|
||||
$senderMock = $this->getMockBuilder(Sender::class)
|
||||
->onlyMethods(['getPhoneNumberUtil'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
||||
|
||||
$this->expectException($expectedException);
|
||||
$senderMock->__construct($number, $country);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
|
||||
'invalid country code' => [$this->phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
||||
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
||||
'invalid number' => ['abc', 'DE', false, NumberParseException::class]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetPhoneNumberUtil()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
PhoneNumberUtil::class,
|
||||
$this->callMethod(
|
||||
$this->sender,
|
||||
'getPhoneNumberUtil'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
243
Tests/ValueObject/SmsBinaryMessageTest.php
Normal file
243
Tests/ValueObject/SmsBinaryMessageTest.php
Normal file
@ -0,0 +1,243 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
||||
use Phlib\SmsLength\SmsLength;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class SmsBinaryMessageTest extends ApiTestCase
|
||||
{
|
||||
/** @var SmsBinaryMessage */
|
||||
public $message;
|
||||
|
||||
private $messageFixture = "testMessage";
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp():void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->message = new SmsBinaryMessage( $this->messageFixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
/** @var SmsLength|MockObject $smsLengthMock */
|
||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['validate'])
|
||||
->getMock();
|
||||
$smsLengthMock->expects($this->atLeastOnce())->method('validate')->willReturn(true);
|
||||
|
||||
/** @var SmsBinaryMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsBinaryMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
$message->__construct($this->messageFixture);
|
||||
|
||||
$this->assertSame(
|
||||
$this->messageFixture,
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'get'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @param $binaryMessage
|
||||
* @param $valid
|
||||
* @param $expectedException
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
*/
|
||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||
{
|
||||
/** @var SmsLength|MockObject $smsLengthMock */
|
||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['validate'])
|
||||
->getMock();
|
||||
if ($valid) {
|
||||
$smsLengthMock->expects( $this->never() )->method( 'validate' )->willReturn( true );
|
||||
} else {
|
||||
$smsLengthMock->expects( $this->atLeastOnce() )->method( 'validate' )->willThrowException(new \Phlib\SmsLength\Exception\InvalidArgumentException());
|
||||
}
|
||||
|
||||
/** @var SmsBinaryMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsBinaryMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
|
||||
$this->expectException($expectedException);
|
||||
$message->__construct($binaryMessage);
|
||||
|
||||
$this->assertSame(
|
||||
$message,
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'get'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty message' => ['', true, InvalidArgumentException::class],
|
||||
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetSmsLengthInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
SmsLength::class,
|
||||
$this->callMethod(
|
||||
$this->message,
|
||||
'getSmsLength'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetChunkCount()
|
||||
{
|
||||
$expected = 2;
|
||||
|
||||
/** @var SmsLength|MockObject $smsLengthMock */
|
||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||
->onlyMethods(['getMessageCount', 'validate'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$smsLengthMock->expects($this->once())->method('getMessageCount')->willReturn($expected);
|
||||
$smsLengthMock->method('validate')->willReturn(true);
|
||||
|
||||
/** @var SmsBinaryMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsBinaryMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'chunkCount'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetSize()
|
||||
{
|
||||
$expected = 55;
|
||||
|
||||
/** @var SmsLength|MockObject $smsLengthMock */
|
||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||
->onlyMethods(['getSize', 'validate'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$smsLengthMock->expects($this->once())->method('getSize')->willReturn($expected);
|
||||
$smsLengthMock->method('validate')->willReturn(true);
|
||||
|
||||
/** @var SmsBinaryMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsBinaryMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'length'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetMessageContent()
|
||||
{
|
||||
/** @var SmsLength|MockObject $smsLengthMock */
|
||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||
->onlyMethods(['validate'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$smsLengthMock->method('validate')->willReturn(true);
|
||||
|
||||
/** @var SmsBinaryMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsBinaryMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
$message->__construct($this->messageFixture);
|
||||
|
||||
$this->assertSame(
|
||||
['dGVzdE1lc3NhZ2U='], // binary content
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'getMessageContent'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
115
Tests/ValueObject/SmsTextMessageTest.php
Normal file
115
Tests/ValueObject/SmsTextMessageTest.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||
|
||||
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
||||
use Phlib\SmsLength\Exception\InvalidArgumentException;
|
||||
use Phlib\SmsLength\SmsLength;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
{
|
||||
/** @var SmsTextMessage */
|
||||
public $message;
|
||||
|
||||
private $messageFixture = "testMessage";
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp():void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->message = new SmsTextMessage( $this->messageFixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
/** @var SmsLength|MockObject $smsLengthMock */
|
||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['validate'])
|
||||
->getMock();
|
||||
$smsLengthMock->expects($this->atLeastOnce())->method('validate')->willReturn(true);
|
||||
|
||||
/** @var SmsTextMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsTextMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
$message->__construct($this->messageFixture);
|
||||
|
||||
$this->assertSame(
|
||||
$this->messageFixture,
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'get'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @param $binaryMessage
|
||||
* @param $valid
|
||||
* @param $expectedException
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
*/
|
||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||
{
|
||||
/** @var SmsLength|MockObject $smsLengthMock */
|
||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['validate'])
|
||||
->getMock();
|
||||
if ($valid) {
|
||||
$smsLengthMock->expects( $this->never() )->method( 'validate' )->willReturn( true );
|
||||
} else {
|
||||
$smsLengthMock->expects( $this->atLeastOnce() )->method( 'validate' )->willThrowException(new InvalidArgumentException());
|
||||
}
|
||||
|
||||
/** @var SmsTextMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsTextMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
|
||||
$this->expectException($expectedException);
|
||||
$message->__construct($binaryMessage);
|
||||
|
||||
$this->assertSame(
|
||||
$message,
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'get'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user