/** @test */ public function ackShouldAcknowledge() { $client = $this->getMockBuilder('React\\Stomp\\Client')->disableOriginalConstructor()->getMock(); $capturedSubId = $capturedMsgId = $capturedHeaders = null; $client->expects($this->exactly(1))->method('ack')->will($this->returnCallback(function ($subId, $msgId, $headers) use(&$capturedSubId, &$capturedMsgId, &$capturedHeaders) { $capturedHeaders = $headers; $capturedMsgId = $msgId; $capturedSubId = $subId; })); $ackResolver = new AckResolver($client, 12345, 54321); $ackResolver->ack(array('foo' => 'bar')); $this->assertEquals(array('foo' => 'bar'), $capturedHeaders); $this->assertEquals(54321, $capturedMsgId); $this->assertEquals(12345, $capturedSubId); }
public function handleLog(PredisClient $redis, Logger $logger, Frame $frame, AckResolver $resolver) { $logger->addInfo(sprintf('Processing job %s', $frame->getHeader('delivery_tag'))); $error = false; try { $job = Factory::fromJson($frame->body); if (!$job instanceof JobInterface) { $error = true; } } catch (RuntimeException $e) { $error = true; } if (!$error) { $promise = $this->saveJob($redis, $job); } else { $promise = $this->saveGarbage($redis, $frame->body); } $promise->then(function () use($resolver) { $resolver->ack(); }); return $promise; }