本文整理匯總了PHP中Magento\TestFramework\ObjectManager::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP ObjectManager::create方法的具體用法?PHP ObjectManager::create怎麽用?PHP ObjectManager::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\TestFramework\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setUp
protected function setUp()
{
/** @var $storeManager \Magento\Framework\StoreManagerInterface */
$storeManager = self::$_objectManager->get('Magento\\Framework\\StoreManagerInterface');
$this->_store = $storeManager->getStore();
$this->_model = self::$_objectManager->create('Magento\\Catalog\\Model\\Category');
}
示例2: testSetAddress
/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
*/
public function testSetAddress()
{
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
$quote->load('test_order_1', 'reserved_order_id');
$cartId = $this->getQuoteMaskedId($quote->getId());
$serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . $cartId . '/billing-address', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Assign']];
$addressData = ['firstname' => 'John', 'lastname' => 'Smith', 'email' => '', 'company' => 'Magento Commerce Inc.', 'street' => ['Typical Street', 'Tiny House 18'], 'city' => 'Big City', 'region_id' => 12, 'region' => 'California', 'region_code' => 'CA', 'postcode' => '0985432', 'country_id' => 'US', 'telephone' => '88776655', 'fax' => '44332255'];
$requestData = ["cartId" => $cartId, 'address' => $addressData];
$addressId = $this->_webApiCall($serviceInfo, $requestData);
//reset $quote to reload data
$quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
$quote->load('test_order_1', 'reserved_order_id');
$address = $quote->getBillingAddress();
$address->getRegionCode();
$savedData = $address->getData();
$this->assertEquals($addressId, $savedData['address_id']);
//custom checks for street, region and address_type
foreach ($addressData['street'] as $streetLine) {
$this->assertContains($streetLine, $quote->getBillingAddress()->getStreet());
}
unset($addressData['street']);
unset($addressData['email']);
$this->assertEquals('billing', $savedData['address_type']);
//check the rest of fields
foreach ($addressData as $key => $value) {
$this->assertEquals($value, $savedData[$key]);
}
}
示例3: testSend
/**
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @dataProvider customerFunctionDataProvider
*
* @param bool isCustomerIdUsed
*/
public function testSend($isCustomerIdUsed)
{
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
$this->_emailModel = $this->_objectManager->create('Magento\\ProductAlert\\Model\\Email');
/** @var \Magento\Store\Model\Website $website */
$website = $this->_objectManager->create('Magento\\Store\\Model\\Website');
$website->load(1);
$this->_emailModel->setWebsite($website);
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
$customerRepository = $this->_objectManager->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
$customer = $customerRepository->getById(1);
if ($isCustomerIdUsed) {
$this->_emailModel->setCustomerId(1);
} else {
$this->_emailModel->setCustomerData($customer);
}
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
$product->load(1);
$this->_emailModel->addPriceProduct($product);
$this->_emailModel->send();
/** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
$transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
$this->assertContains('John Smith,', $transportBuilder->getSentMessage()->getBodyHtml()->getRawContent());
}
示例4: testSave
/**
* @magentoApiDataFixture Magento/GiftMessage/_files/quote_with_item_message.php
*/
public function testSave()
{
// sales/gift_options/allow_items must be set to 1 in system configuration
// @todo remove next statement when \Magento\TestFramework\TestCase\WebapiAbstract::_updateAppConfig is fixed
$this->markTestIncomplete('This test relies on system configuration state.');
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
$quote->load('test_order_item_with_message', 'reserved_order_id');
$product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
$product->load($product->getIdBySku('simple_with_message'));
$itemId = $quote->getItemByProduct($product)->getId();
$cartId = $quote->getId();
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\QuoteIdMaskFactory')->create();
$quoteIdMask->load($cartId, 'quote_id');
//Use masked cart Id
$cartId = $quoteIdMask->getMaskedId();
$serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . $cartId . '/gift-message/' . $itemId, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Save']];
$requestData = ['cartId' => $cartId, 'itemId' => $itemId, 'giftMessage' => ['recipient' => 'John Doe', 'sender' => 'Jane Roe', 'message' => 'Gift Message Text New']];
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
// $quote->load('test_order_item_with_message', 'reserved_order_id');
$messageId = $quote->getItemByProduct($product)->getGiftMessageId();
/** @var \Magento\GiftMessage\Model\Message $message */
$message = $this->objectManager->create('Magento\\GiftMessage\\Model\\Message')->load($messageId);
$this->assertEquals('John Doe', $message->getRecipient());
$this->assertEquals('Jane Roe', $message->getSender());
$this->assertEquals('Gift Message Text New', $message->getMessage());
}
示例5: setUp
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->filterBuilder = $this->objectManager->create('Magento\\Framework\\Api\\FilterBuilder');
$this->sortOrderBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SortOrderBuilder');
$this->searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
}
示例6: testSetGetProduct
/**
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*/
public function testSetGetProduct()
{
$this->assertSame($this->product, $this->block->getProduct());
$product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
$this->block->setProduct($product);
$this->assertSame($product, $this->block->getProduct());
}
示例7: setUp
protected function setUp()
{
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->_model = $this->_objectManager->create('Magento\\Tax\\Model\\Calculation');
$this->customerRepository = $this->_objectManager->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
$this->addressRepository = $this->_objectManager->create('Magento\\Customer\\Api\\AddressRepositoryInterface');
$this->groupRepository = $this->_objectManager->create('Magento\\Customer\\Api\\GroupRepositoryInterface');
}
示例8: setUp
protected function setUp()
{
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $sessionManager \Magento\Framework\Session\SessionManager */
$sessionManager = $this->_objectManager->get('Magento\\Framework\\Session\\SessionManager');
if ($sessionManager->isSessionExists()) {
$sessionManager->writeClose();
}
$this->_model = $this->_objectManager->create('Magento\\Framework\\Session\\Config', array('saveMethod' => 'files', 'cacheLimiter' => $this->_cacheLimiter));
}
示例9: setUp
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->config = $this->objectManager->create('Magento\\Config\\Model\\ResourceModel\\Config');
$this->config->saveConfig('google/analytics/active', 1, 'default', 0);
$this->config->saveConfig('google/analytics/type', 'universal', 'default', 0);
$this->config->saveConfig('google/analytics/experiments', 1, 'default', 0);
$this->config->saveConfig('google/analytics/account', 1234567890, 'default', 0);
$this->resetConfig();
}
示例10: testExecute
/**
* @covers \Magento\Catalog\Model\Product\Gallery\ReadHandler::execute
*/
public function testExecute()
{
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
$product->setId(1);
$this->readHandler->execute('Magento\\Catalog\\Api\\Data\\ProductInterface', $product);
$data = $product->getData();
$this->assertArrayHasKey('media_gallery', $data);
$this->assertArrayHasKey('images', $data['media_gallery']);
$this->assertEquals('Image Alt Text', $data['media_gallery']['images'][0]['label']);
}
示例11: getOptions
/**
* Receive product options with values
*
* @return array
*/
protected function getOptions()
{
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->create('Magento\\Catalog\\Api\\ProductRepositoryInterface');
$product = $productRepository->get(self::SIMPLE_PRODUCT_SKU);
$options = [];
/** @var ProductCustomOptionInterface $option */
foreach ($product->getOptions() as $option) {
$options[] = ['option_id' => $option->getId(), 'option_value' => $this->getOptionRequestValue($option)];
}
return $options;
}
示例12: testGet
/**
* @magentoApiDataFixture Magento/Sales/_files/order.php
*/
public function testGet()
{
/** @var \Magento\Sales\Model\Order $order */
$order = $this->objectManager->create('Magento\\Sales\\Model\\Order');
$order->loadByIncrementId(self::ORDER_INCREMENT_ID);
/** @var \Magento\Sales\Model\Order\Item $orderItem */
$orderItem = current($order->getItems());
$serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $orderItem->getId(), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'get']];
$response = $this->_webApiCall($serviceInfo, ['id' => $orderItem->getId()]);
$this->assertTrue(is_array($response));
$this->assertOrderItem($orderItem, $response);
}
示例13: testCheckClassCanBeDeletedProductClassUsedInTaxRule
/**
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Tax/_files/tax_classes.php
*/
public function testCheckClassCanBeDeletedProductClassUsedInTaxRule()
{
/** @var $registry \Magento\Framework\Registry */
$registry = $this->_objectManager->get('Magento\\Framework\\Registry');
/** @var $taxRule \Magento\Tax\Model\Calculation\Rule */
$taxRule = $registry->registry('_fixture/Magento_Tax_Model_Calculation_Rule');
$productClasses = $taxRule->getProductTaxClasses();
/** @var $model \Magento\Tax\Model\ClassModel */
$model = $this->_objectManager->create('Magento\\Tax\\Model\\ClassModel')->load($productClasses[0]);
$this->setExpectedException('Magento\\Framework\\Exception\\CouldNotDeleteException', 'You cannot delete this tax class because it is used in' . ' Tax Rules. You have to delete the rules it is used in first.');
$model->delete();
}
示例14: testGetTotals
/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php
*/
public function testGetTotals()
{
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
$quote->load('test_order_1', 'reserved_order_id');
$cartId = $this->getQuoteMaskedId($quote->getId());
/** @var \Magento\Quote\Model\Quote\Address $shippingAddress */
$shippingAddress = $quote->getShippingAddress();
$data = [Totals::KEY_BASE_GRAND_TOTAL => $quote->getBaseGrandTotal(), Totals::KEY_GRAND_TOTAL => $quote->getGrandTotal(), Totals::KEY_BASE_SUBTOTAL => $quote->getBaseSubtotal(), Totals::KEY_SUBTOTAL => $quote->getSubtotal(), Totals::KEY_BASE_SUBTOTAL_WITH_DISCOUNT => $quote->getBaseSubtotalWithDiscount(), Totals::KEY_SUBTOTAL_WITH_DISCOUNT => $quote->getSubtotalWithDiscount(), Totals::KEY_DISCOUNT_AMOUNT => $shippingAddress->getDiscountAmount(), Totals::KEY_BASE_DISCOUNT_AMOUNT => $shippingAddress->getBaseDiscountAmount(), Totals::KEY_SHIPPING_AMOUNT => $shippingAddress->getShippingAmount(), Totals::KEY_BASE_SHIPPING_AMOUNT => $shippingAddress->getBaseShippingAmount(), Totals::KEY_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getShippingDiscountAmount(), Totals::KEY_BASE_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getBaseShippingDiscountAmount(), Totals::KEY_TAX_AMOUNT => $shippingAddress->getTaxAmount(), Totals::KEY_BASE_TAX_AMOUNT => $shippingAddress->getBaseTaxAmount(), Totals::KEY_SHIPPING_TAX_AMOUNT => $shippingAddress->getShippingTaxAmount(), Totals::KEY_BASE_SHIPPING_TAX_AMOUNT => $shippingAddress->getBaseShippingTaxAmount(), Totals::KEY_SUBTOTAL_INCL_TAX => $shippingAddress->getSubtotalInclTax(), Totals::KEY_BASE_SUBTOTAL_INCL_TAX => $shippingAddress->getBaseSubtotalTotalInclTax(), Totals::KEY_SHIPPING_INCL_TAX => $shippingAddress->getShippingInclTax(), Totals::KEY_BASE_SHIPPING_INCL_TAX => $shippingAddress->getBaseShippingInclTax(), Totals::KEY_BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)]];
$requestData = ['cartId' => $cartId];
$data = $this->formatTotalsData($data);
$this->assertEquals($data, $this->_webApiCall($this->getServiceInfoForTotalsService($cartId), $requestData));
}
示例15: tearDown
protected function tearDown()
{
try {
$cart = $this->getCart('test01');
$cart->delete();
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
$quoteIdMask = $this->objectManager->create('Magento\\Quote\\Model\\QuoteIdMask');
$quoteIdMask->delete($cart->getId());
} catch (\InvalidArgumentException $e) {
// Do nothing if cart fixture was not used
}
parent::tearDown();
}