use PHPUnit 13 on PHP 8.4+

This commit is contained in:
Christian Flothmann
2026-02-06 08:55:12 +01:00
parent 02ec025730
commit affa113ae0
6 changed files with 46 additions and 42 deletions

View File

@@ -348,10 +348,10 @@ class FailedMessagesRemoveCommandTest extends TestCase
public function testSuccessMessageGoesToStdout()
{
$globalFailureReceiverName = 'failure_receiver';
$receiver = $this->createStub(ListableReceiverInterface::class);
$receiver = $this->createMock(ListableReceiverInterface::class);
$envelope = new Envelope(new \stdClass(), [new TransportMessageIdStamp('some_id')]);
$receiver->method('find')->with('some_id')->willReturn($envelope);
$receiver->expects($this->once())->method('find')->with('some_id')->willReturn($envelope);
$command = new FailedMessagesRemoveCommand($globalFailureReceiverName, new ServiceLocator([$globalFailureReceiverName => fn () => $receiver]));
$tester = new CommandTester($command);
@@ -367,9 +367,9 @@ class FailedMessagesRemoveCommandTest extends TestCase
public function testErrorMessageGoesToStderr()
{
$globalFailureReceiverName = 'failure_receiver';
$receiver = $this->createStub(ListableReceiverInterface::class);
$receiver = $this->createMock(ListableReceiverInterface::class);
$receiver->method('find')->with('not_found')->willReturn(null);
$receiver->expects($this->once())->method('find')->with('not_found')->willReturn(null);
$command = new FailedMessagesRemoveCommand($globalFailureReceiverName, new ServiceLocator([$globalFailureReceiverName => fn () => $receiver]));
$tester = new CommandTester($command);
@@ -385,10 +385,10 @@ class FailedMessagesRemoveCommandTest extends TestCase
public function testNoteMessageGoesToStderr()
{
$globalFailureReceiverName = 'failure_receiver';
$receiver = $this->createStub(ListableReceiverInterface::class);
$receiver = $this->createMock(ListableReceiverInterface::class);
$envelope = new Envelope(new \stdClass(), [new TransportMessageIdStamp('some_id')]);
$receiver->method('find')->with('some_id')->willReturn($envelope);
$receiver->expects($this->once())->method('find')->with('some_id')->willReturn($envelope);
$command = new FailedMessagesRemoveCommand($globalFailureReceiverName, new ServiceLocator([$globalFailureReceiverName => fn () => $receiver]));
$tester = new CommandTester($command);

View File

@@ -208,8 +208,8 @@ class FailedMessagesRetryCommandTest extends TestCase
public function testSuccessMessageGoesToStdout()
{
$envelope = new Envelope(new \stdClass(), [new TransportMessageIdStamp('some_id')]);
$receiver = $this->createStub(ListableReceiverInterface::class);
$receiver->method('find')->with('some_id')->willReturn($envelope);
$receiver = $this->createMock(ListableReceiverInterface::class);
$receiver->expects($this->once())->method('find')->with('some_id')->willReturn($envelope);
$command = new FailedMessagesRetryCommand(
'failure_receiver',
@@ -232,8 +232,8 @@ class FailedMessagesRetryCommandTest extends TestCase
public function testCommentsGoToStderr()
{
$envelope = new Envelope(new \stdClass(), [new TransportMessageIdStamp('some_id')]);
$receiver = $this->createStub(ListableReceiverInterface::class);
$receiver->method('find')->with('some_id')->willReturn($envelope);
$receiver = $this->createMock(ListableReceiverInterface::class);
$receiver->expects($this->once())->method('find')->with('some_id')->willReturn($envelope);
$command = new FailedMessagesRetryCommand(
'failure_receiver',

View File

@@ -225,8 +225,8 @@ class FailedMessagesShowCommandTest extends TestCase
new RedeliveryStamp(0),
ErrorDetailsStamp::create(new \RuntimeException('Things are bad!')),
]);
$receiver = $this->createStub(ListableReceiverInterface::class);
$receiver->method('all')->with()->willReturn([$envelope]);
$receiver = $this->createMock(ListableReceiverInterface::class);
$receiver->expects($this->exactly(3))->method('all')->with()->willReturn([$envelope]);
$failureTransportName = 'failure_receiver';
@@ -254,8 +254,8 @@ class FailedMessagesShowCommandTest extends TestCase
new RedeliveryStamp(0),
ErrorDetailsStamp::create(new \RuntimeException('Things are bad!')),
]);
$receiver = $this->createStub(ListableReceiverInterface::class);
$receiver->method('all')->with()->willReturn([$envelope, $envelope]);
$receiver = $this->createMock(ListableReceiverInterface::class);
$receiver->expects($this->once())->method('all')->with()->willReturn([$envelope, $envelope]);
$failureTransportName = 'failure_receiver';

View File

@@ -38,8 +38,8 @@ class MessengerDataCollectorTest extends TestCase
$message = new DummyMessage('dummy message');
$envelope = new Envelope($message);
$bus = $this->createStub(MessageBusInterface::class);
$bus->method('dispatch')->with($message)->willReturn($envelope);
$bus = $this->createMock(MessageBusInterface::class);
$bus->expects($this->once())->method('dispatch')->with($message)->willReturn($envelope);
$bus = new TraceableMessageBus($bus);
$collector = new MessengerDataCollector();
@@ -79,8 +79,8 @@ class MessengerDataCollectorTest extends TestCase
{
$message = new DummyMessage('dummy message');
$bus = $this->createStub(MessageBusInterface::class);
$bus->method('dispatch')->with($message)->willThrowException(new \RuntimeException('foo'));
$bus = $this->createMock(MessageBusInterface::class);
$bus->expects($this->once())->method('dispatch')->with($message)->willThrowException(new \RuntimeException('foo'));
$bus = new TraceableMessageBus($bus);
$collector = new MessengerDataCollector();

View File

@@ -232,8 +232,9 @@ class DispatchAfterCurrentBusMiddlewareTest extends TestCase
$eventHandlingMiddleware,
]);
$fakePutMessageOnQueue = $this->createStub(MiddlewareInterface::class);
$fakePutMessageOnQueue = $this->createMock(MiddlewareInterface::class);
$fakePutMessageOnQueue
->expects($this->once())
->method('handle')
->with($this->callback(function ($envelope) use ($messageBusAfterQueue) {
// Fake putting the message on the queue
@@ -274,9 +275,10 @@ class DispatchAfterCurrentBusMiddlewareTest extends TestCase
$event = new DummyEvent('First event');
$middleware = new DispatchAfterCurrentBusMiddleware();
$handlingMiddleware = $this->createStub(MiddlewareInterface::class);
$handlingMiddleware = $this->createMock(MiddlewareInterface::class);
$handlingMiddleware
->expects($this->once())
->method('handle')
->with($this->expectHandledMessage($event))
->willReturnCallback($this->handleMessageCallback());

View File

@@ -27,15 +27,9 @@ class InMemoryTransportTest extends TestCase
{
private InMemoryTransport $transport;
private InMemoryTransport $serializeTransport;
private SerializerInterface $serializer;
protected function setUp(): void
{
$this->serializer = $this->createStub(SerializerInterface::class);
$this->transport = new InMemoryTransport();
$this->serializeTransport = new InMemoryTransport($this->serializer);
}
public function testSend()
@@ -49,18 +43,20 @@ class InMemoryTransportTest extends TestCase
{
$envelope = new Envelope(new \stdClass());
$envelopeDecoded = Envelope::wrap(new DummyMessage('Hello.'));
$this->serializer
$serializer = $this->createMock(SerializerInterface::class);
$serializer
->method('encode')
->with($this->equalTo($envelope->with(new TransportMessageIdStamp(1))))
->willReturn(['foo' => 'ba'])
;
$this->serializer
$serializer
->method('decode')
->with(['foo' => 'ba'])
->willReturn($envelopeDecoded)
;
$this->serializeTransport->send($envelope);
$this->assertSame([$envelopeDecoded], $this->serializeTransport->getSent());
$serializeTransport = new InMemoryTransport($serializer);
$serializeTransport->send($envelope);
$this->assertSame([$envelopeDecoded], $serializeTransport->getSent());
}
public function testQueue()
@@ -89,18 +85,20 @@ class InMemoryTransportTest extends TestCase
{
$envelope = new Envelope(new \stdClass());
$envelopeDecoded = Envelope::wrap(new DummyMessage('Hello.'));
$this->serializer
$serializer = $this->createMock(SerializerInterface::class);
$serializer
->method('encode')
->with($this->equalTo($envelope->with(new TransportMessageIdStamp(1))))
->willReturn(['foo' => 'ba'])
;
$this->serializer
$serializer
->method('decode')
->with(['foo' => 'ba'])
->willReturn($envelopeDecoded)
;
$this->serializeTransport->send($envelope);
$this->assertSame([$envelopeDecoded], $this->serializeTransport->get());
$serializeTransport = new InMemoryTransport($serializer);
$serializeTransport->send($envelope);
$this->assertSame([$envelopeDecoded], $serializeTransport->get());
}
public function testAcknowledgeSameMessageWithDifferentStamps()
@@ -128,18 +126,20 @@ class InMemoryTransportTest extends TestCase
{
$envelope = new Envelope(new \stdClass());
$envelopeDecoded = Envelope::wrap(new DummyMessage('Hello.'));
$this->serializer
$serializer = $this->createMock(SerializerInterface::class);
$serializer
->method('encode')
->with($this->equalTo($envelope->with(new TransportMessageIdStamp(1))))
->willReturn(['foo' => 'ba'])
;
$this->serializer
$serializer
->method('decode')
->with(['foo' => 'ba'])
->willReturn($envelopeDecoded)
;
$this->serializeTransport->ack($envelope->with(new TransportMessageIdStamp(1)));
$this->assertSame([$envelopeDecoded], $this->serializeTransport->getAcknowledged());
$serializeTransport = new InMemoryTransport($serializer);
$serializeTransport->ack($envelope->with(new TransportMessageIdStamp(1)));
$this->assertSame([$envelopeDecoded], $serializeTransport->getAcknowledged());
}
public function testReject()
@@ -154,18 +154,20 @@ class InMemoryTransportTest extends TestCase
{
$envelope = new Envelope(new \stdClass());
$envelopeDecoded = Envelope::wrap(new DummyMessage('Hello.'));
$this->serializer
$serializer = $this->createMock(SerializerInterface::class);
$serializer
->method('encode')
->with($this->equalTo($envelope->with(new TransportMessageIdStamp(1))))
->willReturn(['foo' => 'ba'])
;
$this->serializer
$serializer
->method('decode')
->with(['foo' => 'ba'])
->willReturn($envelopeDecoded)
;
$this->serializeTransport->reject($envelope->with(new TransportMessageIdStamp(1)));
$this->assertSame([$envelopeDecoded], $this->serializeTransport->getRejected());
$serializeTransport = new InMemoryTransport($serializer);
$serializeTransport->reject($envelope->with(new TransportMessageIdStamp(1)));
$this->assertSame([$envelopeDecoded], $serializeTransport->getRejected());
}
public function testReset()