From 32ea723301720e75744addbd437c70003ffc0882 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sat, 7 Jan 2023 21:13:32 +0100 Subject: [PATCH] add tests for exception classes --- .../Exceptions/successfullySentException.php | 3 +- .../noRecipientFoundExceptionTest.php | 48 ++++++++++++++++ .../successfullySentExceptionTest.php | 57 +++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/tests/unit/Application/Model/Exceptions/noRecipientFoundExceptionTest.php create mode 100644 src/tests/unit/Application/Model/Exceptions/successfullySentExceptionTest.php diff --git a/src/Application/Model/Exceptions/successfullySentException.php b/src/Application/Model/Exceptions/successfullySentException.php index 9a37909..3843cd5 100644 --- a/src/Application/Model/Exceptions/successfullySentException.php +++ b/src/Application/Model/Exceptions/successfullySentException.php @@ -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); diff --git a/src/tests/unit/Application/Model/Exceptions/noRecipientFoundExceptionTest.php b/src/tests/unit/Application/Model/Exceptions/noRecipientFoundExceptionTest.php new file mode 100644 index 0000000..a6c35d1 --- /dev/null +++ b/src/tests/unit/Application/Model/Exceptions/noRecipientFoundExceptionTest.php @@ -0,0 +1,48 @@ + + * @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' + ) + ); + } +} \ No newline at end of file diff --git a/src/tests/unit/Application/Model/Exceptions/successfullySentExceptionTest.php b/src/tests/unit/Application/Model/Exceptions/successfullySentExceptionTest.php new file mode 100644 index 0000000..63d4c4f --- /dev/null +++ b/src/tests/unit/Application/Model/Exceptions/successfullySentExceptionTest.php @@ -0,0 +1,57 @@ + + * @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' + ) + ); + } +} \ No newline at end of file