Example #1
0
 /**
  * @cover FeatureSet::addFeature
  * @group ZF2-4993
  */
 public function testAddFeatureThatFeatureHasTableGatewayButFeatureSetDoesnotHas()
 {
     $tableGatewayMock = $this->getMockForAbstractClass('Zend\\Db\\TableGateway\\AbstractTableGateway');
     $metadataMock = $this->getMock('Zend\\Db\\Metadata\\MetadataInterface');
     $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(array('id', 'name')));
     $constraintObject = new ConstraintObject('id_pk', 'table');
     $constraintObject->setColumns(array('id'));
     $constraintObject->setType('PRIMARY KEY');
     $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue(array($constraintObject)));
     //feature have tableGateway, but FeatureSet doesn't has
     $feature = new MetadataFeature($metadataMock);
     $feature->setTableGateway($tableGatewayMock);
     $featureSet = new FeatureSet();
     $this->assertInstanceOf('Zend\\Db\\TableGateway\\Feature\\FeatureSet', $featureSet->addFeature($feature));
 }
 /**
  * @param $method
  * @param $arguments
  * @return mixed
  * @throws Exception\InvalidArgumentException
  */
 public function __call($method, $arguments)
 {
     if ($this->featureSet->canCallMagicCall($method)) {
         return $this->featureSet->callMagicCall($method, $arguments);
     }
     throw new Exception\InvalidArgumentException('Invalid method (' . $method . ') called, caught by ' . __CLASS__ . '::__call()');
 }
 /**
  * @param $method
  * @param $arguments
  * @return mixed
  * @throws Exception\InvalidArgumentException
  */
 public function __call($method, $arguments)
 {
     if ($this->featureSet->canCallMagicCall($method)) {
         return $this->featureSet->callMagicCall($method, $arguments);
     }
     throw new Exception\InvalidArgumentException(sprintf('Invalid method (%s) called, caught by %s::__call()', $method, __CLASS__));
 }
 /**
  * {@inheritdoc}
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $this->config[$requestedName];
     $dbAdapter = $container->get(isset($config['adapter']) ? $config['adapter'] : 'db');
     if (isset($config['schema'])) {
         $config['table'] = new TableIdentifier($config['table'], $config['schema']);
     }
     $featureSet = new FeatureSet();
     $featureSet->addFeature(new CommonCallFeature($config['primary']));
     if (isset($config['invokable'])) {
         $config['class'] = $config['invokable'];
     }
     if (isset($config['class'])) {
         if (!class_exists($config['class'])) {
             throw new \RuntimeException("Class '{$config['class']}' not found ");
         }
         /** @var \Zend\Db\TableGateway\TableGateway $table */
         $table = new $config['class']($config['table'], $dbAdapter, $featureSet);
     } else {
         $table = new TableGateway($config['table'], $dbAdapter, $featureSet);
     }
     if (isset($config['row'])) {
         if ($config['row'] === true) {
             $config['row'] = 'Zend\\Db\\RowGateway\\RowGateway';
         }
         if (is_string($config['row'])) {
             if (!class_exists($config['row'])) {
                 throw new \RuntimeException("Class '{$config['row']}' not found ");
             }
             $rowGatewayPrototype = new $config['row']($config['primary'], $config['table'], $dbAdapter, $table->getSql());
         } elseif (is_object($config['row'])) {
             $rowGatewayPrototype = $config['row'];
         } else {
             throw new \InvalidArgumentException('Error row argument');
         }
         $table->getResultSetPrototype()->setArrayObjectPrototype($rowGatewayPrototype);
     }
     return $table;
 }