本文整理汇总了PHP中Magento\Eav\Model\Entity\Attribute\AbstractAttribute::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractAttribute::expects方法的具体用法?PHP AbstractAttribute::expects怎么用?PHP AbstractAttribute::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Entity\Attribute\AbstractAttribute
的用法示例。
在下文中一共展示了AbstractAttribute::expects方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBuild
/**
* @param array $data
* @param array $expected
* @dataProvider buildDataProvider
*/
public function testBuild($attributeInputType, $validateRules, $data, $expected)
{
$this->attributeMock->expects($this->once())->method('getFrontendInput')->willReturn($attributeInputType);
$this->attributeMock->expects($this->any())->method('getValidateRules')->willReturn($validateRules);
$validationRules = $this->subject->build($this->attributeMock, $data);
$this->assertEquals($expected, $validationRules);
}
示例2: testBeforeSave
public function testBeforeSave()
{
$this->attributeMock->expects($this->any())->method('getName')->willReturn('attribute_name');
$object = new DataObject(['use_config_attribute_name' => true]);
$this->model->beforeSave($object);
$this->assertEquals(BooleanSource::VALUE_USE_CONFIG, $object->getData('attribute_name'));
}
示例3: testLock
/**
* @covers \Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker::lock
*/
public function testLock()
{
$lockedFields = ['is_searchable' => 'is_searchable', 'is_filterable' => 'is_filterable'];
$this->attributeMock->expects($this->once())->method('getId')->willReturn(1);
$this->attributeConfigMock->expects($this->once())->method('getLockedFields')->willReturn($lockedFields);
$elementMock = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement')->setMethods(['setDisabled', 'setReadonly'])->disableOriginalConstructor()->getMockForAbstractClass();
$elementMock->expects($this->exactly(2))->method('setDisabled');
$elementMock->expects($this->exactly(2))->method('setReadonly');
$this->formMock->expects($this->exactly(2))->method('getElement')->willReturn($elementMock);
$this->object->lock($this->formMock);
}
示例4: testValidateValue
/**
* @param string $value to assign to boolean
* @param bool $expected text output
* @param string $countryId
* @param bool $isOptional
*
* @dataProvider validateValueDataProvider
*/
public function testValidateValue($value, $expected, $countryId, $isOptional)
{
$storeLabel = 'Zip/Postal Code';
$this->attributeMock->expects($this->once())->method('getStoreLabel')->willReturn($storeLabel);
$this->directoryHelperMock->expects($this->once())->method('isZipCodeOptional')->willReturnMap([[$countryId, $isOptional]]);
$object = new \Magento\Customer\Model\Attribute\Data\Postcode($this->localeMock, $this->loggerMock, $this->localeResolverMock, $this->directoryHelperMock);
$object->setAttribute($this->attributeMock);
$object->setExtractedData(['country_id' => $countryId]);
$actual = $object->validateValue($value);
$this->assertEquals($expected, $actual);
}
示例5: testValidateDefaultSortException
/**
* @param $attributeCode
* @param $data
* @dataProvider validateDefaultSortException
* @expectedException \Magento\Framework\Exception\LocalizedException
*/
public function testValidateDefaultSortException($attributeCode, $data)
{
$this->_attribute->expects($this->any())->method('getName')->will($this->returnValue($attributeCode));
$this->_scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue('another value'));
$object = new \Magento\Framework\DataObject($data);
$this->_model->validate($object);
}
示例6: setUp
/**
* Set up test
*
* @return void
*/
protected function setUp()
{
$this->resource = $this->getMock('Magento\\Framework\\App\\Resource', ['getConnection', 'getTableName'], [], '', false);
$this->ruleCollectionFactory = $this->getMock('Magento\\CatalogRule\\Model\\Resource\\Rule\\CollectionFactory', ['create', 'addFieldToFilter'], [], '', false);
$this->backend = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', [], [], '', false);
$this->select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
$this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
$this->db = $this->getMock('Zend_Db_Statement_Interface', [], [], '', false);
$this->website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
$this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false);
$this->combine = $this->getMock('Magento\\Rule\\Model\\Condition\\Combine', [], [], '', false);
$this->rules = $this->getMock('Magento\\CatalogRule\\Model\\Rule', [], [], '', false);
$this->logger = $this->getMock('Psr\\Log\\LoggerInterface', [], [], '', false);
$this->attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], [], '', false);
$this->priceCurrency = $this->getMock('Magento\\Framework\\Pricing\\PriceCurrencyInterface');
$this->dateFormat = $this->getMock('Magento\\Framework\\Stdlib\\DateTime', [], [], '', false);
$this->dateTime = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateTime', [], [], '', false);
$this->eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
$this->product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
$this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
$this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
$this->connection->expects($this->any())->method('query')->will($this->returnValue($this->db));
$this->select->expects($this->any())->method('distinct')->will($this->returnSelf());
$this->select->expects($this->any())->method('where')->will($this->returnSelf());
$this->select->expects($this->any())->method('from')->will($this->returnSelf());
$this->select->expects($this->any())->method('order')->will($this->returnSelf());
$this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
$this->resource->expects($this->any())->method('getTableName')->will($this->returnArgument(0));
$this->storeManager->expects($this->any())->method('getWebsites')->will($this->returnValue([$this->website]));
$this->storeManager->expects($this->any())->method('getWebsite')->will($this->returnValue($this->website));
$this->rules->expects($this->any())->method('getId')->will($this->returnValue(1));
$this->rules->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
$this->rules->expects($this->any())->method('getConditions')->will($this->returnValue($this->combine));
$this->rules->expects($this->any())->method('getCustomerGroupIds')->will($this->returnValue([1]));
$this->ruleCollectionFactory->expects($this->any())->method('create')->will($this->returnSelf());
$this->ruleCollectionFactory->expects($this->any())->method('addFieldToFilter')->will($this->returnValue([$this->rules]));
$this->product->expects($this->any())->method('load')->will($this->returnSelf());
$this->product->expects($this->any())->method('getId')->will($this->returnValue(1));
$this->product->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
$this->combine->expects($this->any())->method('validate')->will($this->returnValue(true));
$this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
$this->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->attribute));
$this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
$this->indexBuilder = new \Magento\CatalogRule\Model\Indexer\IndexBuilder($this->ruleCollectionFactory, $this->priceCurrency, $this->resource, $this->storeManager, $this->logger, $this->eavConfig, $this->dateFormat, $this->dateTime, $this->productFactory);
}
示例7: setUp
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @return void
*/
protected function setUp()
{
$this->zendDbMock = $this->getMockBuilder('Zend_Db_Statement_Interface')->getMock();
$this->zendDbMock->expects($this->any())->method('fetchColumn')->willReturn([]);
$this->selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'where', 'joinInner', 'joinLeft', 'having', 'useStraightJoin', 'insertFromSelect', '__toString'])->getMock();
$this->selectMock->expects($this->any())->method('from')->willReturnSelf();
$this->selectMock->expects($this->any())->method('where')->willReturnSelf();
$this->selectMock->expects($this->any())->method('joinInner')->willReturnSelf();
$this->selectMock->expects($this->any())->method('joinLeft')->willReturnSelf();
$this->selectMock->expects($this->any())->method('having')->willReturnSelf();
$this->selectMock->expects($this->any())->method('useStraightJoin')->willReturnSelf();
$this->selectMock->expects($this->any())->method('insertFromSelect')->willReturnSelf();
$this->selectMock->expects($this->any())->method('__toString')->willReturn('string');
$this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock();
$this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock);
$this->connectionMock->expects($this->any())->method('query')->willReturn($this->zendDbMock);
$this->resourceMock = $this->getMockBuilder('Magento\\Framework\\App\\Resource')->disableOriginalConstructor()->getMock();
$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
$this->resourceMock->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($arg) {
return $arg;
}));
$this->contextMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\Context')->disableOriginalConstructor()->getMock();
$this->contextMock->expects($this->any())->method('getResources')->willReturn($this->resourceMock);
$this->loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();
$dateTime = $this->getMockBuilder('DateTime')->getMock();
$this->timezoneMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getMock();
$this->timezoneMock->expects($this->any())->method('scopeDate')->willReturn($dateTime);
$this->dateTimeMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->getMock();
$this->flagMock = $this->getMockBuilder('Magento\\Reports\\Model\\Flag')->disableOriginalConstructor()->setMethods(['setReportFlagCode', 'unsetData', 'loadSelf', 'setFlagData', 'setLastUpdate', 'save'])->getMock();
$this->flagFactoryMock = $this->getMockBuilder('Magento\\Reports\\Model\\FlagFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
$this->flagFactoryMock->expects($this->any())->method('create')->willReturn($this->flagMock);
$this->validatorMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\Timezone\\Validator')->disableOriginalConstructor()->getMock();
$this->backendMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend')->disableOriginalConstructor()->getMock();
$this->attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->getMock();
$this->attributeMock->expects($this->any())->method('getBackend')->willReturn($this->backendMock);
$this->productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product')->disableOriginalConstructor()->getMock();
$this->productMock->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock);
$this->helperMock = $this->getMockBuilder('Magento\\Reports\\Model\\Resource\\Helper')->disableOriginalConstructor()->getMock();
$this->viewed = new Viewed($this->contextMock, $this->loggerMock, $this->timezoneMock, $this->flagFactoryMock, $this->dateTimeMock, $this->validatorMock, $this->productMock, $this->helperMock);
}
示例8: testProcessNotStaticAttribute
public function testProcessNotStaticAttribute()
{
$expectedResult = 'search_index.entity_id IN (select entity_id from (TEST QUERY PART) as filter)';
$scopeId = 0;
$isNegation = false;
$query = 'SELECT field FROM table';
$attributeId = 1234567;
$this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId));
$this->filter->expects($this->exactly(4))->method('getField')->will($this->returnValue('not_static_attribute'));
$this->config->expects($this->exactly(1))->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, 'not_static_attribute')->will($this->returnValue($this->attribute));
$this->attribute->expects($this->once())->method('isStatic')->will($this->returnValue(false));
$this->attribute->expects($this->once())->method('getBackendTable')->will($this->returnValue('backend_table'));
$this->attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue($attributeId));
$this->connection->expects($this->once())->method('getIfNullSql')->with('current_store.value', 'main_table.value')->will($this->returnValue('IF NULL SQL'));
$this->select->expects($this->once())->method('from')->with(['main_table' => 'backend_table'], 'entity_id')->will($this->returnSelf());
$this->select->expects($this->once())->method('joinLeft')->with(['current_store' => 'backend_table'])->will($this->returnSelf());
$this->select->expects($this->once())->method('columns')->with(['not_static_attribute' => 'IF NULL SQL'])->will($this->returnSelf());
$this->select->expects($this->exactly(2))->method('where')->will($this->returnSelf());
$this->select->expects($this->once())->method('__toString')->will($this->returnValue('TEST QUERY PART'));
$actualResult = $this->target->process($this->filter, $isNegation, $query);
$this->assertSame($expectedResult, $this->removeWhitespaces($actualResult));
}