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


PHP ObjectManager\ObjectManager类代码示例

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


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

示例1: methodInjection

 /**
  * @param Object $object
  * @param string $methodName
  */
 public function methodInjection($object, $methodName, ObjectManager $objectManager)
 {
     $parameters = $this->getMethod($object, $methodName);
     $argumentsToInject = [];
     foreach ($parameters as $parameter) {
         $argumentsToInject[] = $objectManager->get($parameter[1]);
     }
     call_user_func_array([$object, $methodName], $argumentsToInject);
 }
开发者ID:ktomk,项目名称:n98-magerun2,代码行数:13,代码来源:InjectionHelper.php

示例2: setUp

 protected function setUp()
 {
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\ManagerInterface', [], [], '', false);
     $this->coreRegistryMock = $this->getMock('\\Magento\\Framework\\Registry', [], [], '', false);
     $this->blockMock = $this->getMockBuilder('Magento\\Cms\\Model\\Block')->disableOriginalConstructor()->getMock();
     $this->objectManagerMock = $this->getMockBuilder('Magento\\Framework\\ObjectManager\\ObjectManager')->setMethods(['create', 'get'])->disableOriginalConstructor()->getMock();
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Block')->willReturn($this->blockMock);
     $this->resultRedirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\RedirectFactory')->disableOriginalConstructor()->getMock();
     $this->resultPageFactoryMock = $this->getMock('Magento\\Framework\\View\\Result\\PageFactory', [], [], '', false);
     $this->requestMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, []);
     $this->contextMock = $this->getMock('\\Magento\\Backend\\App\\Action\\Context', [], [], '', false);
     $this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock);
     $this->contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock);
     $this->contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock);
     $this->contextMock->expects($this->once())->method('getResultRedirectFactory')->willReturn($this->resultRedirectFactoryMock);
     $this->editController = $this->objectManager->getObject('Magento\\Cms\\Controller\\Adminhtml\\Block\\Edit', ['context' => $this->contextMock, 'coreRegistry' => $this->coreRegistryMock, 'resultPageFactory' => $this->resultPageFactoryMock]);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:19,代码来源:EditTest.php

示例3: setUp

 /**
  * Set up
  */
 protected function setUp()
 {
     $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false);
     $this->request->expects($this->any())->method('getParam')->with('filename')->willReturn('filename');
     $this->reportHelper = $this->getMock('Magento\\ImportExport\\Helper\\Report', ['importFileExists', 'getReportSize', 'getReportOutput'], [], '', false);
     $this->reportHelper->expects($this->any())->method('getReportSize')->willReturn(1);
     $this->reportHelper->expects($this->any())->method('getReportOutput')->willReturn('output');
     $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', ['get'], [], '', false);
     $this->objectManager->expects($this->any())->method('get')->with('Magento\\ImportExport\\Helper\\Report')->willReturn($this->reportHelper);
     $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getObjectManager', 'getResultRedirectFactory'], [], '', false);
     $this->fileFactory = $this->getMock('Magento\\Framework\\App\\Response\\Http\\FileFactory', ['create'], [], '', false);
     $this->resultRaw = $this->getMock('Magento\\Framework\\Controller\\Result\\Raw', ['setContents'], [], '', false);
     $this->resultRawFactory = $this->getMock('\\Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false);
     $this->resultRawFactory->expects($this->any())->method('create')->willReturn($this->resultRaw);
     $this->redirect = $this->getMock('\\Magento\\Backend\\Model\\View\\Result\\Redirect', ['setPath'], [], '', false);
     $this->resultRedirectFactory = $this->getMock('Magento\\Framework\\Controller\\Result\\RedirectFactory', ['create'], [], '', false);
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->redirect);
     $this->context->expects($this->any())->method('getRequest')->willReturn($this->request);
     $this->context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManager);
     $this->context->expects($this->any())->method('getResultRedirectFactory')->willReturn($this->resultRedirectFactory);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->downloadController = $this->objectManagerHelper->getObject('Magento\\ImportExport\\Controller\\Adminhtml\\History\\Download', ['context' => $this->context, 'fileFactory' => $this->fileFactory, 'resultRawFactory' => $this->resultRawFactory, 'reportHelper' => $this->reportHelper]);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:26,代码来源:DownloadTest.php

