本文整理汇总了PHP中Magento\Framework\ObjectManagerInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManagerInterface类的具体用法?PHP ObjectManagerInterface怎么用?PHP ObjectManagerInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectManagerInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();
$this->dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\Filter\Date')
->disableOriginalConstructor()
->getMock();
$this->helperMock = $this->getMockBuilder('Magento\Backend\Helper\Data')
->disableOriginalConstructor()
->getMock();
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
->disableOriginalConstructor()
->getMock();
$this->objectManagerMock
->expects($this->any())
->method('get')
->willReturn($this->helperMock);
$this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->exportViewedCsv = $objectManager->getObject(
'Magento\Reports\Controller\Adminhtml\Report\Product\ExportViewedCsv',
[
'context' => $this->contextMock,
'fileFactory' => $this->fileFactoryMock,
'dateFilter' => $this->dateMock,
]
);
}
示例2: updateFieldForTable
/**
* Replace {{skin url=""}} with {{view url=""}} for given table field
*
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param string $table
* @param string $col
* @return void
*/
function updateFieldForTable($objectManager, $table, $col)
{
/** @var $installer \Magento\Framework\Setup\ModuleDataSetupInterface */
$installer = $objectManager->create('\\Magento\\Framework\\Setup\\ModuleDataSetupInterface');
$installer->startSetup();
$table = $installer->getTable($table);
echo '-----' . "\n";
if ($installer->getConnection()->isTableExists($table)) {
echo 'Table `' . $table . "` processed\n";
$indexList = $installer->getConnection()->getIndexList($table);
$pkField = array_shift($indexList[$installer->getConnection()->getPrimaryKeyName($table)]['fields']);
/** @var $select \Magento\Framework\DB\Select */
$select = $installer->getConnection()->select()->from($table, ['id' => $pkField, 'content' => $col]);
$result = $installer->getConnection()->fetchPairs($select);
echo 'Records count: ' . count($result) . ' in table: `' . $table . "`\n";
$logMessages = [];
foreach ($result as $recordId => $string) {
$content = str_replace('{{skin', '{{view', $string, $count);
if ($count) {
$installer->getConnection()->update($table, [$col => $content], $installer->getConnection()->quoteInto($pkField . '=?', $recordId));
$logMessages['replaced'][] = 'Replaced -- Id: ' . $recordId . ' in table `' . $table . '`';
} else {
$logMessages['skipped'][] = 'Skipped -- Id: ' . $recordId . ' in table `' . $table . '`';
}
}
if (count($result)) {
printLog($logMessages);
}
} else {
echo 'Table `' . $table . "` was not found\n";
}
$installer->endSetup();
echo '-----' . "\n";
}
示例3: testExecute
public function testExecute()
{
$this->objectManager->expects($this->once())
->method('get')
->with('Magento\Framework\App\Cache')
->willReturn($this->cacheMock);
$this->cacheMock->expects($this->once())->method('clean');
$writeDirectory = $this->getMock('Magento\Framework\Filesystem\Directory\WriteInterface');
$writeDirectory->expects($this->atLeastOnce())->method('delete');
$this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
$progressBar = $this->getMockBuilder(
'Symfony\Component\Console\Helper\ProgressBar'
)
->disableOriginalConstructor()
->getMock();
$this->objectManager->expects($this->once())->method('configure');
$this->objectManager
->expects($this->once())
->method('create')
->with('Symfony\Component\Console\Helper\ProgressBar')
->willReturn($progressBar);
$this->manager->expects($this->exactly(6))->method('addOperation');
$this->manager->expects($this->once())->method('process');
$tester = new CommandTester($this->command);
$tester->execute([]);
$this->assertContains(
'Generated code and dependency injection configuration successfully.',
explode(PHP_EOL, $tester->getDisplay())
);
}
示例4: _getSubject
/**
* Get proxied instance
*
* @return \Magento\Framework\Stdlib\DateTime\DateTime
*/
protected function _getSubject()
{
if (!$this->_subject) {
$this->_subject = true === $this->_isShared ? $this->_objectManager->get($this->_instanceName) : $this->_objectManager->create($this->_instanceName);
}
return $this->_subject;
}
示例5: testUnloginAction
/**
* @covers \Magento\Setup\Controller\Session::testUnloginAction
*/
public function testUnloginAction()
{
$deployConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', ['isAvailable'], [], '', false);
$deployConfigMock->expects($this->once())->method('isAvailable')->will($this->returnValue(true));
$stateMock = $this->getMock('Magento\Framework\App\State', ['setAreaCode'], [], '', false);
$stateMock->expects($this->once())->method('setAreaCode');
$sessionConfigMock =
$this->getMock('Magento\Backend\Model\Session\AdminConfig', ['setCookiePath'], [], '', false);
$sessionConfigMock->expects($this->once())->method('setCookiePath');
$returnValueMap = [
['Magento\Framework\App\DeploymentConfig', $deployConfigMock],
['Magento\Framework\App\State', $stateMock],
['Magento\Backend\Model\Session\AdminConfig', $sessionConfigMock]
];
$this->objectManager->expects($this->atLeastOnce())
->method('get')
->will($this->returnValueMap($returnValueMap));
$sessionMock = $this->getMock('Magento\Backend\Model\Auth\Session', ['prolong'], [], '', false);
$this->objectManager->expects($this->once())
->method('create')
->will($this->returnValue($sessionMock));
$controller = new Session($this->objectManagerProvider);
$controller->prolongAction();
}
示例6: exceptionResponse
/**
* Processing section runtime errors
*
* @return void
*/
protected function exceptionResponse()
{
$dataMock = $this->getMock('Magento\\Framework\\Json\\Helper\\Data', ['jsonEncode'], [], '', false);
$this->objectManagerMock->expects($this->once())->method('get')->will($this->returnValue($dataMock));
$dataMock->expects($this->once())->method('jsonEncode')->will($this->returnValue('{json-data}'));
$this->responseMock->expects($this->once())->method('representJson')->with('{json-data}');
}
示例7: setUp
/**
* Set up
*/
public function setUp()
{
$this->objectManager = Bootstrap::getObjectManager();
$this->accountManagement = $this->objectManager->create('Magento\\Customer\\Api\\AccountManagementInterface');
$this->securityManager = $this->objectManager->create('Magento\\Security\\Model\\SecurityManager');
$this->passwordResetRequestEvent = $this->objectManager->get('Magento\\Security\\Model\\PasswordResetRequestEvent');
}
示例8: create
/**
* Create link builder instance
*
* @param string $instance
* @param array $arguments
* @return CopyConstructorInterface
* @throws \InvalidArgumentException
*/
public function create($instance, array $arguments = [])
{
if (!is_subclass_of($instance, '\\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface')) {
throw new \InvalidArgumentException($instance . ' does not implement \\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface');
}
return $this->objectManager->create($instance, $arguments);
}
示例9: setUp
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->groupRepository = $this->objectManager->create('Magento\\Customer\\Api\\GroupRepositoryInterface');
$this->groupFactory = $this->objectManager->create('Magento\\Customer\\Api\\Data\\GroupInterfaceFactory');
$this->searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
}
示例10: testCreate
public function testCreate()
{
$this->objectManagerProvider->expects($this->once())->method('get')->willReturn($this->objectManager);
$this->objectManager->expects($this->once())->method('get')->with('Magento\\Framework\\Module\\Status');
$this->moduleStatusFactory = new ModuleStatusFactory($this->objectManagerProvider);
$this->moduleStatusFactory->create();
}
示例11: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/* parse arguments */
$argIds = $input->getArgument(static::ARG_IDS);
if (is_null($argIds)) {
$ids = null;
$output->writeln('<info>List of all products will be pulled from Odoo.<info>');
} else {
$ids = explode(',', $argIds);
$output->writeln("<info>Products with Odoo IDs ({$argIds}) will be pulled from Odoo.<info>");
}
/* setup session */
$this->_setAreaCode();
/* call service operation */
/** @var ProductsFromOdooRequest $req */
$req = $this->_manObj->create(ProductsFromOdooRequest::class);
$req->setOdooIds($ids);
/** @var ProductsFromOdooResponse $resp */
$resp = $this->_callReplicate->productsFromOdoo($req);
if ($resp->isSucceed()) {
$output->writeln('<info>Replication is done.<info>');
} else {
$output->writeln('<info>Replication is failed.<info>');
}
}
示例12: getReport
/**
* @param string $requestName
* @return AbstractCollection
* @throws \Exception
*/
public function getReport($requestName)
{
if (!isset($this->collections[$requestName])) {
throw new \Exception(sprintf('Not registered handle %s', $requestName));
}
return $this->objectManager->create($this->collections[$requestName]);
}
示例13: _getSubject
/**
* Retrieve subject
*
* @return \Magento\Config\Model\Config\Structure\SearchInterface
*/
protected function _getSubject()
{
if (!$this->_subject) {
$this->_subject = $this->_objectManager->get('Magento\\Config\\Model\\Config\\Structure');
}
return $this->_subject;
}
示例14: create
/**
* @return \Magento\Framework\View\Result\Layout
*/
public function create()
{
/** @var \Magento\Framework\View\Result\Layout $resultLayout */
$resultLayout = $this->objectManager->create($this->instanceName);
$resultLayout->addDefaultHandle();
return $resultLayout;
}
示例15: get
/**
* Retrieve indexer instance by id
*
* @param string $indexerId
* @return IndexerInterface
*/
public function get($indexerId)
{
if (!isset($this->indexers[$indexerId])) {
$this->indexers[$indexerId] = $this->objectManager->create('Magento\\Indexer\\Model\\IndexerInterface')->load($indexerId);
}
return $this->indexers[$indexerId];
}