本文整理汇总了PHP中PHPUnit_Framework_MockObject_MockObject::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_MockObject_MockObject::setData方法的具体用法?PHP PHPUnit_Framework_MockObject_MockObject::setData怎么用?PHP PHPUnit_Framework_MockObject_MockObject::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_MockObject_MockObject
的用法示例。
在下文中一共展示了PHPUnit_Framework_MockObject_MockObject::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetShippingDataObject
/**
* @param array $addressData
* @param bool $useBaseCurrency
* @param string $shippingTaxClass
* @param bool shippingPriceInclTax
* @param array $expectedValue
* @dataProvider getShippingDataObjectDataProvider
*/
public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
{
$baseShippingAmount = $addressData['base_shipping_amount'];
$shippingAmount = $addressData['shipping_amount'];
$itemMock = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterface');
$this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
$this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
$this->address->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
if ($shippingAmount) {
if ($useBaseCurrency && $shippingAmount != 0) {
$this->address->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
$this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($baseShippingAmount);
} else {
$this->address->expects($this->never())->method('getBaseShippingDiscountAmount');
$this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($shippingAmount);
}
}
foreach ($addressData as $key => $value) {
$this->address->setData($key, $value);
}
$this->taxClassKeyBuilderMock->expects($this->any())->method('setType')->willReturnSelf();
$this->taxClassKeyBuilderMock->expects($this->any())->method('setValue')->with($shippingTaxClass)->willReturnSelf();
$this->quoteDetailsItemBuilderMock->expects($this->once())->method('create')->willReturn($itemMock);
$this->assertEquals($itemMock, $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency));
}
示例2: testValidateArrayOperatorType
/**
* @param $existingValue
* @param $operator
* @param $valueForValidate
* @param $expectedResult
* @param $inputType
*
* @dataProvider validateAttributeArrayInputTypeDataProvider
*/
public function testValidateArrayOperatorType($existingValue, $operator, $valueForValidate, $expectedResult, $inputType)
{
$this->_condition->setOperator($operator);
$this->_condition->setData('value_parsed', $existingValue);
$this->_condition->getDefaultOperatorInputByType();
$this->_condition->expects($this->any())->method('getInputType')->will($this->returnValue($inputType));
$this->assertEquals($expectedResult, $this->_condition->validateAttribute($valueForValidate), "Failed asserting that " . var_export($existingValue, true) . $operator . var_export($valueForValidate, true));
}
示例3: testGetInfoData
/**
* @dataProvider getInfoDataProvider
*/
public function testGetInfoData($field, $value, $expected)
{
$methodInstance = $this->getMockBuilder('\\Magento\\Payment\\Model\\Method\\AbstractMethod')->setMethods(['getData'])->disableOriginalConstructor()->getMock();
$methodInstance->expects($this->any())->method('getData')->with($field)->will($this->returnValue($value));
$method = $this->getMockBuilder('Magento\\Payment\\Model\\MethodInterface')->getMockForAbstractClass();
$method->expects($this->any())->method('getInfoInstance')->will($this->returnValue($methodInstance));
$this->_object->setData('method', $method);
$this->assertEquals($expected, $this->_object->getInfoData($field));
}
示例4: testJsonEncode_EncodesData
public function testJsonEncode_EncodesData()
{
$testData = 'something something 123';
$testType = 'testType';
$expected = json_encode(['type' => $testType, 'data' => $testData]);
$this->abstractCommand->expects($this->once())->method('getType')->willReturn('testType');
$this->abstractCommand->setData($testData);
$this->assertJsonStringEqualsJsonString($expected, json_encode($this->abstractCommand));
}
示例5: testValidate
/**
* @dataProvider validateDataProvider
* @param bool $value
*/
public function testValidate($value)
{
$attributeCode = 'attr_code';
$attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute', ['getAttributeCode', 'getIsRequired', 'isValueEmpty', 'getIsUnique', 'getEntityType', '__wakeup'], [], '', false);
$attributeEntity = $this->getMock('\\Magento\\Framework\\Model\\ResourceModel\\AbstractResourceAbstractEntity', ['checkAttributeUniqueValue']);
$attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
$attribute->expects($this->any())->method('getIsRequired')->will($this->returnValue(true));
$attribute->expects($this->any())->method('isValueEmpty')->will($this->returnValue($value));
$attribute->expects($this->any())->method('getIsUnique')->will($this->returnValue(true));
$attribute->expects($this->any())->method('getEntityType')->will($this->returnValue($attributeEntity));
$attributeEntity->expects($this->any())->method('checkAttributeUniqueValue')->will($this->returnValue(true));
$this->attributeRepository->expects($this->once())->method('get')->with('media_gallery')->willReturn($attribute);
$this->dataObject->setData(['attr_code' => 'attribute data']);
$this->assertEquals(!$value, $this->model->validate($this->dataObject));
}
示例6: testGetIsSecureMode
/**
* @dataProvider getIsSecureModeDataProvider
* @param bool $isSecureMode
* @param bool $methodInstance
* @param bool $store
* @param string $storeCode
* @param bool $expectedResult
*/
public function testGetIsSecureMode($isSecureMode, $methodInstance, $store, $storeCode, $expectedResult)
{
if (isset($store)) {
$methodInstance = $this->_getMethodInstanceMock($store);
}
if (isset($storeCode)) {
$storeMock = $this->_getStoreMock($storeCode);
$this->_storeManager->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
}
$paymentInfo = $this->getMockBuilder('\\Magento\\Payment\\Model\\Info')->disableOriginalConstructor()->getMock();
$paymentInfo->expects($this->any())->method('getMethodInstance')->will($this->returnValue($methodInstance));
$this->_object->setData('info', $paymentInfo);
$this->_object->setData('is_secure_mode', $isSecureMode);
$result = $this->_object->getIsSecureMode();
$this->assertEquals($result, $expectedResult);
}
示例7: testSaveValidation
/**
* @param array $badStoreData
*
* @dataProvider saveValidationDataProvider
* @magentoAppIsolation enabled
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
* @expectedException \Magento\Framework\Exception\LocalizedException
*/
public function testSaveValidation($badStoreData)
{
$normalStoreData = ['code' => 'test', 'website_id' => 1, 'group_id' => 1, 'name' => 'test name', 'sort_order' => 0, 'is_active' => 1];
$data = array_merge($normalStoreData, $badStoreData);
$this->model->setData($data);
$this->model->save();
}
示例8: testPrepareValueOptions
/**
* @param array $setData
* @param string $attributeObjectFrontendInput
* @param array $attrObjectSourceAllOptionsValue
* @param array $attrSetCollectionOptionsArray
* @param bool $expectedAttrObjSourceAllOptionsParam
* @param array $expectedValueSelectOptions
* @param array $expectedValueOption
* @dataProvider prepareValueOptionsDataProvider
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function testPrepareValueOptions($setData, $attributeObjectFrontendInput, $attrObjectSourceAllOptionsValue, $attrSetCollectionOptionsArray, $expectedAttrObjSourceAllOptionsParam, $expectedValueSelectOptions, $expectedValueOption)
{
foreach ($setData as $key => $value) {
$this->_condition->setData($key, $value);
}
$attrObjectSourceMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource')->setMethods(['getAllOptions'])->disableOriginalConstructor()->getMock();
$attrObjectSourceMock->expects(null === $expectedAttrObjSourceAllOptionsParam ? $this->never() : $this->once())->method('getAllOptions')->with($expectedAttrObjSourceAllOptionsParam)->willReturn($attrObjectSourceAllOptionsValue);
$attributeObjectMock = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->setMethods(['usesSource', 'getFrontendInput', 'getSource', 'getAllOptions'])->disableOriginalConstructor()->getMock();
$attributeObjectMock->method('usesSource')->willReturn(true);
$attributeObjectMock->expects(null === $attributeObjectFrontendInput ? $this->never() : $this->once())->method('getFrontendInput')->willReturn($attributeObjectFrontendInput);
$attributeObjectMock->method('getSource')->willReturn($attrObjectSourceMock);
$entityTypeMock = $this->getMockBuilder('Magento\\Framework\\Model\\AbstractModel\\Type')->setMethods(['getId'])->disableOriginalConstructor()->getMock();
$entityTypeMock->method('getId')->willReturn('SomeEntityType');
$configValueMock = $this->getMock('Magento\\Eav\\Model\\Config', ['getAttribute', 'getEntityType'], [], '', false);
$configValueMock->method('getAttribute')->willReturn($attributeObjectMock);
$configValueMock->method('getEntityType')->willReturn($entityTypeMock);
$configProperty = new ReflectionProperty('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_config');
$configProperty->setAccessible(true);
$configProperty->setValue($this->_condition, $configValueMock);
$attrSetCollectionValueMock = $this->getMockBuilder('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection')->setMethods(['setEntityTypeFilter', 'load', 'toOptionArray'])->disableOriginalConstructor()->getMock();
$attrSetCollectionValueMock->method('setEntityTypeFilter')->will($this->returnSelf());
$attrSetCollectionValueMock->method('load')->will($this->returnSelf());
$attrSetCollectionValueMock->expects(null === $attrSetCollectionOptionsArray ? $this->never() : $this->once())->method('toOptionArray')->willReturn($attrSetCollectionOptionsArray);
$attrSetCollectionProperty = new ReflectionProperty('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_attrSetCollection');
$attrSetCollectionProperty->setAccessible(true);
$attrSetCollectionProperty->setValue($this->_condition, $attrSetCollectionValueMock);
$testedMethod = new ReflectionMethod('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_prepareValueOptions');
$testedMethod->setAccessible(true);
$testedMethod->invoke($this->_condition);
$this->assertEquals($expectedValueSelectOptions, $this->_condition->getData('value_select_options'));
$this->assertEquals($expectedValueOption, $this->_condition->getData('value_option'));
}
示例9: testCRUD
/**
* @magentoAppIsolation enabled
*/
public function testCRUD()
{
$this->_model->setData(array('code' => 'test', 'website_id' => 1, 'group_id' => 1, 'name' => 'test name', 'sort_order' => 0, 'is_active' => 1));
/* emulate admin store */
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
$crud = new Magento_Test_Entity($this->_model, array('name' => 'new name'));
$crud->testCrud();
}
示例10: testCollect
/**
* @param array $orderData
* @param array $invoiceData
* @param array $expectedResults
* @dataProvider collectDataProvider
*/
public function testCollect($orderData, $invoiceData, $expectedResults)
{
$roundingDelta = [];
$this->setupOrder($orderData);
//Set up weeeData mock
$this->weeeData->expects($this->once())->method('includeInSubtotal')->will($this->returnValue($invoiceData['include_in_subtotal']));
//Set up invoice mock
/** @var \Magento\Sales\Model\Order\Invoice\Item[] $invoiceItems */
$invoiceItems = [];
foreach ($invoiceData['items'] as $itemKey => $invoiceItemData) {
$invoiceItems[$itemKey] = $this->getInvoiceItem($invoiceItemData);
}
$this->invoice->expects($this->once())->method('getAllItems')->will($this->returnValue($invoiceItems));
$this->invoice->expects($this->once())->method('isLast')->will($this->returnValue($invoiceData['is_last']));
foreach ($invoiceData['data_fields'] as $key => $value) {
$this->invoice->setData($key, $value);
}
$this->invoice->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
if (!isset($roundingDelta[$type])) {
$roundingDelta[$type] = 0;
}
$roundedPrice = round($price + $roundingDelta[$type], 2);
$roundingDelta[$type] = $price - $roundedPrice;
return $roundedPrice;
}));
$this->model->collect($this->invoice);
//verify invoice data
foreach ($expectedResults['invoice_data'] as $key => $value) {
$this->assertEquals($value, $this->invoice->getData($key), 'Invoice data field ' . $key . ' is incorrect');
}
//verify invoice item data
foreach ($expectedResults['invoice_items'] as $itemKey => $itemData) {
$invoiceItem = $invoiceItems[$itemKey];
foreach ($itemData as $key => $value) {
if ($key == 'tax_ratio') {
$taxRatio = unserialize($invoiceItem->getData($key));
$expectedTaxRatio = unserialize($itemData[$key]);
$this->assertEquals($expectedTaxRatio['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
} else {
$this->assertEquals($value, $invoiceItem->getData($key), 'Invoice item field ' . $key . ' is incorrect');
}
}
}
}
示例11: testCalculate
/**
* @covers \Magento\SalesRule\Model\Rule\Action\Discount\CartFixed::calculate
*/
public function testCalculate()
{
$this->rule->setData(['id' => 1, 'discount_amount' => 10.0]);
$this->address->expects($this->any())->method('getCartFixedRules')->will($this->returnValue([]));
$store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
$this->priceCurrency->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0));
$this->priceCurrency->expects($this->atLeastOnce())->method('round')->will($this->returnArgument(0));
$this->quote->expects($this->any())->method('getStore')->will($this->returnValue($store));
/** validators data */
$this->validator->expects($this->once())->method('getItemPrice')->with($this->item)->will($this->returnValue(100));
$this->validator->expects($this->once())->method('getItemBasePrice')->with($this->item)->will($this->returnValue(100));
$this->validator->expects($this->once())->method('getItemOriginalPrice')->with($this->item)->will($this->returnValue(100));
$this->validator->expects($this->once())->method('getItemBaseOriginalPrice')->with($this->item)->will($this->returnValue(100));
$this->address->expects($this->once())->method('setCartFixedRules')->with([1 => 0.0]);
$this->model->calculate($this->rule, $this->item, 1);
$this->assertEquals($this->data->getAmount(), 10);
$this->assertEquals($this->data->getBaseAmount(), 10);
$this->assertEquals($this->data->getOriginalAmount(), 10);
$this->assertEquals($this->data->getBaseOriginalAmount(), 100);
}
示例12: testCollect
/**
* @param array $orderData
* @param array $creditmemoData
* @param array $expectedResults
* @dataProvider collectDataProvider
*/
public function testCollect($orderData, $creditmemoData, $expectedResults)
{
$roundingDelta = [];
//Set up order mock
foreach ($orderData['data_fields'] as $key => $value) {
$this->order->setData($key, $value);
}
//Set up creditmemo mock
/** @var \Magento\Sales\Model\Order\Creditmemo\Item[] $creditmemoItems */
$creditmemoItems = [];
foreach ($creditmemoData['items'] as $itemKey => $creditmemoItemData) {
$creditmemoItems[$itemKey] = $this->getCreditmemoItem($creditmemoItemData);
}
$this->creditmemo->expects($this->once())->method('getAllItems')->will($this->returnValue($creditmemoItems));
$this->creditmemo->expects($this->any())->method('isLast')->will($this->returnValue($creditmemoData['is_last']));
foreach ($creditmemoData['data_fields'] as $key => $value) {
$this->creditmemo->setData($key, $value);
}
$this->creditmemo->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
if (!isset($roundingDelta[$type])) {
$roundingDelta[$type] = 0;
}
$roundedPrice = round($price + $roundingDelta[$type], 2);
$roundingDelta[$type] = $price - $roundedPrice;
return $roundedPrice;
}));
$this->model->collect($this->creditmemo);
//verify invoice data
foreach ($expectedResults['creditmemo_data'] as $key => $value) {
$this->assertEquals($value, $this->creditmemo->getData($key));
}
//verify invoice item data
foreach ($expectedResults['creditmemo_items'] as $itemKey => $itemData) {
$creditmemoItem = $creditmemoItems[$itemKey];
foreach ($itemData as $key => $value) {
$this->assertEquals($value, $creditmemoItem->getData($key));
}
}
}
示例13: testApplyRulesThatAppliedRuleIdsAreCollected
public function testApplyRulesThatAppliedRuleIdsAreCollected()
{
$positivePrice = 1;
$ruleId1 = 123;
$ruleId2 = 234;
$expectedRuleIds = [$ruleId1 => $ruleId1, $ruleId2 => $ruleId2];
$this->model->init($this->model->getWebsiteId(), $this->model->getCustomerGroupId(), $this->model->getCouponCode());
$this->item->setDiscountCalculationPrice($positivePrice);
$this->item->setData('calculation_price', $positivePrice);
$this->model->setSkipActionsValidation(true);
$this->rulesApplier->expects($this->once())->method('applyRules')->with($this->equalTo($this->item), $this->equalTo($this->ruleCollection), $this->anything(), $this->anything())->will($this->returnValue($expectedRuleIds));
$this->rulesApplier->expects($this->once())->method('setAppliedRuleIds')->with($this->anything(), $expectedRuleIds);
$this->model->process($this->item);
}
示例14: startTestGetProductCollection
/**
* @param string $displayType
* @param bool $pagerEnable
* @param int $productsCount
* @param int $productsPerPage
*/
protected function startTestGetProductCollection($displayType, $pagerEnable, $productsCount, $productsPerPage)
{
$productCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory', ['create'], [], '', false, false);
$productCollectionFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->productCollection);
$this->block = $this->objectManager->getObject('Magento\\Catalog\\Block\\Product\\Widget\\NewWidget', ['context' => $this->context, 'productCollectionFactory' => $productCollectionFactory]);
if (null === $productsPerPage) {
$this->block->unsetData('products_per_page');
} else {
$this->block->setData('products_per_page', $productsPerPage);
}
$this->block->setData('show_pager', $pagerEnable);
$this->block->setData('display_type', $displayType);
$this->block->setProductsCount($productsCount);
$this->block->toHtml();
}
示例15: testSaveExistingWithMediaGalleryEntries
public function testSaveExistingWithMediaGalleryEntries()
{
//update one entry, delete one entry
$newEntries = [['id' => 5, "label" => "new_label_text", 'file' => 'filename1', 'position' => 10, 'disabled' => false, 'types' => ['image', 'small_image']]];
$existingMediaGallery = ['images' => [['value_id' => 5, "label" => "label_text", 'file' => 'filename1', 'position' => 10, 'disabled' => true], ['value_id' => 6, 'file' => 'filename2']]];
$expectedResult = [['id' => 5, 'value_id' => 5, "label" => "new_label_text", 'file' => 'filename1', 'position' => 10, 'disabled' => false, 'types' => ['image', 'small_image']], ['value_id' => 6, 'file' => 'filename2', 'removed' => true]];
$this->setupProductMocksForSave();
//media gallery data
$this->productData['media_gallery_entries'] = $newEntries;
$this->extensibleDataObjectConverterMock->expects($this->once())->method('toNestedArray')->will($this->returnValue($this->productData));
$this->initializedProductMock->setData('media_gallery', $existingMediaGallery);
$this->initializedProductMock->expects($this->any())->method('getMediaAttributes')->willReturn(["image" => "filename1", "small_image" => "filename2"]);
$this->mediaGalleryProcessor->expects($this->once())->method('clearMediaAttribute')->with($this->initializedProductMock, ['image', 'small_image']);
$this->mediaGalleryProcessor->expects($this->once())->method('setMediaAttribute')->with($this->initializedProductMock, ['image', 'small_image'], 'filename1');
$this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
$this->model->save($this->productMock);
$this->assertEquals($expectedResult, $this->initializedProductMock->getMediaGallery('images'));
}