当前位置: 首页>>代码示例>>PHP>>正文


PHP ObjectManager::getInstance方法代码示例

本文整理汇总了PHP中Magento\TestFramework\ObjectManager::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::getInstance方法的具体用法?PHP ObjectManager::getInstance怎么用?PHP ObjectManager::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\TestFramework\ObjectManager的用法示例。


在下文中一共展示了ObjectManager::getInstance方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAddForDifferentWebsite

 /**
  * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
  * @magentoApiDataFixture Magento/Store/_files/website.php
  */
 public function testAddForDifferentWebsite()
 {
     $productSku = 'simple';
     $serviceInfo = ['rest' => ['resourcePath' => '/V1/products/' . $productSku . '/group-prices/1/price/10', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Add']];
     $this->_webApiCall($serviceInfo, ['sku' => $productSku, 'customerGroupId' => 1, 'price' => 10]);
     $objectManager = \Magento\TestFramework\ObjectManager::getInstance();
     /** @var \Magento\Catalog\Api\ProductGroupPriceManagementInterface $service */
     $service = $objectManager->get('Magento\\Catalog\\Api\\ProductGroupPriceManagementInterface');
     $prices = $service->getList($productSku);
     $this->assertCount(1, $prices);
     $this->assertEquals(10, $prices[0]->getValue());
     $this->assertEquals(1, $prices[0]->getCustomerGroupId());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:ProductGroupPriceManagementTest.php

示例2: testContactDataFieldsAreUpdatedByEmail

 public function testContactDataFieldsAreUpdatedByEmail()
 {
     $this->markTestSkipped();
     ///updatecontactdatafieldsbyemail called
     /** @var ObjectManager  $objectManager */
     $objectManager = ObjectManager::getInstance();
     $mockFormKeyValidator = $this->getMockBuilder(FromKeyValidator::class)->disableOriginalConstructor()->getMock();
     $mockFormKeyValidator->method('validate')->willReturn(true);
     $objectManager->addSharedInstance($mockFormKeyValidator, FromKeyValidator::class);
     $sessionMethods = array_merge(get_class_methods(CustomerSession::class), ['getConnectorContactId']);
     /**
      * Customer Session mock.
      */
     $mockCustomerSession = $this->getMockBuilder(CustomerSession::class)->disableOriginalConstructor()->setMethods($sessionMethods)->getMock();
     $mockCustomerSession->method('getConnectorContactId')->willReturn('dummy123');
     $mockCustomerSession->method('getCustomerId')->willReturn(1);
     $objectManager->addSharedInstance($mockCustomerSession, CustomerSession::class);
     /**
      * Customer mock.
      */
     $customerMethods = array_merge(get_class_methods(Customer::class));
     $mockCustomer = $this->getMockBuilder(Customer::class)->disableOriginalConstructor()->getMock();
     /**
      * Store mock.
      */
     $storeMethods = array_merge(get_class_methods(Store::class), ['getWebsite']);
     $mockStore = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock();
     /**
      * Helper mock.
      */
     $mockHelper = $this->getMockBuilder(Data::class)->disableOriginalConstructor()->getMock();
     /**
      * Client mock.
      */
     $mockClient = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock();
     //\Dotdigitalgroup\Email\Helper\Data
     $objectManager->addSharedInstance($mockHelper, Data::class);
     $mockCustomerSession->method('getCustomer')->willReturn($mockCustomer);
     $mockCustomer->method('getStore')->willReturn($mockStore);
     $mockStore->method('getWebsite')->willReturn('0');
     $mockHelper->method('isEnabled')->willReturn('1');
     $mockHelper->method('getWebsiteApiClient')->willReturn($mockClient);
     $mockClient->method('getContactById')->willReturn((object) ['id' => '111']);
     $mockClient->method('setApiUsername')->willReturn('93465');
     $mockClient->method('getDataFields')->willReturn([]);
     $mockClient->method('setApipassword')->willReturn('pass');
     $mockClient->method('getContactById')->willReturn((object) ['id' => '111']);
     $mockClient->expects($this->atLeastOnce())->method('updateContactDatafieldsByEmail')->willReturn(true);
     $this->getRequest()->setParam('data_fields', []);
     $this->dispatch('connector/customer/newsletter');
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:51,代码来源:NewsletterTest.php

示例3:

<?php

/**
 * Paid invoice fixture.
 *
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
require 'order_fixture_store.php';
/** @var \Magento\Sales\Model\Order $order */
$orderService = \Magento\TestFramework\ObjectManager::getInstance()->create('Magento\\Sales\\Model\\Service\\Order', ['order' => $order]);
$invoice = $orderService->prepareInvoice();
$invoice->register();
$order->setIsInProcess(true);
$transactionSave = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\DB\\Transaction');
$transactionSave->addObject($invoice)->addObject($order)->save();
开发者ID:shabbirvividads,项目名称:magento2,代码行数:16,代码来源:invoice_fixture_store_order.php

示例4: getObjectManager

 /**
  * getObjectManager
  *
  * @return ObjectManager
  */
 private function getObjectManager()
 {
     $objectManager = ObjectManager::getInstance();
     return $objectManager;
 }
开发者ID:davidverholen,项目名称:magento2-teaser,代码行数:10,代码来源:ModuleConfigTest.php

示例5: testGet

 /**
  * @magentoApiDataFixture Magento/Catalog/_files/product_with_image.php
  */
 public function testGet()
 {
     $productSku = 'simple';
     $objectManager = \Magento\TestFramework\ObjectManager::getInstance();
     /** @var \Magento\Catalog\Model\ProductRepository $repository */
     $repository = $objectManager->create('Magento\\Catalog\\Model\\ProductRepository');
     $product = $repository->get($productSku);
     $image = current($product->getMediaGallery('images'));
     $imageId = $image['value_id'];
     $expected = ['label' => $image['label'], 'position' => $image['position'], 'disabled' => (bool) $image['disabled'], 'file' => $image['file'], 'types' => ['image', 'small_image', 'thumbnail']];
     $serviceInfo = ['rest' => ['resourcePath' => '/V1/products/' . $productSku . '/media/' . $imageId, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => 'catalogProductAttributeMediaGalleryManagementV1', 'serviceVersion' => 'V1', 'operation' => 'catalogProductAttributeMediaGalleryManagementV1Get']];
     $requestData = ['sku' => $productSku, 'imageId' => $imageId];
     $data = $this->_webApiCall($serviceInfo, $requestData);
     $actual = (array) $data;
     $this->assertEquals($expected['label'], $actual['label']);
     $this->assertEquals($expected['position'], $actual['position']);
     $this->assertEquals($expected['file'], $actual['file']);
     $this->assertEquals($expected['types'], $actual['types']);
     $this->assertEquals($expected['disabled'], (bool) $actual['disabled']);
 }
开发者ID:nja78,项目名称:magento2,代码行数:23,代码来源:ProductAttributeMediaGalleryManagementInterfaceTest.php

示例6: testCanBeLoadedByQuoteId

 /**
  * @magentoDbIsolation enabled
  */
 public function testCanBeLoadedByQuoteId()
 {
     $storeId = 1;
     $dummyQuoteId = 3;
     $model = $this->createCampaign(1, 'foo@example.com');
     $model->setData('store_id', $storeId);
     $model->setData('quote_id', $dummyQuoteId);
     $model->getResource()->save($model);
     /** @var Campaign $emptyModel */
     $emptyModel = ObjectManager::getInstance()->create(Campaign::class);
     $loadedModel = $emptyModel->loadByQuoteId($dummyQuoteId, $storeId);
     $this->assertSame($model->getId(), $loadedModel->getId());
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:16,代码来源:CampaignORMTest.php

示例7: testCreateAllStoreCode

 /**
  * @param array $fixtureProduct
  *
  * @dataProvider productCreationProvider
  * @magentoApiDataFixture Magento/Store/_files/fixture_store_with_catalogsearch_index.php
  */
 public function testCreateAllStoreCode($fixtureProduct)
 {
     $response = $this->saveProduct($fixtureProduct, 'all');
     $this->assertArrayHasKey(ProductInterface::SKU, $response);
     /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
     $storeManager = \Magento\TestFramework\ObjectManager::getInstance()->get('Magento\\Store\\Model\\StoreManagerInterface');
     foreach ($storeManager->getStores(true) as $store) {
         $code = $store->getCode();
         if ($code === Store::ADMIN_CODE) {
             continue;
         }
         $this->assertArrayHasKey(ProductInterface::SKU, $this->getProduct($fixtureProduct[ProductInterface::SKU], $code));
     }
     $this->deleteProduct($fixtureProduct[ProductInterface::SKU]);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:ProductRepositoryInterfaceTest.php

示例8:

<?php

/**
 * Not paid invoice fixture for online payment method.
 *
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
require 'order_paid_with_payflowpro.php';
/** @var \Magento\Sales\Model\Order $order */
$orderService = \Magento\TestFramework\ObjectManager::getInstance()->create('Magento\\Sales\\Api\\InvoiceManagementInterface');
$invoice = $orderService->prepareInvoice($order);
/** To allow invoice cancelling it should be created without capturing. */
$invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::NOT_CAPTURE)->register();
$order = $invoice->getOrder();
$order->setIsInProcess(true);
$transactionSave = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\DB\\Transaction');
$transactionSave->addObject($invoice)->addObject($order)->save();
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:18,代码来源:invoice_payflowpro.php

示例9: testUpdateWithAllGroups

 /**
  * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
  * @magentoAppIsolation enabled
  */
 public function testUpdateWithAllGroups()
 {
     $productSku = 'simple';
     $customerGroupId = 'all';
     $qty = 2;
     $price = 20;
     $serviceInfo = ['rest' => ['resourcePath' => '/V1/products/' . $productSku . '/group-prices/' . $customerGroupId . '/tiers/' . $qty . '/price/' . $price, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Add']];
     $requestData = ['sku' => $productSku, 'customerGroupId' => $customerGroupId, 'qty' => $qty, 'price' => $price];
     $this->_webApiCall($serviceInfo, $requestData);
     $objectManager = \Magento\TestFramework\ObjectManager::getInstance();
     /** @var \Magento\Catalog\Api\ProductTierPriceManagementInterface $service */
     $service = $objectManager->get('Magento\\Catalog\\Api\\ProductTierPriceManagementInterface');
     $prices = $service->getList($productSku, 'all');
     $this->assertCount(2, $prices);
     $this->assertEquals(20, (int) $prices[0]->getValue());
     $this->assertEquals(2, (int) $prices[0]->getQty());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:21,代码来源:ProductTierPriceManagementTest.php

示例10: testModuleIsEnabled

 public function testModuleIsEnabled()
 {
     $om = ObjectManager::getInstance();
     // TODO: get ready
 }
开发者ID:nadobnykh,项目名称:Like2Buy-magento2,代码行数:5,代码来源:ConfigTest.php

示例11: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->objectManager = ObjectManager::getInstance();
 }
开发者ID:davidverholen,项目名称:magento2-teaser,代码行数:5,代码来源:TeaserItemTest.php

示例12: testRuleWithSubtotalCondition

 public function testRuleWithSubtotalCondition()
 {
     //subtotal
     $conditionValue = '300.00';
     $attribute = 'subtotal';
     $this->createAbandonedCartRuleWithCondition($attribute, 'gteq', $conditionValue, self::RULE_OPERATOR_AND);
     $quote = $this->createQuoteWithSubtotal('500.00');
     $quote1 = $this->createQuoteWithSubtotal('1000.11');
     $quote2 = $this->createQuoteWithSubtotal('999.11');
     /** @var Rules $ruleService */
     $ruleService = ObjectManager::getInstance()->create(Rules::class);
     $ruleService->process($this->quoteCollection, Rules::ABANDONED, $this->currentWebsiteId);
     $this->assertQuoteCollectionNotContains($quote);
     $this->assertQuoteCollectionNotContains($quote1);
     $this->assertQuoteCollectionNotContains($quote2);
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:16,代码来源:RulesTest.php

示例13: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->objectManager = ObjectManager::getInstance();
     $this->subject = $this->objectManager->create($this->model);
 }
开发者ID:davidverholen,项目名称:magento2-teaser,代码行数:6,代码来源:TeaserItemTest.php


注:本文中的Magento\TestFramework\ObjectManager::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。