示例4: testCreate

 /**
  * @param $typeId
  * @param $quantity
  * @param $infoClass
  * @param $prices
  * @dataProvider createPriceInfoDataProvider
  */
 public function testCreate($typeId, $quantity, $infoClass, $prices)
 {
     $this->saleableItemMock->expects($this->once())->method('getTypeId')->will($this->returnValue($typeId));
     $this->saleableItemMock->expects($this->once())->method('getQty')->will($this->returnValue($quantity));
     $this->objectManagerMock->expects($this->exactly(2))->method('create')->will($this->returnValueMap([[$prices, ['saleableItem' => $this->saleableItemMock, 'quantity' => $quantity], $this->pricesMock], [$infoClass, ['saleableItem' => $this->saleableItemMock, 'quantity' => $quantity, 'prices' => $this->pricesMock], $this->priceInfoMock]]));
     $this->assertEquals($this->priceInfoMock, $this->factory->create($this->saleableItemMock, []));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:FactoryTest.php

示例5: testCreate

 public function testCreate()
 {
     $adapterClassName = '\\Migration\\Resource\\Adapter\\Mysql';
     $data = ['config' => ['key' => 'value']];
     $adapter = $this->getMock($adapterClassName, [], [], '', false);
     $this->config->expects($this->once())->method('getOption')->with('resource_adapter_class_name')->will($this->returnValue(null));
     $this->objectManager->expects($this->once())->method('create')->with('\\Migration\\Resource\\Adapter\\Mysql', $data)->will($this->returnValue($adapter));
     $this->assertInstanceOf($adapterClassName, $this->adapterFactory->create($data));
 }
开发者ID:okite11,项目名称:frames21,代码行数:9,代码来源:AdapterFactoryTest.php

示例6: testDeleteActionThrowsException

 public function testDeleteActionThrowsException()
 {
     $errorMsg = 'Can\'t delete the page';
     $this->requestMock->expects($this->once())->method('getParam')->willReturn($this->pageId);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Page')->willReturn($this->pageMock);
     $this->pageMock->expects($this->once())->method('load')->with($this->pageId);
     $this->pageMock->expects($this->once())->method('getTitle')->willReturn($this->title);
     $this->pageMock->expects($this->once())->method('delete')->willThrowException(new \Exception(__($errorMsg)));
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('adminhtml_cmspage_on_delete', ['title' => $this->title, 'status' => 'fail']);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMsg);
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/edit', ['page_id' => $this->pageId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->deleteController->execute());
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:14,代码来源:DeleteTest.php

示例7: testEmailNoInvoice

    public function testEmailNoInvoice()
    {
        $invoiceId = 10000031;
        $this->request->expects($this->once())
            ->method('getParam')
            ->with('invoice_id')
            ->willReturn($invoiceId);

        $invoiceRepository = $this->getMockBuilder('Magento\Sales\Api\InvoiceRepositoryInterface')
            ->disableOriginalConstructor()
            ->getMock();
        $invoiceRepository->expects($this->any())
            ->method('get')
            ->willReturn(null);
        $this->objectManager->expects($this->at(0))
            ->method('create')
            ->with('Magento\Sales\Api\InvoiceRepositoryInterface')
            ->willReturn($invoiceRepository);

        $this->resultForwardFactory->expects($this->any())
            ->method('create')
            ->willReturn($this->resultForward);
        $this->resultForward->expects($this->once())
            ->method('forward')
            ->with('noroute')
            ->willReturnSelf();

        $this->assertInstanceOf('Magento\Backend\Model\View\Result\Forward', $this->invoiceEmail->executeInternal());
    }
开发者ID:nblair,项目名称:magescotch,代码行数:29,代码来源:EmailTest.php

示例8: testExecute

 public function testExecute()
 {
     $shipmentId = 1000012;
     $orderId = 10003;
     $tracking = [];
     $shipmentData = ['items' => [], 'send_email' => ''];
     $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', 'register', 'getOrder', 'getOrderId', '__wakeup'], [], '', false);
     $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipmentData], ['tracking', null, $tracking]]));
     $this->shipmentLoader->expects($this->any())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoader->expects($this->any())->method('setOrderId')->with($orderId);
     $this->shipmentLoader->expects($this->any())->method('setShipment')->with($shipmentData);
     $this->shipmentLoader->expects($this->any())->method('setTracking')->with($tracking);
     $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($shipment));
     $this->session->expects($this->once())->method('getCommentText')->with(true)->will($this->returnValue(''));
     $this->objectManager->expects($this->atLeastOnce())->method('get')->with('Magento\\Backend\\Model\\Session')->will($this->returnValue($this->session));
     $this->view->expects($this->once())->method('loadLayout')->will($this->returnSelf());
     $this->view->expects($this->once())->method('renderLayout')->will($this->returnSelf());
     $this->view->expects($this->any())->method('getPage')->willReturn($this->resultPageMock);
     $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->pageTitleMock);
     $layout = $this->getMock('Magento\\Framework\\View\\Layout\\Element\\Layout', ['getBlock'], [], '', false);
     $menuBlock = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface', ['toHtml', 'setActive', 'getMenuModel'], [], '', false);
     $menuModel = $this->getMockBuilder('Magento\\Backend\\Model\\Menu')->disableOriginalConstructor()->getMock();
     $itemId = 'Magento_Sales::sales_order';
     $parents = [new \Magento\Framework\DataObject(['title' => 'title1']), new \Magento\Framework\DataObject(['title' => 'title2']), new \Magento\Framework\DataObject(['title' => 'title3'])];
     $menuModel->expects($this->once())->method('getParentItems')->with($itemId)->will($this->returnValue($parents));
     $menuBlock->expects($this->once())->method('setActive')->with($itemId);
     $menuBlock->expects($this->once())->method('getMenuModel')->will($this->returnValue($menuModel));
     $this->view->expects($this->once())->method('getLayout')->will($this->returnValue($layout));
     $layout->expects($this->once())->method('getBlock')->with('menu')->will($this->returnValue($menuBlock));
     $this->assertNull($this->newAction->execute());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:32,代码来源:NewActionTest.php

