Skip to content

Commit

Permalink
EA-6300: initialize $__lastErrorMessage with null to avoid type error
Browse files Browse the repository at this point in the history
  • Loading branch information
sleipi committed Feb 28, 2024
1 parent bbe4aa2 commit 5006e03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Message/AbstractAmqpTransportableMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class AbstractAmqpTransportableMessage implements AmqpTransportableMess

private int $__receiveCount = 0;

private ?string $__lastErrorMessage;
private ?string $__lastErrorMessage = null;

private readonly string $__messageId;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
/**
* This File is part of JTL-Software
*
Expand All @@ -8,7 +10,6 @@

namespace JTL\Nachricht\Message;

use JTL\Nachricht\Message\Cache\TestMessage;
use PHPUnit\Framework\TestCase;

class TestAmqpMessage extends AbstractAmqpTransportableMessage
Expand All @@ -24,46 +25,54 @@ class TestAmqpMessage extends AbstractAmqpTransportableMessage
*/
class AbstractAmqpTransportableMessageTest extends TestCase
{
public function testCanCreateWithMessageId()
public function testCanCreateWithMessageId(): void
{
$messageId = uniqid();
$message = new TestAmqpMessage($messageId);
$this->assertEquals($messageId, $message->getMessageId());
}

public function testCanCreateWithoutMessageId()
public function testCanCreateWithoutMessageId(): void
{
$message = new TestAmqpMessage();
$this->assertIsString($message->getMessageId());
$this->assertTrue(strlen($message->getMessageId()) > 0);
}

public function testCanGetAndSetLastErrorMessage()
public function testCanGetAndSetLastErrorMessage(): void
{
$errorMessage = uniqid();
$message = new TestAmqpMessage();
self::assertNull($message->getLastErrorMessage());
$message->setLastError($errorMessage);

$this->assertSame($errorMessage, $message->getLastErrorMessage());
}

public function testCanCheckIfMessageIsDeadLetterTrue()
public function testDefaultErrorMessageIsNull(): void
{
$message = new TestAmqpMessage();
self::assertNull($message->getLastErrorMessage());
}


public function testCanCheckIfMessageIsDeadLetterTrue(): void
{
$message = new class extends AbstractAmqpTransportableMessage {
const DEFAULT_RETRY_COUNT = 0;
};
$this->assertTrue($message->isDeadLetter());
}

public function testCanCheckIfMessageIsDeadLetterFalse()
public function testCanCheckIfMessageIsDeadLetterFalse(): void
{
$message = new class extends AbstractAmqpTransportableMessage {
const DEFAULT_RETRY_COUNT = 1;
};
$this->assertFalse($message->isDeadLetter());
}

public function testCanIncreaseReceiveCountOnDeserialization()
public function testCanIncreaseReceiveCountOnDeserialization(): void
{
$message = new TestAmqpMessage();
$this->assertFalse($message->isDeadLetter());
Expand Down

0 comments on commit 5006e03

Please sign in to comment.