本文整理匯總了PHP中Magento\TestFramework\ObjectManager::get方法的典型用法代碼示例。如果您正苦於以下問題:PHP ObjectManager::get方法的具體用法?PHP ObjectManager::get怎麽用?PHP ObjectManager::get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\TestFramework\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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());
}
示例2: 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');
}
示例3: 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));
}
示例4: getCart
/**
* Retrieve quote by given reserved order ID
*
* @param string $reservedOrderId
* @return \Magento\Quote\Model\Quote
* @throws \InvalidArgumentException
*/
protected function getCart($reservedOrderId)
{
/** @var $cart \Magento\Quote\Model\Quote */
$cart = $this->objectManager->get('Magento\\Quote\\Model\\Quote');
$cart->load($reservedOrderId, 'reserved_order_id');
if (!$cart->getId()) {
throw new \InvalidArgumentException('There is no quote with provided reserved order ID.');
}
return $cart;
}
示例5: 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();
}
示例6: setUp
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->productRepository = $this->objectManager->create('Magento\\Catalog\\Api\\ProductRepositoryInterface');
try {
$this->product = $this->productRepository->get('simple');
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->product = $this->productRepository->get('simple_dropdown_option');
}
$this->objectManager->get('Magento\\Framework\\Registry')->unregister('current_product');
$this->objectManager->get('Magento\\Framework\\Registry')->register('current_product', $this->product);
$this->block = $this->objectManager->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Catalog\\Block\\Product\\View\\Options');
}
示例7: setUp
protected function setUp()
{
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $sessionManager \Magento\Framework\Session\SessionManager */
$sessionManager = $this->_objectManager->create('Magento\\Framework\\Session\\SessionManager');
if ($sessionManager->isSessionExists()) {
$sessionManager->writeClose();
}
$this->deploymentConfigMock = $this->getMock('Magento\\Framework\\App\\DeploymentConfig', [], [], '', false);
$this->deploymentConfigMock->expects($this->at(0))->method('get')->with(Config::PARAM_SESSION_SAVE_PATH)->will($this->returnValue(null));
$this->deploymentConfigMock->expects($this->at(1))->method('get')->with(Config::PARAM_SESSION_CACHE_LIMITER)->will($this->returnValue($this->_cacheLimiter));
$this->_model = $this->_objectManager->create('Magento\\Framework\\Session\\Config', ['deploymentConfig' => $this->deploymentConfigMock]);
$this->defaultSavePath = $this->_objectManager->get('Magento\\Framework\\Filesystem\\DirectoryList')->getPath(DirectoryList::SESSION);
}
示例8: setUp
protected function setUp()
{
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->_model = $this->_objectManager->get('Magento\\Framework\\Session\\SaveHandler\\DbTable');
/** @var $resource \Magento\Framework\App\Resource */
$resource = $this->_objectManager->get('Magento\\Framework\\App\\Resource');
$this->_connection = $resource->getConnection('core_write');
$this->_sessionTable = $resource->getTableName('session');
// session stores serialized objects with protected properties
// we need to test this case to ensure that DB adapter successfully processes "\0" symbols in serialized data
foreach ($this->_sourceData as $key => $data) {
$this->_sessionData[$key] = new \Magento\Framework\Object($data);
}
}
示例9: setUp
public function setUp()
{
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$xmlFiles = $this->getXmlConfigFiles();
if (!empty($xmlFiles)) {
$this->_fileResolverMock = $this->getMockBuilder('Magento\\Framework\\App\\Arguments\\FileResolver\\Primary')->disableOriginalConstructor()->getMock();
/* Enable Validation regardles of MAGE_MODE */
$validateStateMock = $this->getMockBuilder('Magento\\Framework\\Config\\ValidationStateInterface')->disableOriginalConstructor()->getMock();
$validateStateMock->expects($this->any())->method('isValidated')->will($this->returnValue(true));
$this->_reader = $this->_objectManager->create($this->_getReaderClassName(), ['configFiles' => $xmlFiles, 'fileResolver' => $this->_fileResolverMock, 'validationState' => $validateStateMock]);
/** @var \Magento\Framework\Filesystem $filesystem */
$filesystem = $this->_objectManager->get('Magento\\Framework\\Filesystem');
$this->_schemaFile = $filesystem->getDirectoryRead($this->getDirectoryConstant())->getAbsolutePath($this->_getXsdPath());
}
}
示例10: testSetMyCouponSuccess
/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Sales/_files/quote.php
* @magentoApiDataFixture Magento/Checkout/_files/discount_10percent_generalusers.php
*/
public function testSetMyCouponSuccess()
{
$this->_markTestAsRestOnly();
// get customer ID token
/** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
$customerTokenService = $this->objectManager->create('Magento\\Integration\\Api\\CustomerTokenServiceInterface');
$token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
$quote->load('test01', 'reserved_order_id');
$cartId = $quote->getId();
/** @var \Magento\SalesRule\Model\Rule $salesRule */
$salesRule = $this->objectManager->create('Magento\\SalesRule\\Model\\Rule');
$salesRuleId = $this->objectManager->get('Magento\\Framework\\Registry')->registry('Magento/Checkout/_file/discount_10percent_generalusers');
$salesRule->load($salesRuleId);
$couponCode = $salesRule->getPrimaryCoupon()->getCode();
/* Since this isn't a full quote fixture, need to assign it to the right customer */
$cartManagementService = $this->objectManager->create('Magento\\Quote\\Api\\CartManagementInterface');
$cartManagementService->assignCustomer($cartId, 1, 1);
$serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . 'mine/coupons/' . $couponCode, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, 'token' => $token]];
$requestData = ["couponCode" => $couponCode];
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
$quoteWithCoupon = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
$quoteWithCoupon->load('test01', 'reserved_order_id');
$this->assertEquals($quoteWithCoupon->getCouponCode(), $couponCode);
}
示例11: testSaveActionExistingCustomerUnsubscribeNewsletter
/**
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
*/
public function testSaveActionExistingCustomerUnsubscribeNewsletter()
{
$customerId = 1;
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
$subscriber = $this->objectManager->get('Magento\\Newsletter\\Model\\SubscriberFactory')->create();
$this->assertEmpty($subscriber->getId());
$subscriber->loadByCustomerId($customerId);
$this->assertNotEmpty($subscriber->getId());
$this->assertEquals(1, $subscriber->getStatus());
$post = ['customer' => ['entity_id' => $customerId], 'subscription' => 'false'];
$this->getRequest()->setPostValue($post);
$this->getRequest()->setParam('id', 1);
$this->dispatch('backend/customer/index/save');
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
$subscriber = $this->objectManager->get('Magento\\Newsletter\\Model\\SubscriberFactory')->create();
$this->assertEmpty($subscriber->getId());
$subscriber->loadByCustomerId($customerId);
$this->assertNotEmpty($subscriber->getId());
$this->assertEquals(3, $subscriber->getStatus());
/**
* Check that success message is set
*/
$this->assertSessionMessages($this->equalTo(['You saved the customer.']), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS);
$this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'index/key/'));
}
示例12: testInlinecssDirectiveThrowsExceptionWhenMissingParameter
/**
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
* @magentoComponentsDir Magento/Email/Model/_files/design
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
* @dataProvider inlinecssDirectiveThrowsExceptionWhenMissingParameterDataProvider
*
* @param string $templateText
*/
public function testInlinecssDirectiveThrowsExceptionWhenMissingParameter($templateText)
{
/** @var \Magento\Theme\Model\Theme\Registration $registration */
$registration = $this->objectManager->get('Magento\\Theme\\Model\\Theme\\Registration');
$registration->register();
$this->setUpDesignParams();
$this->model->filter($templateText);
}
示例13: 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');
/**
* @var $entityMetadata \Magento\Framework\Model\Entity\EntityMetadata
*/
$entityMetadata = $this->objectManager->get(MetadataPool::class)->getMetadata(ProductInterface::class);
$productRepository = $this->objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$linkFieldId = $productRepository->get('simple')->getData($entityMetadata->getLinkField());
$product->setData($entityMetadata->getLinkField(), $linkFieldId);
$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']);
}
示例14: deleteCart
/**
* Delete quote by given reserved order ID
*
* @param string $reservedOrderId
* @return void
*/
protected function deleteCart($reservedOrderId)
{
try {
/** @var $cart \Magento\Quote\Model\Quote */
$cart = $this->objectManager->get('Magento\\Quote\\Model\\Quote');
$cart->load($reservedOrderId, 'reserved_order_id');
if (!$cart->getId()) {
throw new \InvalidArgumentException('There is no quote with provided reserved order ID.');
}
$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
}
}
示例15: testGetTitles
/**
* @magentoDataFixture Magento/Store/_files/store.php
* @magentoDataFixture Magento/Tax/_files/tax_classes.php
*/
public function testGetTitles()
{
/** @var \Magento\Tax\Model\Calculation\Rate $rate */
$rate = $this->_objectManager->create('Magento\\Tax\\Model\\Calculation\\Rate');
$rate->load(1);
/** @var \Magento\Store\Model\Store $store */
$store = $this->_objectManager->get('Magento\\Store\\Model\\Store');
$store->load('test', 'code');
$title = 'title';
$rate->saveTitles([$store->getId() => $title]);
$coreRegistry = $this->_objectManager->create('Magento\\Framework\\Registry');
$coreRegistry->register(RegistryConstants::CURRENT_TAX_RATE_ID, 1);
/** @var \Magento\Tax\Block\Adminhtml\Rate\Title $block */
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Tax\\Block\\Adminhtml\\Rate\\Title', ['coreRegistry' => $coreRegistry]);
$titles = $block->getTitles();
$this->assertArrayHasKey($store->getId(), $titles, 'Store was not created');
$this->assertEquals($title, $titles[$store->getId()], 'Invalid Tax Title');
}