示例9: testEmail

    public function testEmail()
    {
        $cmId = 10000031;
        $cmManagement = 'Magento\Sales\Api\CreditmemoManagementInterface';
        $cmManagementMock = $this->getMock($cmManagement, [], [], '', false);
        $this->prepareRedirect($cmId);

        $this->request->expects($this->once())
            ->method('getParam')
            ->with('creditmemo_id')
            ->willReturn($cmId);
        $this->objectManager->expects($this->once())
            ->method('create')
            ->with($cmManagement)
            ->willReturn($cmManagementMock);
        $cmManagementMock->expects($this->once())
            ->method('notify')
            ->willReturn(true);
        $this->messageManager->expects($this->once())
            ->method('addSuccess')
            ->with('You sent the message.');

        $this->assertInstanceOf(
            'Magento\Backend\Model\View\Result\Redirect',
            $this->creditmemoEmail->executeInternal()
        );
        $this->assertEquals($this->response, $this->creditmemoEmail->getResponse());
    }
开发者ID:nblair,项目名称:magescotch,代码行数:28,代码来源:EmailTest.php

示例10: testEmail

 public function testEmail()
 {
     $shipmentId = 1000012;
     $orderId = 10003;
     $tracking = [];
     $shipment = ['items' => []];
     $orderShipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', '__wakeup'], [], '', false);
     $shipmentNotifierClassName = 'Magento\\Shipping\\Model\\ShipmentNotifier';
     $shipmentNotifier = $this->getMock($shipmentNotifierClassName, ['notify', '__wakeup'], [], '', false);
     $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipment], ['tracking', null, $tracking]]));
     $this->shipmentLoader->expects($this->once())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoader->expects($this->once())->method('setOrderId')->with($orderId);
     $this->shipmentLoader->expects($this->once())->method('setShipment')->with($shipment);
     $this->shipmentLoader->expects($this->once())->method('setTracking')->with($tracking);
     $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($orderShipment));
     $orderShipment->expects($this->once())->method('save')->will($this->returnSelf());
     $this->objectManager->expects($this->once())->method('create')->with($shipmentNotifierClassName)->will($this->returnValue($shipmentNotifier));
     $shipmentNotifier->expects($this->once())->method('notify')->with($orderShipment)->will($this->returnValue(true));
     $this->messageManager->expects($this->once())->method('addSuccess')->with('You sent the shipment.');
     $path = '*/*/view';
     $arguments = ['shipment_id' => $shipmentId];
     $this->prepareRedirect($path, $arguments, 0);
     $this->shipmentEmail->execute();
     $this->assertEquals($this->response, $this->shipmentEmail->getResponse());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:25,代码来源:EmailTest.php

