function it_resolves_the_repository_of_a_reference_data($configurationRegistry, $doctrine, ConfigurationInterface $configuration, ObjectRepository $repository)
 {
     $configuration->getClass()->willReturn('Acme\\Bundle\\AppBundle\\Entity\\Color');
     $configurationRegistry->get('colors')->willReturn($configuration);
     $doctrine->getRepository('Acme\\Bundle\\AppBundle\\Entity\\Color')->willReturn($repository);
     $this->resolve('colors')->shouldReturn($repository);
 }
 function it_checks_an_invalid_reference_data($em, ConfigurationInterface $configuration, ClassMetadataInfo $metadata)
 {
     $em->getClassMetadata(Argument::any())->willReturn($metadata);
     $metadata->getFieldMapping('code')->willReturn(['fieldName' => "code", 'type' => "string", 'length' => 255, 'unique' => false, 'columnName' => "code"]);
     $configuration->getClass()->willReturn('\\StdClass');
     $this->check($configuration)->shouldReturn(false);
     $this->getFailure()->shouldReturn('Please configure a "code" column with a unique constraint in your Reference Data mapping.');
 }
 function it_checks_an_invalid_product_value_for_multiple_reference_data(ConfigurationInterface $configuration)
 {
     $this->beConstructedWith('spec\\Pim\\Bundle\\ReferenceDataBundle\\RequirementChecker\\CustomInvalidProductValue');
     $configuration->getType()->willReturn(ConfigurationInterface::TYPE_MULTI);
     $configuration->getName()->willReturn('fabrics');
     $this->check($configuration)->shouldReturn(false);
     $this->getFailure()->shouldReturn('Please implement the accessors "getFabrics, setFabrics, addFabric, removeFabric" for ' . '"spec\\Pim\\Bundle\\ReferenceDataBundle\\RequirementChecker\\CustomInvalidProductValue".');
 }
 function it_checks_an_invalid_many_to_many_relationship($classMetadata, ConfigurationInterface $configuration)
 {
     $classMetadata->getAssociationMapping('fabrics')->willReturn(['type' => ClassMetadataInfo::MANY_TO_MANY, 'isOwningSide' => false]);
     $configuration->getType()->willReturn(ConfigurationInterface::TYPE_MULTI);
     $configuration->getName()->willReturn('fabrics');
     $this->check($configuration)->shouldReturn(false);
     $this->getFailure()->shouldReturn('Please configure your "spec\\Pim\\Bundle\\ReferenceDataBundle\\RequirementChecker\\CustomValidProductValue" ' . 'relation "fabrics" correctly. You can take the relation "options" as example.');
 }
 function it_checks_an_invalid_many_to_many_relationship($classMetadata, ConfigurationInterface $configuration)
 {
     $classMetadata->getFieldMapping('fabrics')->willReturn(['type' => 'entities', 'isOwningSide' => false, 'idsField' => 'fabricIds']);
     $classMetadata->getFieldMapping('fabricIds')->willReturn(['type' => 'collection']);
     $configuration->getType()->willReturn(ConfigurationInterface::TYPE_MULTI);
     $configuration->getName()->willReturn('fabrics');
     $this->check($configuration)->shouldReturn(false);
     $this->getFailure()->shouldReturn('Please configure the type and the owning side correctly in your ' . '"spec\\Pim\\Bundle\\ReferenceDataBundle\\RequirementChecker\\CustomValidProductValue" "fabrics" relation. ' . 'You can take the relation "options" as example.');
 }
 /**
  * {@inheritdoc}
  */
 public function check(ConfigurationInterface $configuration)
 {
     $name = $configuration->getName();
     if (1 === preg_match("/[^A-Za-z]/", $name)) {
         $this->failure = sprintf('Please use a proper name instead of "%s" for your Reference Data.', $name);
         return false;
     }
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function check(ConfigurationInterface $configuration)
 {
     $this->model = $configuration->getClass();
     $reflection = new \ReflectionClass($this->model);
     if (!$reflection->implementsInterface($this->interface)) {
         $this->failure = sprintf('Please implement "%s" for your Reference Data model "%s".', $this->interface, $this->model);
         return false;
     }
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function check(ConfigurationInterface $configuration)
 {
     try {
         $mapping = $this->getCodeFieldMapping($configuration->getClass());
     } catch (\Exception $e) {
         $this->failure = $e->getMessage();
         return false;
     }
     if (!isset($mapping['unique']) || true !== $mapping['unique']) {
         $this->failure = 'Please configure a "code" column with a unique constraint ' . 'in your Reference Data mapping.';
         return false;
     }
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function check(ConfigurationInterface $configuration)
 {
     $reflection = new \ReflectionClass($this->productValueClass);
     foreach ($this->getRequiredAccessorForSimpleReferenceData($configuration->getName()) as $accessor) {
         if (!$reflection->hasMethod($accessor)) {
             $this->missingAccessors[] = $accessor;
         }
     }
     if (ConfigurationInterface::TYPE_MULTI === $configuration->getType()) {
         foreach ($this->getRequiredAccessorForMultipleReferenceData($configuration->getName()) as $accessor) {
             if (!$reflection->hasMethod($accessor)) {
                 $this->missingAccessors[] = $accessor;
             }
         }
     }
     if (0 !== count($this->missingAccessors)) {
         $this->failure = sprintf('Please implement the accessors "%s" for "%s".', implode(', ', $this->missingAccessors), $this->productValueClass);
         return false;
     }
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function check(ConfigurationInterface $configuration)
 {
     try {
         $mapping = $this->getAssociationMapping($configuration->getName());
     } catch (\Exception $e) {
         $this->failure = $e->getMessage();
         return false;
     }
     if (ConfigurationInterface::TYPE_MULTI === $configuration->getType()) {
         $expectedType = ClassMetadataInfo::MANY_TO_MANY;
         $relationExample = 'options';
     } else {
         $expectedType = ClassMetadataInfo::MANY_TO_ONE;
         $relationExample = 'option';
     }
     if ($mapping['type'] !== $expectedType || true !== $mapping['isOwningSide']) {
         $this->failure = sprintf('Please configure your "%s" relation "%s" correctly. ' . 'You can take the relation "%s" as example.', $this->productValueClass, $configuration->getName(), $relationExample);
         return false;
     }
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function check(ConfigurationInterface $configuration)
 {
     try {
         $isFieldCollectionOk = true;
         $isFieldOk = $this->checkFieldMapping($configuration->getName(), $configuration->getType());
         if (ConfigurationInterface::TYPE_MULTI === $configuration->getType()) {
             $isFieldCollectionOk = $this->checkCollectionFieldMapping($configuration->getName());
         }
     } catch (\Exception $e) {
         $this->failure = $e->getMessage();
         return false;
     }
     if (!$isFieldOk || !$isFieldCollectionOk) {
         $relationExample = ConfigurationInterface::TYPE_MULTI === $configuration->getType() ? 'options' : 'option';
         $this->failure .= sprintf(' You can take the relation "%s" as example.', $relationExample);
         return false;
     }
     return true;
 }
 function it_checks_an_invalid_reference_data(ConfigurationInterface $configuration)
 {
     $configuration->getClass()->willReturn('\\StdClass');
     $this->check($configuration)->shouldReturn(false);
     $this->getFailure()->shouldReturn('Please implement "Pim\\Component\\ReferenceData\\Model\\ReferenceDataInterface" for your Reference Data model "\\StdClass".');
 }
 /**
  * {@inheritdoc}
  */
 public function register(ConfigurationInterface $configuration, $name)
 {
     $configuration->setName($name);
     self::$configurations[$name] = $configuration;
     return $this;
 }
 function it_checks_an_invalid_reference_data(ConfigurationInterface $configuration)
 {
     $configuration->getName()->willReturn('main-color');
     $this->check($configuration)->shouldReturn(false);
     $this->getFailure()->shouldReturn('Please use a proper name instead of "main-color" for your Reference Data.');
 }