本文整理汇总了PHP中Magento\Framework\App\ObjectManager::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::expects方法的具体用法?PHP ObjectManager::expects怎么用?PHP ObjectManager::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::expects方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->context = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false, false);
$this->orderCollectionFactory = $this->getMockBuilder('Magento\\Sales\\Model\\ResourceModel\\Order\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
$this->orderCollectionFactoryInterface = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
$this->objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class, [], [], '', false);
$this->objectManager->expects($this->any())->method('get')->will($this->returnValue($this->orderCollectionFactoryInterface));
\Magento\Framework\App\ObjectManager::setInstance($this->objectManager);
$this->customerSession = $this->getMockBuilder('Magento\\Customer\\Model\\Session')->setMethods(['getCustomerId'])->disableOriginalConstructor()->getMock();
$this->orderConfig = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Config')->setMethods(['getVisibleOnFrontStatuses'])->disableOriginalConstructor()->getMock();
$this->pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
$this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
}
示例2: testExecute
public function testExecute()
{
$mutableConfig = $this->getMock('Magento\\Framework\\App\\Config\\MutableScopeConfigInterface', [], [], '', false);
$logFactory = $this->getMockBuilder('Magento\\Log\\Model\\LogFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
$returnValueMap = [['Magento\\Framework\\App\\Config\\MutableScopeConfigInterface', [], $mutableConfig], ['Magento\\Log\\Model\\LogFactory', [], $logFactory]];
$this->objectManager->expects($this->exactly(2))->method('create')->will($this->returnValueMap($returnValueMap));
$mutableConfig->expects($this->once())->method('setValue');
$log = $this->getMock('Magento\\Log\\Model\\Log', [], [], '', false);
$logFactory->expects($this->once())->method('create')->willReturn($log);
$log->expects($this->once())->method('clean');
$this->commandTester->execute(['--days' => '1']);
$this->assertEquals('Log cleaned.' . PHP_EOL, $this->commandTester->getDisplay());
}
示例3: testDispatchRunJob
/**
* Test case, successfully run job
*/
public function testDispatchRunJob()
{
require_once __DIR__ . '/CronJob.php';
$testCronJob = new \Magento\Cron\Model\CronJob();
$jobConfig = ['test_group' => ['test_job1' => ['instance' => 'CronJob', 'method' => 'execute']]];
$scheduleMethods = ['getJobCode', 'tryLockJob', 'getScheduledAt', 'save', 'setStatus', 'setMessages', 'setExecutedAt', 'setFinishedAt', '__wakeup'];
$schedule = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->setMethods($scheduleMethods)->disableOriginalConstructor()->getMock();
$schedule->expects($this->any())->method('getJobCode')->will($this->returnValue('test_job1'));
$schedule->expects($this->once())->method('getScheduledAt')->will($this->returnValue('-1 day'));
$schedule->expects($this->once())->method('tryLockJob')->will($this->returnValue(true));
// cron start to execute some job
$schedule->expects($this->any())->method('setExecutedAt')->will($this->returnSelf());
$schedule->expects($this->at(5))->method('save');
// cron end execute some job
$schedule->expects($this->at(6))->method('setStatus')->with($this->equalTo(\Magento\Cron\Model\Schedule::STATUS_SUCCESS))->will($this->returnSelf());
$schedule->expects($this->at(8))->method('save');
$this->_collection->addItem($schedule);
$this->_config->expects($this->once())->method('getJobs')->will($this->returnValue($jobConfig));
$lastRun = time() + 10000000;
$this->_cache->expects($this->any())->method('load')->will($this->returnValue($lastRun));
$this->_scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue(strtotime('+1 day')));
$scheduleMock = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->disableOriginalConstructor()->getMock();
$scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection));
$this->_scheduleFactory->expects($this->once())->method('create')->will($this->returnValue($scheduleMock));
$this->_objectManager->expects($this->once())->method('create')->with($this->equalTo('CronJob'))->will($this->returnValue($testCronJob));
$this->_observer->dispatch('');
$this->assertInstanceOf('Magento\\Cron\\Model\\Schedule', $testCronJob->getParam());
}
示例4: testExecuteAddSuccessCriticalException
/**
* Test execute add success critical exception
*
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExecuteAddSuccessCriticalException()
{
$wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
$product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
$item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
$helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
$logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false);
$exception = new \Exception();
$logger->expects($this->once())->method('critical')->with($exception)->willReturn(true);
$helper->expects($this->exactly(2))->method('calculate')->willReturn(true);
$wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item);
$wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf();
$wishlist->expects($this->once())->method('save')->willReturn(null);
$wishlist->expects($this->once())->method('getId')->willReturn(56);
$product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
$product->expects($this->once())->method('getName')->willReturn('Test name');
$this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2);
$this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3);
$this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product);
$item->expects($this->once())->method('load')->with(3)->willReturnSelf();
$item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12);
$this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist);
$this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
$this->request->expects($this->once())->method('getParams')->willReturn([]);
$this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
$this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
$this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger);
$this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true);
$this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception);
$this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true);
$this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf();
$this->assertSame($this->resultRedirectMock, $this->getController()->execute());
}
示例5: testNewsletterAction
public function testNewsletterAction()
{
$subscriberMock = $this->getMock('\\Magento\\Newsletter\\Model\\Subscriber', array(), array(), '', false);
$subscriberMock->expects($this->once())->method('loadByCustomerId');
$this->_objectManager->expects($this->at(1))->method('create')->with('Magento\\Newsletter\\Model\\Subscriber')->will($this->returnValue($subscriberMock));
$this->_testedObject->execute();
}
示例6: testIndexAction
/**
* @param array $expected
* @param $withSampleData
*
* @dataProvider indexActionDataProvider
*/
public function testIndexAction($expected, $withSampleData)
{
if ($withSampleData) {
$this->moduleList->expects($this->once())->method('has')->willReturn(true);
$this->objectManager->expects($this->once())->method('get')->willReturn($this->sampleDataState);
$this->sampleDataState->expects($this->once())->method('isInstalled')->willReturn($expected['isSampleDataInstalled']);
$this->sampleDataState->expects($this->once())->method('hasError')->willReturn($expected['isSampleDataErrorInstallation']);
} else {
$this->moduleList->expects($this->once())->method('has')->willReturn(false);
$this->objectManager->expects($this->never())->method('get');
}
$this->lists->expects($this->once())->method('getTimezoneList')->willReturn($expected['timezone']);
$this->lists->expects($this->once())->method('getCurrencyList')->willReturn($expected['currency']);
$this->lists->expects($this->once())->method('getLocaleList')->willReturn($expected['language']);
$viewModel = $this->controller->indexAction();
$this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $viewModel);
$this->assertTrue($viewModel->terminate());
$variables = $viewModel->getVariables();
$this->assertArrayHasKey('timezone', $variables);
$this->assertArrayHasKey('currency', $variables);
$this->assertArrayHasKey('language', $variables);
$this->assertSame($expected, $variables);
}
示例7: testExecuteCanNotSaveWishlistAndWithRedirect
public function testExecuteCanNotSaveWishlistAndWithRedirect()
{
$referer = 'http://referer-url.com';
$exception = new \Exception('Message');
$wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
$wishlist->expects($this->once())->method('save')->willThrowException($exception);
$this->wishlistProvider->expects($this->once())->method('getWishlist')->with(2)->willReturn($wishlist);
$this->messageManager->expects($this->once())->method('addError')->with('An error occurred while deleting the item from wish list.')->willReturn(true);
$wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
$wishlistHelper->expects($this->once())->method('calculate')->willReturnSelf();
$this->om->expects($this->once())->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper));
$item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
$item->expects($this->once())->method('load')->with(1)->willReturnSelf();
$item->expects($this->once())->method('getId')->willReturn(1);
$item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(2);
$item->expects($this->once())->method('delete')->willReturn(true);
$this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
$this->request->expects($this->once())->method('getServer')->with('HTTP_REFERER')->willReturn($referer);
$this->request->expects($this->exactly(3))->method('getParam')->willReturnMap([['item', null, 1], ['referer_url', null, $referer], ['uenc', null, false]]);
$this->url->expects($this->once())->method('getUrl')->with('*/*')->willReturn('http:/test.com/frontname/module/controller/action');
$this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('http:/test.com/frontname/module/controller/action');
$this->response->expects($this->once())->method('setRedirect')->with('http:/test.com/frontname/module/controller/action')->willReturn(true);
$this->getController()->execute();
}
示例8: testGetResourceCached
public function testGetResourceCached()
{
$this->objectManagerMock->expects($this->never())->method('create');
$this->uut->getResource();
}
示例9: testCreateWithException
/**
* @expectedException \InvalidArgumentException
*/
public function testCreateWithException()
{
$this->objectManagerMock->expects($this->once())->method('create')->willReturn(null);
$this->model->create('');
}