Exemple #1
0
 /**
  * Returns list of available resources
  *
  * @return array
  */
 public function toOptionArray()
 {
     $resourceOptions = array();
     foreach (array_keys($this->_arguments->getResources()) as $resourceName) {
         $resourceOptions[] = array('value' => $resourceName, 'label' => $resourceName);
     }
     sort($resourceOptions);
     reset($resourceOptions);
     return $resourceOptions;
 }
Exemple #2
0
 /**
  * @param string|null $fixtureFrontendId
  * @param string $inputCacheType
  * @param string $expectedFrontendId
  *
  * @dataProvider getDataProvider
  */
 public function testGet($fixtureFrontendId, $inputCacheType, $expectedFrontendId)
 {
     $this->_arguments->expects($this->once())->method('getCacheTypeFrontendId')->with($inputCacheType)->will($this->returnValue($fixtureFrontendId));
     $cacheFrontend = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface');
     $this->_cachePool->expects($this->once())->method('get')->with($expectedFrontendId)->will($this->returnValue($cacheFrontend));
     $accessProxy = $this->getMock('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', array(), array(), '', false);
     $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', $this->identicalTo(array('frontend' => $cacheFrontend, 'identifier' => $inputCacheType)))->will($this->returnValue($accessProxy));
     $this->assertSame($accessProxy, $this->_model->get($inputCacheType));
     // Result has to be cached in memory
     $this->assertSame($accessProxy, $this->_model->get($inputCacheType));
 }
Exemple #3
0
 /**
  * Create connection adapter instance
  *
  * @param string $connectionName
  * @return \Magento\Framework\DB\Adapter\AdapterInterface
  * @throws \InvalidArgumentException
  */
 public function create($connectionName)
 {
     $connectionConfig = $this->_localConfig->getConnection($connectionName);
     if (!$connectionConfig || !isset($connectionConfig['active']) || !$connectionConfig['active']) {
         return null;
     }
     if (!isset($connectionConfig['adapter'])) {
         throw new \InvalidArgumentException('Adapter is not set for connection "' . $connectionName . '"');
     }
     $adapterInstance = $this->_objectManager->create($connectionConfig['adapter'], $connectionConfig);
     if (!$adapterInstance instanceof ConnectionAdapterInterface) {
         throw new \InvalidArgumentException('Trying to create wrong connection adapter');
     }
     return $adapterInstance->getConnection();
 }
Exemple #4
0
 /**
  * Retrieve settings for all cache front-ends known to the system
  *
  * @return array Format: array('<frontend_id>' => array(<cache_settings>), ...)
  */
 protected function _getCacheSettings()
 {
     /*
      * Merging is intentionally implemented through array_merge() instead of array_replace_recursive()
      * to avoid "inheritance" of the default settings that become irrelevant as soon as cache storage type changes
      */
     return array_merge($this->_frontendSettings, $this->_arguments->getCacheFrontendSettings());
 }
Exemple #5
0
 public function testCreate()
 {
     $config = ['active' => 1, 'adapter' => 'Magento\\Framework\\App\\Resource\\ConnectionAdapterInterface'];
     $this->localConfig->expects($this->once())->method('getConnection')->with('connection_name')->will($this->returnValue($config));
     $adapterMock = $this->getMock('Magento\\Framework\\App\\Resource\\ConnectionAdapterInterface');
     $this->objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Resource\\ConnectionAdapterInterface', $config)->will($this->returnValue($adapterMock));
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $adapterMock->expects($this->once())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->assertEquals($connectionMock, $this->model->create('connection_name'));
 }
Exemple #6
0
 /**
  * Retrieve cache frontend identifier, associated with a cache type
  *
  * @param string $cacheType
  * @return string
  */
 protected function _getCacheFrontendId($cacheType)
 {
     $result = $this->_arguments->getCacheTypeFrontendId($cacheType);
     if (!$result) {
         if (isset($this->_typeFrontendMap[$cacheType])) {
             $result = $this->_typeFrontendMap[$cacheType];
         } else {
             $result = \Magento\Framework\App\Cache\Frontend\Pool::DEFAULT_FRONTEND_ID;
         }
     }
     return $result;
 }
Exemple #7
0
 /**
  * Retrieve connection data from config
  *
  * @return array
  */
 public function getConnectionData()
 {
     if (!$this->_connectionData) {
         if ($this->_configData) {
             $connectionData = array('host' => $this->_configData['db_host'], 'username' => $this->_configData['db_user'], 'password' => $this->_configData['db_pass'], 'dbName' => $this->_configData['db_name'], 'pdoType' => $this->getPdoType());
         } else {
             $default = $this->_arguments->getConnection('default');
             $connectionData = array('host' => $default['host'], 'username' => $default['username'], 'password' => $default['password'], 'dbName' => $default['dbName'], 'pdoType' => $this->getPdoType());
         }
         $this->_connectionData = $connectionData;
     }
     return $this->_connectionData;
 }
Exemple #8
0
 public function testGetCacheFrontendSettings()
 {
     $this->assertEquals(self::$fixtureConfig['cache']['frontend'], $this->_arguments->getCacheFrontendSettings());
     $this->assertEquals(self::$fixtureConfigMerged['cache']['frontend'], $this->_argumentsMerged->getCacheFrontendSettings());
 }
Exemple #9
0
 protected function setUp()
 {
     $this->configMock = $this->getMock('Magento\\Framework\\App\\Arguments', array(), array(), '', false);
     $this->configMock->expects($this->any())->method('getResources')->will($this->returnValue(array('default_setup' => array('default_setup'), 'custom_resource' => array('custom_resource'))));
     $this->mediaDatabase = new \Magento\Backend\Model\Config\Source\Storage\Media\Database($this->configMock);
 }
Exemple #10
0
 /**
  * Installation config data
  *
  * @param   array $data
  * @return  $this
  */
 public function installConfig($data)
 {
     $data['db_active'] = true;
     $data = $this->_installerDb->checkDbConnectionData($data);
     $this->_installerConfig->setConfigData($data)->install();
     $this->_arguments->reload();
     $this->_resource->setTablePrefix($data['db_prefix']);
     $this->_config->reinit();
     return $this;
 }
Exemple #11
0
 /**
  * {@inheritdoc}
  */
 public function reload()
 {
     return $this->subject->reload();
 }