add tests for exception classes

This commit is contained in:
Daniel Seifert 2023-01-07 21:13:32 +01:00
parent 26a6223442
commit 32ea723301
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
3 changed files with 107 additions and 1 deletions

View File

@ -17,6 +17,7 @@ namespace D3\Linkmobility4OXID\Application\Model\Exceptions;
use Exception;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Language;
use OxidEsales\Eshop\Core\Registry;
class successfullySentException extends StandardException
@ -29,7 +30,7 @@ class successfullySentException extends StandardException
public function __construct($messageCount = 1, $code = 0, Exception $previous = null)
{
/** @var string $format */
$format = Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT');
$format = d3GetOxidDIC()->get('d3ox.linkmobility.'.Language::class)->translateString('D3LM_EXC_SMS_SUCC_SENT');
$message = sprintf($format, $messageCount);
parent::__construct($message, $code, $previous);

View File

@ -0,0 +1,48 @@
<?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\Application\Model\Exceptions;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
use D3\TestingTools\Development\CanAccessRestricted;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class noRecipientFoundExceptionTest extends LMUnitTestCase
{
use CanAccessRestricted;
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException::__construct
*/
public function canConstruct()
{
/** @var noRecipientFoundException|MockObject $sut */
$sut = $this->getMockBuilder(noRecipientFoundException::class)
->getMock();
$this->assertRegExp(
'@.*NO.*RECIPIENT.*SET.*@',
$this->callMethod(
$sut,
'getMessage'
)
);
}
}

View File

@ -0,0 +1,57 @@
<?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\Application\Model\Exceptions;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
use D3\TestingTools\Development\CanAccessRestricted;
use OxidEsales\Eshop\Core\Language;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class successfullySentExceptionTest extends LMUnitTestCase
{
use CanAccessRestricted;
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException::__construct
*/
public function canConstruct()
{
/** @var Language|MockObject $languageMock */
$languageMock = $this->getMockBuilder(Language::class)
->onlyMethods(['translateString'])
->getMock();
$languageMock->method('translateString')->willReturn('%1$s messages');
d3GetOxidDIC()->set('d3ox.linkmobility.'.Language::class, $languageMock);
/** @var successfullySentException|MockObject $sut */
$sut = $this->getMockBuilder(successfullySentException::class)
->setConstructorArgs([25, 10])
->getMock();
$this->assertSame(
'25 messages',
$this->callMethod(
$sut,
'getMessage'
)
);
}
}