linkmobility4oxid/src/tests/unit/Application/Controller/Admin/AdminOrderTest.php

88 lines
3.1 KiB
PHP
Raw Normal View History

2022-12-26 00:20:16 +01:00
<?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\Controller\Admin;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\TestingTools\Development\CanAccessRestricted;
use OxidEsales\Eshop\Application\Model\Order;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
2022-12-28 00:09:24 +01:00
class AdminOrderTest extends AdminSend
2022-12-26 00:20:16 +01:00
{
use CanAccessRestricted;
2022-12-28 00:09:24 +01:00
protected $subjectUnderTestClass = AdminOrder::class;
protected $itemClass = Order::class;
protected $itemRecipientClass = OrderRecipients::class;
2022-12-26 00:20:16 +01:00
/**
* @test
2022-12-28 00:09:24 +01:00
* @param $canSendItemMessage
2022-12-26 00:20:16 +01:00
* @return void
* @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder::sendMessage
* @dataProvider canSendMessageDataProvider
*/
2022-12-28 00:09:24 +01:00
public function canSendMessage($canSendItemMessage)
2022-12-26 00:20:16 +01:00
{
/** @var Sms|MockObject $smsMock */
$smsMock = $this->getMockBuilder(Sms::class)
->disableOriginalConstructor()
->onlyMethods(['sendOrderMessage'])
->getMock();
2022-12-28 00:09:24 +01:00
$smsMock->expects($this->once())->method('sendOrderMessage')->willReturn($canSendItemMessage);
2022-12-26 00:20:16 +01:00
/** @var AdminOrder|MockObject $sut */
$sut = $this->getMockBuilder(AdminOrder::class)
->disableOriginalConstructor()
->onlyMethods(['d3GetMockableOxNewObject', 'getMessageBody', 'getSuccessSentMessage', 'getUnsuccessfullySentMessage'])
->getMock();
$sut->method('d3GetMockableOxNewObject')->willReturnCallback(
2022-12-28 00:09:24 +01:00
function () use ($smsMock) {
2022-12-26 00:20:16 +01:00
$args = func_get_args();
switch ($args[0]) {
case Sms::class:
return $smsMock;
default:
return call_user_func_array("oxNew", $args);
}
}
);
$sut->method('getMessageBody')->willReturn('messageBodyFixture');
2022-12-28 00:09:24 +01:00
$sut->expects($this->exactly((int) $canSendItemMessage))->method('getSuccessSentMessage')
2022-12-26 00:20:16 +01:00
->willReturn(oxNew(successfullySentException::class, 'expectedReturn'));
2022-12-28 00:09:24 +01:00
$sut->expects($this->exactly((int) !$canSendItemMessage))->method('getUnsuccessfullySentMessage')
2022-12-26 00:20:16 +01:00
->willReturn('expectedReturn');
2022-12-28 00:09:24 +01:00
$this->setValue(
$sut,
'item',
oxNew($this->itemClass)
2022-12-26 00:20:16 +01:00
);
$this->assertIsString(
$this->callMethod(
$sut,
2022-12-28 00:09:24 +01:00
'sendMessage'
2022-12-26 00:20:16 +01:00
)
);
}
}