public function testFindColumn()
 {
     $schema = $this->getMockComposite();
     $tables = $schema->getChildren();
     $finder = new CompositeFinder();
     $finder->set($tables[1]);
     $this->assertEquals('columnB1', $finder->column('columnB1')->get()->getId());
     $this->assertEquals('columnB1', $finder->column('columnB1')->get()->getId());
     $finder->set($tables[2]);
     $this->assertEquals(null, $finder->column('columnB1')->get());
     $finder->set($tables[1]);
     $this->assertEquals(null, $finder->column('ss')->get());
 }
 public function visitDirectedGraphBuilder(CompositeInterface $composite)
 {
     $builder = $this->pathBuilder;
     $parentNode = $composite->getParent();
     if ($composite instanceof SchemaNode) {
         $this->graph->setRoot($composite);
     } elseif ($composite instanceof TableNode) {
         # if we have a table connect to schema
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($parentNode), $parentNode);
     } elseif ($composite instanceof ColumnNode) {
         # if instance of column connect to table
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($parentNode), $parentNode);
     } elseif ($composite instanceof FormatterNode) {
         # if instance of formatterNode connect to schema
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($parentNode), $parentNode);
     } elseif ($composite instanceof ForeignKeyNode) {
         # if have a fk connect two columns and tables as well as the FKNode to FKColumn
         $finder = new CompositeFinder();
         $parentTable = $finder->set($composite)->parentTable()->get();
         $parentColumn = $finder->set($composite)->parentColumn()->get();
         $fkTableName = $composite->getOption('foreignTable');
         $fkColumnName = $composite->getOption('foreignColumn');
         $fkTable = $finder->set($composite)->table($fkTableName)->get();
         # Does the foreign table exist
         if ($fkTable === null) {
             throw new CompositeException($composite, sprintf('The Foreign Table %s does not exist', $fkTableName));
         }
         # match the column
         $fkColumn = $finder->set($composite)->table($fkTableName)->column($fkColumnName)->get();
         if ($fkColumn === null) {
             return new CompositeException($composite, sprintf('The Foreign Column %s.%s does not exist', $fkTableName, $fkColumnName));
         }
         # a Column could be related to many others for examaple as a composite primary key so
         # the ResultCache can't be attached to a column but instead to the ForeignKeyNode child of the column
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($fkColumn), $fkColumn);
         # connect the two columns for easy lookup for Circular Reference checks
         $this->graph->connect($builder->buildPath($parentColumn), $parentColumn, $builder->buildPath($fkColumn), $fkColumn);
         # tables are now related connect them for easy lookup for Circular Reference checks
         $this->graph->connect($builder->buildPath($parentTable), $parentTable, $builder->buildPath($fkTable), $fkTable);
     }
 }
 public function visitDatasourceGatherer(CompositeInterface $node)
 {
     $builder = $this->pathBuilder;
     $parentNode = $composite->getParent();
     if ($composite instanceof SchemaNode) {
         $this->graph->setRoot($composite);
     } elseif ($composite instanceof DatasourceNode) {
         # have a datasource related to schema it contained in.
         $finder = new CompositeFinder();
         $parentSchema = $finder->set($composite)->parentSchema()->get();
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($parentSchema), $parentSchema);
     } elseif ($composite instanceof TypeNode && $composite->getType() instanceof FromSource) {
         # if have Type node with internal FromSource.
         # were not relating this
         $finder = new CompositeFinder();
         $parentTable = $finder->set($composite)->parentTable()->get();
         $parentColumn = $finder->set($composite)->parentColumn()->get();
         $fkTableName = $composite->getOption('foreignTable');
         $fkColumnName = $composite->getOption('foreignColumn');
         $fkTable = $finder->set($composite)->table($fkTableName)->get();
         # Does the foreign table exist
         if ($fkTable === null) {
             throw new CompositeException($composite, sprintf('The Foreign Table %s does not exist', $fkTableName));
         }
         # match the column
         $fkColumn = $finder->set($composite)->table($fkTableName)->column($fkColumnName)->get();
         if ($fkColumn === null) {
             return new CompositeException($composite, sprintf('The Foreign Column %s.%s does not exist', $fkTableName, $fkColumnName));
         }
         # a Column could be related to many others for examaple as a composite primary key so
         # the ResultCache can't be attached to a column but instead to the ForeignKeyNode child of the column
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($fkColumn), $fkColumn);
         # connect the two columns for easy lookup for Circular Reference checks
         $this->graph->connect($builder->buildPath($parentColumn), $parentColumn, $builder->buildPath($fkColumn), $fkColumn);
         # tables are now related connect them for easy lookup for Circular Reference checks
         $this->graph->connect($builder->buildPath($parentTable), $parentTable, $builder->buildPath($fkTable), $fkTable);
     }
 }