metadataPool = $this->getMockBuilder(MetadataPool::class) ->disableOriginalConstructor() ->getMock(); $this->resourceConnection = $this->getMockBuilder(ResourceConnection::class) ->disableOriginalConstructor() ->getMock(); $this->createMain = $this->getMockBuilder(CreateMain::class) ->disableOriginalConstructor() ->getMock(); $this->sequenceApplier = $this->getMockBuilder(SequenceApplier::class) ->disableOriginalConstructor() ->getMock(); $objectManagerHelper = new ObjectManager($this); $this->create = $objectManagerHelper->getObject(Create::class, [ 'metadataPool' => $this->metadataPool, 'resourceConnection' => $this->resourceConnection, 'createMain' => $this->createMain, 'sequenceApplier' => $this->sequenceApplier, ]); } /** * @expectedException \Magento\Framework\Exception\AlreadyExistsException */ public function testDuplicateExceptionProcessingOnExecute() { $metadata = $this->createMock(EntityMetadataInterface::class); $this->metadataPool->expects($this->any())->method('getMetadata')->willReturn($metadata); $connection = $this->createMock(AdapterInterface::class); $connection->expects($this->once())->method('rollback'); $this->resourceConnection->expects($this->any())->method('getConnectionByName')->willReturn($connection); $this->createMain->expects($this->once())->method('execute')->willThrowException(new DuplicateException()); $entity = $this->getMockBuilder(DataObject::class) ->disableOriginalConstructor() ->getMock(); $this->create->execute($entity); } }