Пример #1
0
 /**
  * Create state object
  *
  * @param string $cardType
  * @return \Magento\Centinel\Model\AbstractState|false
  */
 public function createState($cardType)
 {
     if (!isset($this->_stateClassMap[$cardType])) {
         return false;
     }
     return $this->_objectManager->create($this->_stateClassMap[$cardType]);
 }
Пример #2
0
 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->builder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\TaxRuleSearchResultsBuilder');
     $this->searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Service\\V1\\Data\\SearchCriteriaBuilder');
     $this->taxRuleBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\TaxRuleBuilder');
 }
Пример #3
0
 /**
  * Create new calculator
  *
  * @param string $type Type of calculator
  * @param int $storeId
  * @param Address $billingAddress
  * @param Address $shippingAddress
  * @param null|int $customerTaxClassId
  * @param null|int $customerId
  * @return \Magento\Tax\Model\Calculation\AbstractCalculator
  * @throws \InvalidArgumentException
  */
 public function create($type, $storeId, Address $billingAddress = null, Address $shippingAddress = null, $customerTaxClassId = null, $customerId = null)
 {
     switch ($type) {
         case self::CALC_UNIT_BASE:
             $className = 'Magento\\Tax\\Model\\Calculation\\UnitBaseCalculator';
             break;
         case self::CALC_ROW_BASE:
             $className = 'Magento\\Tax\\Model\\Calculation\\RowBaseCalculator';
             break;
         case self::CALC_TOTAL_BASE:
             $className = 'Magento\\Tax\\Model\\Calculation\\TotalBaseCalculator';
             break;
         default:
             throw new \InvalidArgumentException('Unknown calculation type: ' . $type);
     }
     /** @var \Magento\Tax\Model\Calculation\AbstractCalculator $calculator */
     $calculator = $this->objectManager->create($className, ['storeId' => $storeId]);
     if (null != $shippingAddress) {
         $calculator->setShippingAddress($shippingAddress);
     }
     if (null != $billingAddress) {
         $calculator->setBillingAddress($billingAddress);
     }
     if (null != $customerTaxClassId) {
         $calculator->setCustomerTaxClassId($customerTaxClassId);
     }
     if (null != $customerId) {
         $calculator->setCustomerId($customerId);
     }
     return $calculator;
 }
Пример #4
0
 /**
  * Retrieve router instance by id
  *
  * @param string $routerId
  * @return RouterInterface
  */
 protected function getRouterInstance($routerId)
 {
     if (!isset($this->routerList[$routerId]['object'])) {
         $this->routerList[$routerId]['object'] = $this->objectManager->create($this->routerList[$routerId]['class']);
     }
     return $this->routerList[$routerId]['object'];
 }
Пример #5
0
 /**
  * Create link builder instance
  *
  * @param string $instance
  * @param array $arguments
  * @return CopyConstructorInterface
  * @throws \InvalidArgumentException
  */
 public function create($instance, array $arguments = array())
 {
     if (!is_subclass_of($instance, '\\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface')) {
         throw new \InvalidArgumentException($instance . ' does not implement \\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface');
     }
     return $this->objectManager->create($instance, $arguments);
 }
 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->builder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\QuoteDetailsBuilder');
     $this->itemBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\QuoteDetails\\ItemBuilder');
     $this->addressBuilder = $this->objectManager->create('\\Magento\\Customer\\Service\\V1\\Data\\AddressBuilder');
 }
Пример #7
0
 /**
  * Create handler instance
  *
  * @param string $instance
  * @param array $arguments
  * @return object
  * @throws \InvalidArgumentException
  */
 public function create($instance, array $arguments = array())
 {
     if (!is_subclass_of($instance, '\\Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper\\HandlerInterface')) {
         throw new \InvalidArgumentException($instance . ' does not implement ' . 'Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper\\HandlerInterface');
     }
     return $this->objectManager->create($instance, $arguments);
 }
Пример #8
0
 /**
  * Retrieve subject
  *
  * @return \Magento\Backend\Model\Config\Structure\Element\Group
  */
 protected function _getSubject()
 {
     if (!$this->_subject) {
         $this->_subject = $this->_objectManager->create('Magento\\Backend\\Model\\Config\\Structure\\Element\\Group');
     }
     return $this->_subject;
 }
