| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types=1 ); |
| 4 |
|
| 5 |
namespace Tests\Module\Order; |
| 6 |
|
| 7 |
use Packetery\Core\Api\Soap\Client; |
| 8 |
use Packetery\Core\Api\Soap\Response\PacketSetStoredUntil as ResponsePacketSetStoredUntil; |
| 9 |
use Packetery\Core\CoreHelper; |
| 10 |
use Packetery\Core\Log\ILogger; |
| 11 |
use Packetery\Module\Order\PacketSetStoredUntil; |
| 12 |
use PHPUnit\Framework\MockObject\MockObject; |
| 13 |
use PHPUnit\Framework\TestCase; |
| 14 |
use Tests\Core\DummyFactory; |
| 15 |
|
| 16 |
class PacketSetStoredUntilTest extends TestCase { |
| 17 |
|
| 18 |
private Client|MockObject $client; |
| 19 |
private ILogger|MockObject $loggerMock; |
| 20 |
private ResponsePacketSetStoredUntil|MockObject $responsePacketSetStoredUntil; |
| 21 |
private PacketSetStoredUntil $packetSetStoredUntil; |
| 22 |
|
| 23 |
public function createPacketStoredUntil(): void { |
| 24 |
$this->client = $this->createMock( Client::class ); |
| 25 |
$this->loggerMock = $this->createMock( ILogger::class ); |
| 26 |
$this->responsePacketSetStoredUntil = $this->createMock( ResponsePacketSetStoredUntil::class ); |
| 27 |
|
| 28 |
$this->packetSetStoredUntil = new PacketSetStoredUntil( |
| 29 |
$this->client, |
| 30 |
$this->loggerMock, |
| 31 |
new CoreHelper( 'dummyUrl' ), |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
public function testSetStoredUntilWithoutFault(): void { |
| 36 |
$this->createPacketStoredUntil(); |
| 37 |
$this->responsePacketSetStoredUntil->method( 'hasFault' )->willReturn( false ); |
| 38 |
$this->loggerMock->expects( $this->once() )->method( 'add' ); |
| 39 |
|
| 40 |
$this->client->expects( $this->once() )->method( 'packetSetStoredUntil' )->willReturn( $this->responsePacketSetStoredUntil ); |
| 41 |
|
| 42 |
$result = $this->packetSetStoredUntil->setStoredUntil( DummyFactory::createOrderCzPp(), 'test', \DateTimeImmutable::createFromFormat( 'Y-m-d', '2024-12-24' ) ); |
| 43 |
|
| 44 |
$this->assertNull( $result ); |
| 45 |
} |
| 46 |
|
| 47 |
public function testSetStoredUntilWithFault(): void { |
| 48 |
$this->createPacketStoredUntil(); |
| 49 |
$errorMessage = 'some nasty fault'; |
| 50 |
|
| 51 |
$this->responsePacketSetStoredUntil->method( 'hasFault' )->willReturn( true ); |
| 52 |
$this->responsePacketSetStoredUntil->method( 'getFaultString' )->willReturn( $errorMessage ); |
| 53 |
$this->loggerMock->expects( $this->once() )->method( 'add' ); |
| 54 |
|
| 55 |
$this->client->expects( $this->once() )->method( 'packetSetStoredUntil' )->willReturn( $this->responsePacketSetStoredUntil ); |
| 56 |
|
| 57 |
$result = $this->packetSetStoredUntil->setStoredUntil( DummyFactory::createOrderCzPp(), 'test', \DateTimeImmutable::createFromFormat( 'Y-m-d', '2024-12-24' ) ); |
| 58 |
|
| 59 |
$this->assertSame( $errorMessage, $result ); |
| 60 |
} |
| 61 |
} |
| 62 |
|