payment = new class { public string $method = 'paypal_smart_button'; public array $additional = ['cart_id' => 5, 'express' => true]; }; } public function fresh(): static { return $this; } }; $orderRepository = Mockery::mock(OrderRepository::class); $orderRepository->shouldReceive('find')->once()->with(42)->andReturn($order); $service = Mockery::mock(PaymentService::class, [ $orderRepository, Mockery::mock(CartRepository::class), Mockery::mock(CartTokenService::class), Mockery::mock(InvoiceRepository::class), Mockery::mock(OrderTransactionRepository::class), Mockery::mock(PaymentAttemptRepository::class), ])->makePartial()->shouldAllowMockingProtectedMethods(); $service->shouldReceive('createGatewayOrderForOrder')->once()->with($order)->andReturn('GW-NEW-1'); $service->shouldReceive('writeGatewayOrderId')->once()->with($order, 'GW-NEW-1'); $service->shouldReceive('recordAttempt')->once(); $service->shouldReceive('scheduleReconciliation')->once()->with($order); $input = new PaymentReplayInput; $input->orderId = 42; /** @var PaymentService $service */ $result = $service->replay($input, null); $this->assertSame('GW-NEW-1', $result['gatewayOrderId']); $this->assertSame($order, $result['order']); } }