function it_should_rollback_on_the_sub_items(Transactional $item) { $item->beginTransaction()->shouldBeCalled(); $item->rollback()->shouldBeCalled(); $this->addTransactionalItem($item); $this->beginTransaction(); $this->rollback(); }
function it_should_rollback_right_away(Transactional $item) { $item->beginTransaction()->shouldBeCalledTimes(1); $item->rollback()->shouldBeCalledTimes(1); $this->addTransactionalItem($item); $this->beginTransaction(); $this->beginTransaction(); $this->rollback(); $this->rollback(); }
/** * @test */ public function it_should_rollback_if_consumer_throws_exception() { $this->setExpectedException(\Exception::class); $this->transactionManager->shouldReceive('beginTransaction'); $this->transactionManager->shouldReceive('commit')->never(); $this->transactionManager->shouldReceive('rollback'); $this->consumer->shouldReceive('consume')->andThrow(\Exception::class); $consumer = new TransactionalConsumer($this->consumer, $this->transactionManager); $consumer->consume('test'); }
/** * Consumes a message. * * @param string $message * * @return string|null|void * * @throws \Exception */ public function consume($message) { try { $this->transactionManager->beginTransaction(); } catch (BeginException $e) { throw new ConsumerException($e->getMessage(), $e->getCode(), $e); } try { $this->consumer->consume($message); $this->transactionManager->commit(); } catch (\Exception $e) { $this->transactionManager->rollback(); throw $e; } }