示例#1
0
 /**
  * {@inheritdoc}
  */
 public function toOptionArray()
 {
     if ($this->_options === null) {
         $this->_options = [];
         foreach ($this->_importConfig->getAvailableServices() as $serviceName) {
             $this->_options[] = ['label' => $this->_importConfig->getServiceLabel($serviceName), 'value' => $serviceName];
         }
     }
     return $this->_options;
 }
 public function testToOptionArray()
 {
     $this->_importConfig->expects($this->once())->method('getAvailableServices')->will($this->returnValue(['service_one', 'service_two']));
     $this->_importConfig->expects($this->at(1))->method('getServiceLabel')->with('service_one')->will($this->returnValue('Service One'));
     $this->_importConfig->expects($this->at(2))->method('getServiceLabel')->with('service_two')->will($this->returnValue('Service Two'));
     $expectedResult = [['value' => 'service_one', 'label' => 'Service One'], ['value' => 'service_two', 'label' => 'Service Two']];
     $this->assertEquals($expectedResult, $this->_model->toOptionArray());
     // Makes sure the value is calculated only once
     $this->assertEquals($expectedResult, $this->_model->toOptionArray());
 }
示例#3
0
 /**
  * Create new import object
  *
  * @param string $serviceName
  * @param array $data
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @return \Magento\Directory\Model\Currency\Import\ImportInterface
  */
 public function create($serviceName, array $data = [])
 {
     $serviceClass = $this->_serviceConfig->getServiceClass($serviceName);
     if (!$serviceClass) {
         throw new \InvalidArgumentException("Currency import service '{$serviceName}' is not defined.");
     }
     $serviceInstance = $this->_objectManager->create($serviceClass, $data);
     if (!$serviceInstance instanceof \Magento\Directory\Model\Currency\Import\ImportInterface) {
         throw new \UnexpectedValueException("Class '{$serviceClass}' has to implement \\Magento\\Directory\\Model\\Currency\\Import\\ImportInterface.");
     }
     return $serviceInstance;
 }
 /**
  * @param string $serviceName
  * @param mixed $expectedResult
  * @dataProvider getServiceLabelDataProvider
  */
 public function testGetServiceLabel($serviceName, $expectedResult)
 {
     $this->assertEquals($expectedResult, $this->_model->getServiceLabel($serviceName));
 }
示例#5
0
 /**
  * @expectedException \UnexpectedValueException
  * @expectedExceptionMessage Class 'stdClass' has to implement
  * \Magento\Directory\Model\Currency\Import\ImportInterface
  */
 public function testCreateIrrelevantServiceClass()
 {
     $this->_importConfig->expects($this->once())->method('getServiceClass')->with('test')->will($this->returnValue('stdClass'));
     $this->_objectManager->expects($this->once())->method('create')->with('stdClass')->will($this->returnValue(new \stdClass()));
     $this->_model->create('test');
 }