Пример #9
0
 /**
  * @param array $data
  * @dataProvider createTaxRateModelDataProvider
  */
 public function testCreateTaxRateModel($data)
 {
     $taxRateDataObjectBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\TaxRateBuilder');
     $zipRangeDataObjectBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\ZipRangeBuilder');
     /** @var  $converter \Magento\Tax\Model\Calculation\Rate\Converter */
     $converter = $this->objectManager->create('Magento\\Tax\\Model\\Calculation\\Rate\\Converter', ['taxRateDataObjectBuilder' => $taxRateDataObjectBuilder, 'zipRangeDataObjectBuilder' => $zipRangeDataObjectBuilder]);
     $taxRateDataObject = $taxRateDataObjectBuilder->populateWithArray($data)->create();
     $taxRateModel = $converter->createTaxRateModel($taxRateDataObject);
     //Assertion
     $this->assertEquals($taxRateDataObject->getId(), $taxRateModel->getId());
     $this->assertEquals($taxRateDataObject->getCountryId(), $taxRateModel->getTaxCountryId());
     $this->assertEquals($taxRateDataObject->getRegionId(), $taxRateModel->getTaxRegionId());
     $this->assertEquals($taxRateDataObject->getPostcode(), $taxRateModel->getTaxPostcode());
     $this->assertEquals($taxRateDataObject->getcode(), $taxRateModel->getCode());
     $this->assertEquals($taxRateDataObject->getPercentageRate(), $taxRateModel->getRate());
     if ($taxRateDataObject->getZipRange()) {
         if ($taxRateDataObject->getZipRange()->getFrom()) {
             $this->assertEquals($taxRateDataObject->getZipRange()->getFrom(), $taxRateModel->getZipFrom());
         } else {
             $this->assertNull($taxRateModel->getZipFrom());
         }
         if ($taxRateDataObject->getZipRange()->getTo()) {
             $this->assertEquals($taxRateDataObject->getZipRange()->getTo(), $taxRateModel->getZipTo());
         } else {
             $this->assertNull($taxRateModel->getTo());
         }
     } else {
         $this->assertNull($taxRateModel->getZipFrom());
         $this->assertNull($taxRateModel->getZipTo());
     }
 }
Пример #10
0
 public function setUp()
 {
     $directoryList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Filesystem\\DirectoryList', array('root' => \Magento\Framework\App\Filesystem::ROOT_DIR, 'directories' => array(\Magento\Framework\App\Filesystem::MODULES_DIR => array('path' => dirname(__DIR__)))));
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Filesystem', array('directoryList' => $directoryList));
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_model = $this->_objectManager->create('Magento\\Persistent\\Model\\Persistent\\Config', array('filesystem' => $filesystem));
 }
Пример #11
0
 /**
  * Run application
  *
  * @param string $applicationName
  * @param array $arguments
  * @return void
  */
 public function run($applicationName, array $arguments = array())
 {
     try {
         \Magento\Framework\Profiler::start('magento');
         if (!$this->_locator) {
             $locatorFactory = new \Magento\Framework\App\ObjectManagerFactory();
             $this->_locator = $locatorFactory->create($this->_rootDir, $this->_parameters);
         }
         $application = $this->_locator->create($applicationName, $arguments);
         $response = $application->launch();
         \Magento\Framework\Profiler::stop('magento');
         $response->sendResponse();
     } catch (\Exception $exception) {
         if (isset($this->_parameters[State::PARAM_MODE]) && $this->_parameters[State::PARAM_MODE] == State::MODE_DEVELOPER) {
             echo $exception->getMessage() . "\n\n";
             echo $exception->getTraceAsString();
         } else {
             $message = "Error happened during application run.\n";
             try {
                 if (!$this->_locator) {
                     throw new \DomainException();
                 }
                 $this->_locator->get('Magento\\Framework\\Logger')->logException($exception);
             } catch (\Exception $e) {
                 $message .= "Could not write error message to log. Please use developer mode to see the message.\n";
             }
             echo $message;
         }
     }
 }
Пример #12
0
 public function testInitForm()
 {
     $this->setupExistingCustomerData();
     $block = $this->_objectManager->create('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\Addresses');
     /** @var Addresses $block */
     $block = $block->initForm();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $block->getForm();
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Fieldset', $form->getElement('address_fieldset'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('prefix'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('firstname'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('middlename'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('lastname'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('suffix'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('company'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Multiline', $form->getElement('street'));
     $this->assertEquals(2, $form->getElement('street')->getLineCount());
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('city'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Select', $form->getElement('country_id'));
     $this->assertEquals('US', $form->getElement('country_id')->getValue());
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('region'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Hidden', $form->getElement('region_id'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('postcode'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('telephone'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('fax'));
     $this->assertInstanceOf('Magento\\Framework\\Data\\Form\\Element\\Text', $form->getElement('vat_id'));
 }
Пример #13
0
 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->appliedTaxBuilder = $this->objectManager->create('\\Magento\\Tax\\Service\\V1\\Data\\TaxDetails\\AppliedTaxBuilder');
     $this->taxDetailsItemBuilder = $this->objectManager->create('\\Magento\\Tax\\Service\\V1\\Data\\TaxDetails\\ItemBuilder');
     $this->taxDetailsBuilder = $this->objectManager->create('\\Magento\\Tax\\Service\\V1\\Data\\TaxDetailsBuilder');
 }
