/** * Initialize * * @return null */ public function initialize() { if ($this->isInitialized) { return; } if (!$this->featureSet instanceof Feature\FeatureSet) { $this->featureSet = new Feature\FeatureSet(); } $this->featureSet->setTableGateway($this); $this->featureSet->apply('preInitialize', array()); if (!$this->adapter instanceof Adapter) { throw new Exception\RuntimeException('This table does not have an Adapter setup'); } if (!is_string($this->table) && !$this->table instanceof TableIdentifier) { throw new Exception\RuntimeException('This table object does not have a valid table set.'); } if (!$this->resultSetPrototype instanceof ResultSetInterface) { $this->resultSetPrototype = new ResultSet(); } if (!$this->sql instanceof Sql) { $this->sql = new Sql($this->adapter, $this->table); } $this->featureSet->apply('postInitialize', array()); $this->isInitialized = true; }
/** * @cover FeatureSet::addFeature * @group ZF2-4993 */ public function testAddFeatureThatFeatureDoesnotHasTableGatewayButFeatureSetHas() { $mockMasterAdapter = $this->getMock('Zend\\Db\\Adapter\\AdapterInterface', array('getDriver', 'getPlatform')); $mockStatement = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface'); $mockDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface'); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); $mockMasterAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); $mockMasterAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue(new \Zend\Db\Adapter\Platform\Sql92())); $mockSlaveAdapter = $this->getMock('Zend\\Db\\Adapter\\AdapterInterface', array('getDriver', 'getPlatform')); $mockStatement = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface'); $mockDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface'); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); $mockSlaveAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); $mockSlaveAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue(new \Zend\Db\Adapter\Platform\Sql92())); $tableGatewayMock = $this->getMockForAbstractClass('Zend\\Db\\TableGateway\\AbstractTableGateway'); //feature doesn't have tableGateway, but FeatureSet has $feature = new MasterSlaveFeature($mockSlaveAdapter); $featureSet = new FeatureSet(); $featureSet->setTableGateway($tableGatewayMock); $this->assertInstanceOf('Zend\\Db\\TableGateway\\Feature\\FeatureSet', $featureSet->addFeature($feature)); }