public function testSetSession() { $mockUnitOfWork = $this->getMock(UnitOfWorkInterface::class); CurrentUnitOfWork::set($mockUnitOfWork); $this->assertSame($mockUnitOfWork, CurrentUnitOfWork::get()); CurrentUnitOfWork::clear($mockUnitOfWork); $this->assertFalse(CurrentUnitOfWork::isStarted()); }
public function setUp() { $this->mockEventBus = $this->getMock(EventBusInterface::class); $this->lockManager = $this->getMock(NullLockManager::class); // new NullLockManager(); //spy(new OptimisticLockManager()); $this->lockManager->expects($this->any())->method('validateLock')->will($this->returnValue(true)); $this->testSubject = new InMemoryLockingRepository(StubAggregate::class, $this->mockEventBus, $this->lockManager); //testSubject = spy(testSubject); // some UoW is started somewhere, but not shutdown in the same test. while (CurrentUnitOfWork::isStarted()) { CurrentUnitOfWork::get()->rollback(); } }
public function publish(array $events) { if (null === $this->connection) { throw new \RuntimeException("The AMQPTerminal has no connection configured."); } $channel = $this->connection->channel(); if ($this->isTransactional) { $channel->tx_select(); } try { if ($this->waitForAck) { $channel->confirm_select(); } foreach ($events as $event) { $amqpMessage = $this->messageConverter->createAmqpMessage($event); $this->doSendMessage($channel, $amqpMessage); } if (CurrentUnitOfWork::isStarted()) { CurrentUnitOfWork::get()->registerListener(new ChannelTransactionUnitOfWorkListener($this->logger, $channel, $this)); } elseif ($this->isTransactional) { $channel->tx_commit(); } elseif ($this->waitForAck) { $channel->wait_for_pending_acks($this->publisherAckTimeout); } } catch (\Exception $ex) { if ($this->isTransactional) { $this->tryRollback($channel); } throw new EventPublicationFailedException("Failed to dispatch Events to the Message Broker.", 0, $ex); } finally { if (!CurrentUnitOfWork::isStarted()) { $this->tryClose($channel); } } }
public function testDispatchCommand_ImplicitUnitOfWorkIsRolledBackOnException() { $command = new TestCommand("Say hi!"); $test = $this; $this->handlerRegistry->subscribe(TestCommand::class, new CallbackCommandHandler(function (CommandMessageInterface $commandMessage, UnitOfWorkInterface $unitOfWork) use($test) { $test->assertTrue(CurrentUnitOfWork::isStarted()); $test->assertNotNull(CurrentUnitOfWork::get()); throw new \RuntimeException("exception"); })); $callback = new ClosureCommandCallback(function ($result) use($command) { $this->fail("Did not expect exception"); }, function ($exception) { $this->assertEquals(\RuntimeException::class, get_class($exception)); }); $this->commandBus->dispatch(GenericCommandMessage::asCommandMessage($command), $callback); $this->assertFalse(CurrentUnitOfWork::isStarted()); }
public function tearDown() { while (CurrentUnitOfWork::isStarted()) { CurrentUnitOfWork::get()->rollback(); } }
public function testInnerUnitOfWorkCommittedBackWithOuter() { $isCommitted = false; $outer = DefaultUnitOfWork::startAndGet(); $inner = DefaultUnitOfWork::startAndGet(); $inner->registerListener(new AfterCommitTestAdapter(function (UnitOfWorkInterface $uow) use(&$isCommitted) { $isCommitted = true; })); $inner->commit(); $this->assertFalse($isCommitted, "The inner UoW was committed prematurely"); $outer->commit(); $this->assertTrue($isCommitted, "The inner UoW wasn't properly committed"); $this->assertFalse(CurrentUnitOfWork::isStarted(), "The UnitOfWork haven't been correctly cleared"); }