Пример #14
0
 protected function setUp()
 {
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_builder = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\Data\\CustomerDetailsBuilder');
     $this->_customerBuilder = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\Data\\CustomerBuilder');
     $this->_addressBuilder = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\Data\\AddressBuilder');
 }
Пример #15
0
 /**
  * @param string $className
  * @return \Magento\ImportExport\Model\Export\Entity\AbstractEntity|\Magento\ImportExport\Model\Export\AbstractEntity
  * @throws \InvalidArgumentException
  */
 public function create($className)
 {
     if (!$className) {
         throw new \InvalidArgumentException('Incorrect class name');
     }
     return $this->_objectManager->create($className);
 }
Пример #16
0
 /**
  * @param string $type
  * @return \Magento\SalesRule\Model\Rule\Action\Discount\DiscountInterface
  * @throws \InvalidArgumentException
  */
 public function create($type)
 {
     if (!isset($this->classByType[$type])) {
         throw new \InvalidArgumentException($type . ' is unknown type');
     }
     return $this->_objectManager->create($this->classByType[$type]);
 }
Пример #17
0
 /**
  * @param string $indexerInstanceName
  * @return \Magento\Index\Model\Indexer\AbstractIndexer|null
  */
 public function create($indexerInstanceName)
 {
     if ($indexerInstanceName) {
         return $this->_objectManager->create($indexerInstanceName);
     }
     return null;
 }
Пример #18
0
 /**
  * Create class instance with specified parameters
  *
  * @param array $data
  * @return LayoutInterface
  * @throws \InvalidArgumentException
  */
 public function create(array $data = array())
 {
     $layout = $this->_objectManager->create($this->_instanceName, $data);
     if (!$layout instanceof LayoutInterface) {
         throw new \InvalidArgumentException(get_class($layout) . ' must be an instance of LayoutInterface.');
     }
     return $layout;
 }
Пример #19
0
 /**
  * Return newly created instance of a view file list
  *
  * @param string $instanceName
  * @return \Magento\Framework\View\File\FileList
  * @throws \UnexpectedValueException
  */
 public function create($instanceName = self::FILE_LIST_COLLATOR)
 {
     $collator = $this->objectManager->get($instanceName);
     if (!$collator instanceof CollateInterface) {
         throw new \UnexpectedValueException("{$instanceName} has to implement the collate interface.");
     }
     return $this->objectManager->create('Magento\\Framework\\View\\File\\FileList', array('collator' => $collator));
 }
Пример #20
0
 /**
  * Create shared price adjustment
  *
  * @param string $className
  * @param array $arguments
  * @return \Magento\Framework\Pricing\Adjustment\AdjustmentInterface
  * @throws \InvalidArgumentException
  */
 public function create($className, array $arguments = [])
 {
     $adjustment = $this->objectManager->create($className, $arguments);
     if (!$adjustment instanceof AdjustmentInterface) {
         throw new \InvalidArgumentException($className . ' doesn\'t implement \\Magento\\Framework\\Pricing\\Adjustment\\AdjustmentInterface');
     }
     return $adjustment;
 }
Пример #21
0
 /**
  * Create layer filter
  *
  * @param string $className
  * @param array $data
  * @return \Magento\Catalog\Model\Layer\Filter\Attribute
  * @throws \Magento\Framework\Model\Exception
  */
 public function create($className, array $data = array())
 {
     $filter = $this->_objectManager->create($className, $data);
     if (!$filter instanceof \Magento\Catalog\Model\Layer\Filter\AbstractFilter) {
         throw new \Magento\Framework\Model\Exception($className . ' doesn\'t extends \\Magento\\Catalog\\Model\\Layer\\Filter\\AbstractFilter');
     }
     return $filter;
 }
Пример #22
0
 /**
  * Create price model for product of particular type
  *
  * @param string $className
  * @param array $data
  * @return \Magento\Catalog\Model\Product\Type\Price
  * @throws \Magento\Framework\Model\Exception
  */
 public function create($className, array $data = array())
 {
     $price = $this->_objectManager->create($className, $data);
     if (!$price instanceof \Magento\Catalog\Model\Product\Type\Price) {
         throw new \Magento\Framework\Model\Exception($className . ' doesn\'t extends \\Magento\\Catalog\\Model\\Product\\Type\\Price');
     }
     return $price;
 }
