Пример #1
0
 public function testTypeInterfaceProperties()
 {
     $id = 'fk_table_1';
     $event = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->getMock();
     $node = new WhenNode($id, $event);
     $utilities = $this->getMock('Faker\\Components\\Engine\\Common\\Utilities');
     $generator = $this->getMock('PHPStats\\Generator\\GeneratorInterface');
     $locale = $this->getMock('Faker\\Locale\\LocaleInterface');
     $node->setUtilities($utilities);
     $node->setLocale($locale);
     $node->setGenerator($generator);
     $this->assertEquals($utilities, $node->getUtilities());
     $this->assertEquals($locale, $node->getLocale());
     $this->assertEquals($generator, $node->getGenerator());
 }
Пример #2
0
 public function addSelector($name, array $options = array())
 {
     # check if head is a column or a selector
     if (!($this->head instanceof ColumnNode or $this->head instanceof SelectorNode)) {
         throw new EngineException('Can not add new Selector without first setting a table, schema and column');
     }
     # validate name for empty string
     if (empty($name)) {
         throw new EngineException('Selector must have a name');
     }
     if (isset($options['name']) === false) {
         unset($options['name']);
     }
     $parent_id = $this->head->getId();
     switch ($name) {
         case 'alternate':
             $currentSelectorBuilder = new SelectorAlternateBuilder($parent_id . '.alternate', $this->eventDispatcher, $this->typeFactory, $this->util, $this->defaultGenerator, $this->defaultLocale, $this->db, $this->templateLoader);
             foreach ($options as $optionKey => $optionValue) {
                 $currentSelectorBuilder->attribute($optionKey, $optionValue);
             }
             $currentSelector = $currentSelectorBuilder->getNode();
             break;
         case 'pick':
             $currentSelectorBuilder = new SelectorWeightBuilder($parent_id . '.pick', $this->eventDispatcher, $this->typeFactory, $this->util, $this->defaultGenerator, $this->defaultLocale, $this->db, $this->templateLoader);
             foreach ($options as $optionKey => $optionValue) {
                 $currentSelectorBuilder->attribute($optionKey, $optionValue);
             }
             $currentSelector = $currentSelectorBuilder->getNode();
             break;
         case 'random':
             $currentSelectorBuilder = new SelectorRandomBuilder($parent_id . '.random', $this->eventDispatcher, $this->typeFactory, $this->util, $this->defaultGenerator, $this->defaultLocale, $this->db, $this->templateLoader);
             foreach ($options as $optionKey => $optionValue) {
                 $currentSelectorBuilder->attribute($optionKey, $optionValue);
             }
             $currentSelector = $currentSelectorBuilder->getNode();
             break;
         case 'swap':
             $currentSelectorBuilder = new SelectorSwapBuilder($parent_id . '.swap', $this->eventDispatcher, $this->typeFactory, $this->util, $this->defaultGenerator, $this->defaultLocale, $this->db, $this->templateLoader);
             foreach ($options as $optionKey => $optionValue) {
                 $currentSelectorBuilder->attribute($optionKey, $optionValue);
             }
             $currentSelector = $currentSelectorBuilder->getNode();
             break;
         case 'when':
             if (!$this->head instanceof SelectorNode) {
                 throw new EngineException('When node must have a selector as a parent');
             }
             if (!$this->head->getInternal() instanceof SwapSelector) {
                 throw new EngineException('When node must have a swap node as parent');
             }
             $currentSelector = new WhenNode($parent_id . '.when', $this->eventDispatcher);
             foreach ($options as $optionKey => $optionValue) {
                 $currentSelector->setOption($optionKey, $optionValue);
             }
             break;
         default:
             throw new EngineException('Unknown Selector:: ' . $name);
     }
     # add selector to head
     $this->head->addChild($currentSelector);
     # set the current selector to new head
     $this->head = $currentSelector;
     return $this;
 }