Esempio n. 1
0
 public function testFilenameSetter()
 {
     $data = new GeneratorData(uniqid('testSource', true));
     $filename = uniqid('testFilename', true);
     $data->setFilename($filename);
     $this->assertSame($filename, $data->getFilename());
 }
    /**
     * @dataProvider sourceCodeProvider
     *
     * @param string $code
     */
    public function testGenerate($code)
    {
        $data = new GeneratorData($code);
        $data->setFilename('testfilename.php');
        $this->assertSame(<<<CLASS
<?php

/**
 * Filename: testfilename.php
 */
class testClassName implements \\Oro\\Component\\Layout\\LayoutUpdateInterface
{
    public function updateLayout(\\Oro\\Component\\Layout\\LayoutManipulatorInterface \$layoutManipulator, \\Oro\\Component\\Layout\\LayoutItemInterface \$item)
    {
        echo 123;
    }
}
CLASS
, $this->generator->generate('testClassName', $data));
    }
 /**
  * {@inheritdoc}
  */
 protected function prepare(GeneratorData $data, VisitorCollection $visitorCollection)
 {
     $source = $data->getSource();
     if (is_array($source)) {
         if (isset($source[self::NODE_ACTIONS])) {
             // traversing through actions, looking for "@addTree" action
             $actions = $source[self::NODE_ACTIONS];
             foreach ($actions as $nodeNo => $actionDefinition) {
                 // do not validate syntax, error will be thrown afterwards
                 $actionName = is_array($actionDefinition) ? key($actionDefinition) : '';
                 if (self::ACTION_ADD_TREE === $actionName) {
                     $path = self::NODE_ACTIONS . '.' . $nodeNo;
                     $actionNode = reset($actionDefinition);
                     // looking for items, parent and tree it self
                     if (!isset($actionNode[self::NODE_ITEMS], $actionNode[self::NODE_TREE])) {
                         throw new SyntaxException('expected array with keys "items" and "tree"', $actionDefinition, $path);
                     }
                     $transformedActions = [];
                     $treeParent = key($actionNode[self::NODE_TREE]);
                     $tree = current($actionNode[self::NODE_TREE]);
                     try {
                         $this->processTree($transformedActions, $tree, $treeParent, $actionNode[self::NODE_ITEMS]);
                     } catch (\LogicException $e) {
                         throw new SyntaxException('invalid tree definition. ' . $e->getMessage(), $actionDefinition, $path);
                     }
                     // pre-generate "path" option in order to show correct path if validation error will occur
                     array_walk($transformedActions, function (&$val) use($path) {
                         $val[self::PATH_ATTR] = $path;
                     });
                     $source[self::NODE_ACTIONS] = array_merge($source[self::NODE_ACTIONS], $transformedActions);
                     // unset processed "@addTree" action
                     unset($source[self::NODE_ACTIONS][$nodeNo]);
                 }
             }
         }
         // apply extensions
         foreach ($this->extensions as $extension) {
             $extension->prepare($source, $visitorCollection);
         }
     }
     $data->setSource($source);
 }