public function testExceptionalSender() { /** @var ShortMessageInterface|\PHPUnit_Framework_MockObject_MockObject $message */ $message = $this->getMock('ScayTrase\\SmsDeliveryBundle\\Service\\ShortMessageInterface'); $transport = new DummyTransport(); $sender = new MessageDeliveryService($transport); self::assertFalse($sender->spoolMessage($message)); $profile = $sender->getProfile(); self::assertCount(1, $profile); self::assertEquals('Sending not configured', $profile[0]->getReason()); }
public function onTerminate() { $spool = $this->sender->getSpool(); if ($spool instanceof MemorySpool) { try { $spool->flush(); } catch (\Exception $exception) { if (null !== $this->logger) { $this->logger->error(sprintf('Exception occurred while flushing message queue: %s', $exception->getMessage())); } } } }
public function testSpoolingAndFlushing() { /** @var \PHPUnit_Framework_MockObject_MockObject|TransportInterface $transport */ $transport = $this->getMock('ScayTrase\\SmsDeliveryBundle\\Transport\\TransportInterface'); $transport->expects(self::any())->method('send')->willReturn(true); $spool = new MemorySpool(); $sender = new MessageDeliveryService($transport, $spool); /** @var ShortMessageInterface|\PHPUnit_Framework_MockObject_MockObject $message */ $message = $this->getMock('ScayTrase\\SmsDeliveryBundle\\Service\\ShortMessageInterface'); self::assertTrue($sender->spoolMessage($message)); $profile = $sender->getProfile(); self::assertCount(1, $profile); self::assertEquals(Package::STATUS_SPOOLED, $profile[0]->getStatus()); self::assertTrue($sender->getSpool()->flush()); self::assertCount(1, $profile); self::assertEquals(Package::STATUS_SUCCESS, $profile[0]->getStatus()); }
public function testDataCollector() { $transport = new DummyTransport(); /** @var MessageDeliveryService $sender */ $sender = new MessageDeliveryService($transport, new DisabledSpool()); $collector = new MessageDeliveryDataCollector($sender); /** @var ShortMessageInterface|\PHPUnit_Framework_MockObject_MockObject $message */ $message = $this->getMock('ScayTrase\\SmsDeliveryBundle\\Service\\ShortMessageInterface'); self::assertTrue($sender->spoolMessage($message)); $collector->collect(new Request(), new Response()); self::assertEquals(1, count($collector->getData())); }
/** * Collects data for the given Request and Response. * * @param Request $request A Request instance * @param Response $response A Response instance * @param \Exception $exception An Exception instance * * @api */ public function collect(Request $request, Response $response, \Exception $exception = null) { $this->data = $this->sender->getProfile(); }