示例11: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         /** @var \Magento\Framework\Component\ComponentRegistrar $componentRegistrar */
         $componentRegistrar = $this->objectManager->get('Magento\\Framework\\Component\\ComponentRegistrar');
         /** @var \Magento\Framework\Component\DirSearch $dirSearch */
         $dirSearch = $this->objectManager->get('Magento\\Framework\\Component\\DirSearch');
         /** @var \Magento\Framework\View\Design\Theme\ThemePackageList $themePackageList */
         $themePackageList = $this->objectManager->get('Magento\\Framework\\View\\Design\\Theme\\ThemePackageList');
         Files::setInstance(new Files($componentRegistrar, $dirSearch, $themePackageList));
         $this->buildReport($input->getOption(self::INPUT_KEY_OUTPUT));
         $output->writeln('<info>Report successfully processed.</info>');
     } catch (\Exception $e) {
         $output->writeln('<error>Please check the path you provided. Dependencies report generator failed with error: ' . $e->getMessage() . '</error>');
     }
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:19,代码来源:AbstractDependenciesCommand.php

示例12: testExecuteUpdateAction

 public function testExecuteUpdateAction()
 {
     $orderId = 30;
     $action = 'update';
     $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action);
     $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($this->orderMock);
     $this->orderMock->expects($this->once())->method('load')->with($orderId)->willReturn($this->orderMock);
     $this->orderMock->expects($this->any())->method('getId')->willReturn($orderId);
     $this->orderMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock);
     $this->orderMock->expects($this->once())->method('save')->willReturnSelf();
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with('The payment update has been made.');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
     $this->paymentMock->expects($this->once())->method('update');
     $result = $this->reviewPayment->execute();
     $this->assertEquals($this->resultRedirectMock, $result);
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:18,代码来源:ReviewPaymentTest.php

示例13: testDeleteActionThrowsException

 public function testDeleteActionThrowsException()
 {
     $errorMsg = 'Can\'t create the block';
     $this->requestMock->expects($this->once())->method('getParam')->willReturn($this->blockId);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Block')->willThrowException(new \Exception(__($errorMsg)));
     $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMsg);
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/edit', ['block_id' => $this->blockId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->deleteController->execute());
 }
开发者ID:kid17,项目名称:magento2,代码行数:10,代码来源:DeleteTest.php

示例14: testSaveAction

 public function testSaveAction()
 {
     $userId = 1;
     $requestParams = ['password' => 'password', 'password_confirmation' => true, 'interface_locale' => 'US', 'username' => 'Foo', 'firstname' => 'Bar', 'lastname' => 'Dummy', 'email' => 'test@example.com', \Magento\Backend\Block\System\Account\Edit\Form::IDENTITY_VERIFICATION_PASSWORD_FIELD => 'current_password'];
     $testedMessage = 'The account has been saved.';
     $this->_authSessionMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock));
     $this->_userMock->expects($this->any())->method('load')->will($this->returnSelf());
     $this->_validatorMock->expects($this->once())->method('isValid')->with($this->equalTo($requestParams['interface_locale']))->will($this->returnValue(true));
     $this->_managerMock->expects($this->any())->method('switchBackendInterfaceLocale');
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Auth\\Session'))->will($this->returnValue($this->_authSessionMock));
     $this->_objectManagerMock->expects($this->at(1))->method('create')->with($this->equalTo('Magento\\User\\Model\\User'))->will($this->returnValue($this->_userMock));
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with($this->equalTo('Magento\\Framework\\Locale\\Validator'))->will($this->returnValue($this->_validatorMock));
     $this->_objectManagerMock->expects($this->at(3))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Locale\\Manager'))->will($this->returnValue($this->_managerMock));
     $this->_userMock->setUserId($userId);
     $this->_userMock->expects($this->once())->method('save');
     $this->_userMock->expects($this->once())->method('verifyIdentity')->will($this->returnValue(true));
     $this->_userMock->expects($this->once())->method('sendPasswordResetNotificationEmail');
     $this->_requestMock->setParams($requestParams);
     $this->_messagesMock->expects($this->once())->method('addSuccess')->with($this->equalTo($testedMessage));
     $this->_controller->execute();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:21,代码来源:SaveTest.php

示例15: testEmailNoOrderId

 public function testEmailNoOrderId()
 {
     $orderClassName = 'Magento\\Sales\\Model\\Order';
     $order = $this->getMock($orderClassName, ['load', 'getId', '__wakeup'], [], '', false);
     $this->request->expects($this->once())->method('getParam')->with('order_id')->will($this->returnValue(null));
     $this->objectManager->expects($this->at(0))->method('create')->with($orderClassName)->will($this->returnValue($order));
     $order->expects($this->once())->method('load')->with(null)->will($this->returnSelf());
     $this->messageManager->expects($this->once())->method('addError')->with('This order no longer exists.');
     $this->actionFlag->expects($this->once())->method('set')->with('', 'no-dispatch', true)->will($this->returnValue(true));
     $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->orderEmail->execute());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:EmailTest.php


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