public function test_it_should_throw_exception()
 {
     $categoryValidator = new CategoryValidator();
     $record = ['parentId' => ''];
     $this->expectException(AdapterException::class);
     $categoryValidator->checkRequiredFields($record);
 }
 /**
  * Insert/Update data into db
  *
  * @param array $records
  */
 public function write($records)
 {
     $records = $records['default'];
     $this->validateRecordsShouldNotBeEmpty($records);
     $records = Shopware()->Events()->filter('Shopware_Components_SwagImportExport_DbAdapters_CategoriesDbAdapter_Write', $records, ['subject' => $this]);
     foreach ($records as $index => $record) {
         try {
             $record = $this->validator->filterEmptyString($record);
             $category = $this->findCategoryById($record['categoryId']);
             if (!$category instanceof Category) {
                 $record = $this->dataManager->setDefaultFieldsForCreate($record, $this->defaultValues);
                 $category = $this->createCategoryAndSetId($record['categoryId']);
             }
             $this->validator->checkRequiredFields($record);
             $this->validator->validate($record, CategoryDataType::$mapper);
             $record['parent'] = $this->repository->find($record['parentId']);
             $this->validateParentCategory($record);
             $record = $this->prepareData($record, $index, $category->getId(), $records['customerGroups']);
             $category->fromArray($record);
             $this->validateCategoryModel($category);
             /** @var ClassMetadata $metaData */
             $metaData = $this->modelManager->getClassMetaData(Category::class);
             $metaData->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
             $this->modelManager->persist($category);
             $this->modelManager->flush($category);
         } catch (AdapterException $e) {
             $message = $e->getMessage();
             $this->saveMessage($message);
         }
     }
 }