Пример #23
0
 /**
  * Creates new instances of payment method models
  *
  * @param string $className
  * @param array $data
  * @return \Magento\Payment\Model\MethodInterface
  * @throws \Magento\Framework\Model\Exception
  */
 public function create($className, $data = array())
 {
     $method = $this->_objectManager->create($className, $data);
     if (!$method instanceof \Magento\Payment\Model\MethodInterface) {
         throw new \Magento\Framework\Model\Exception(sprintf("%s class doesn't implement \\Magento\\Payment\\Model\\MethodInterface", $className));
     }
     return $method;
 }
Пример #24
0
 public function setUp()
 {
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_customerSession = $this->_objectManager->get('Magento\\Customer\\Model\\Session');
     $this->_customerAccountService = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     $this->_persistentSessionHelper = $this->_objectManager->create('Magento\\Persistent\\Helper\\Session');
     $this->_observer = $this->_objectManager->create('Magento\\Persistent\\Model\\Observer\\EmulateCustomer', ['customerAccountService' => $this->_customerAccountService, 'persistentSession' => $this->_persistentSessionHelper]);
 }
Пример #25
0
 /**
  * Create new form object
  *
  * @param string $form
  * @param array $data
  * @throws \InvalidArgumentException
  * @return \Magento\Eav\Model\Form
  */
 public function create($form, array $data = array())
 {
     $formInstance = $this->_objectManager->create($form, $data);
     if (false == $formInstance instanceof \Magento\Eav\Model\Form) {
         throw new \InvalidArgumentException($form . ' is not instance of \\Magento\\Eav\\Model\\Form');
     }
     return $formInstance;
 }
Пример #26
0
 /**
  * @param string $resourceName
  * @param string $moduleName
  * @return SetupInterface
  * @throws \LogicException
  */
 public function create($resourceName, $moduleName)
 {
     $className = isset($this->_resourceTypes[$resourceName]) ? $this->_resourceTypes[$resourceName] : 'Magento\\Framework\\Module\\Updater\\SetupInterface';
     if (false == is_subclass_of($className, self::INSTANCE_TYPE) && $className !== self::INSTANCE_TYPE) {
         throw new \LogicException($className . ' is not a \\Magento\\Framework\\Module\\Updater\\SetupInterface');
     }
     return $this->_objectManager->create($className, array('resourceName' => $resourceName, 'moduleName' => $moduleName));
 }
Пример #27
0
 protected function setUp()
 {
     $this->objectManager = Bootstrap::getObjectManager();
     $this->taxClassService = $this->objectManager->create('Magento\\Tax\\Service\\V1\\TaxClassService');
     $this->taxClassBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\TaxClassBuilder');
     $this->taxClassModel = $this->objectManager->create('Magento\\Tax\\Model\\ClassModel');
     $this->predefinedTaxClasses = [TaxClassServiceInterface::TYPE_PRODUCT => 'Taxable Goods', TaxClassServiceInterface::TYPE_CUSTOMER => 'Retail Customer'];
 }
Пример #28
0
 /**
  * Create instance of a total model
  *
  * @param string|null $class
  * @param array $arguments
  * @return \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal
  * @throws \Magento\Framework\Model\Exception
  */
 public function create($class = null, $arguments = array())
 {
     $class = $class ?: $this->_defaultTotalModel;
     if (!is_a($class, 'Magento\\Sales\\Model\\Order\\Pdf\\Total\\DefaultTotal', true)) {
         throw new \Magento\Framework\Model\Exception(sprintf('The PDF total model %s must be or extend \\Magento\\Sales\\Model\\Order\\Pdf\\Total\\DefaultTotal.', $class));
     }
     return $this->_objectManager->create($class, $arguments);
 }
Пример #29
0
 /**
  * @param string $className
  * @param array $data
  * @return AbstractCollection
  * @throws \InvalidArgumentException
  */
 public function create($className, array $data = array())
 {
     $instance = $this->_objectManager->create($className, $data);
     if (!$instance instanceof AbstractCollection) {
         throw new \InvalidArgumentException($className . ' does not implement \\Magento\\Sales\\Model\\Resource\\Order\\Collection\\AbstractCollection');
     }
     return $instance;
 }
Пример #30
0
 /**
  * Create class instance with specified parameters
  *
  * @param array $data
  * @return \Magento\Framework\App\Config\ValueInterface
  * @throws \InvalidArgumentException
  */
 public function create(array $data = array())
 {
     $model = $this->_objectManager->create($this->_instanceName, $data);
     if (!$model instanceof \Magento\Framework\App\Config\ValueInterface) {
         throw new \InvalidArgumentException('Invalid config field model: ' . $this->_instanceName);
     }
     return $model;
 }