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


PHP Data::expects方法代码示例

本文整理汇总了PHP中Magento\Framework\Json\Helper\Data::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::expects方法的具体用法?PHP Data::expects怎么用?PHP Data::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Json\Helper\Data的用法示例。


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

示例1: testJsonEncode

 public function testJsonEncode()
 {
     $expectedValue = 'string';
     $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with($this->equalTo($expectedValue))->will($this->returnValue($expectedValue));
     $result = $this->object->jsonEncode($expectedValue);
     $this->assertEquals($expectedValue, $result);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:7,代码来源:PriceBoxTest.php

示例2: testExecuteWithException

 public function testExecuteWithException()
 {
     $this->requestMock->expects($this->once())->method('getParam')->with('item_id', null)->willReturn('1');
     $exception = new \Exception('Error message!');
     $this->sidebarMock->expects($this->once())->method('checkQuoteItem')->with(1)->willThrowException($exception);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception)->willReturn(null);
     $this->sidebarMock->expects($this->once())->method('getResponseData')->with('Error message!')->willReturn(['success' => false, 'error_message' => 'Error message!']);
     $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(['success' => false, 'error_message' => 'Error message!'])->willReturn('json encoded');
     $this->responseMock->expects($this->once())->method('representJson')->with('json encoded')->willReturn('json represented');
     $this->assertEquals('json represented', $this->removeItem->executeInternal());
 }
开发者ID:nblair,项目名称:magescotch,代码行数:11,代码来源:RemoveItemTest.php

示例3: testGetRegionJson

 public function testGetRegionJson()
 {
     $countries = [new \Magento\Framework\DataObject(['country_id' => 'Country1']), new \Magento\Framework\DataObject(['country_id' => 'Country2'])];
     $countryIterator = new \ArrayIterator($countries);
     $this->_countryCollection->expects($this->atLeastOnce())->method('getIterator')->will($this->returnValue($countryIterator));
     $regions = [new \Magento\Framework\DataObject(['country_id' => 'Country1', 'region_id' => 'r1', 'code' => 'r1-code', 'name' => 'r1-name']), new \Magento\Framework\DataObject(['country_id' => 'Country1', 'region_id' => 'r2', 'code' => 'r2-code', 'name' => 'r2-name']), new \Magento\Framework\DataObject(['country_id' => 'Country2', 'region_id' => 'r3', 'code' => 'r3-code', 'name' => 'r3-name'])];
     $regionIterator = new \ArrayIterator($regions);
     $this->_regionCollection->expects($this->once())->method('addCountryFilter')->with(['Country1', 'Country2'])->will($this->returnSelf());
     $this->_regionCollection->expects($this->once())->method('load');
     $this->_regionCollection->expects($this->once())->method('getIterator')->will($this->returnValue($regionIterator));
     $expectedDataToEncode = ['config' => ['show_all_regions' => false, 'regions_required' => []], 'Country1' => ['r1' => ['code' => 'r1-code', 'name' => 'r1-name'], 'r2' => ['code' => 'r2-code', 'name' => 'r2-name']], 'Country2' => ['r3' => ['code' => 'r3-code', 'name' => 'r3-name']]];
     $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(new \PHPUnit_Framework_Constraint_IsIdentical($expectedDataToEncode))->will($this->returnValue('encoded_json'));
     // Test
     $result = $this->_object->getRegionJson();
     $this->assertEquals('encoded_json', $result);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:DataTest.php

示例4: testAfterRenderResultWithWrongArray

 public function testAfterRenderResultWithWrongArray()
 {
     $messageType = 'message1type';
     $messageText = 'message1text';
     $messages = [['type' => $messageType, 'text' => $messageText]];
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $resultMock */
     $resultMock = $this->getMockBuilder(Redirect::class)->disableOriginalConstructor()->getMock();
     /** @var PublicCookieMetadata|\PHPUnit_Framework_MockObject_MockObject $cookieMetadataMock */
     $cookieMetadataMock = $this->getMockBuilder(PublicCookieMetadata::class)->disableOriginalConstructor()->getMock();
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->willReturn($cookieMetadataMock);
     $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode($messages), $cookieMetadataMock);
     $this->cookieManagerMock->expects($this->once())->method('getCookie')->with(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode([]))->willReturn(\Zend_Json::encode('string'));
     $this->dataMock->expects($this->any())->method('jsonDecode')->willReturnCallback(function ($data) {
         return \Zend_Json::decode($data);
     });
     $this->dataMock->expects($this->any())->method('jsonEncode')->willReturnCallback(function ($data) {
         return \Zend_Json::encode($data);
     });
     /** @var MessageInterface|\PHPUnit_Framework_MockObject_MockObject $messageMock */
     $messageMock = $this->getMockBuilder(MessageInterface::class)->getMock();
     $messageMock->expects($this->once())->method('getType')->willReturn($messageType);
     $this->interpretationStrategyMock->expects($this->once())->method('interpret')->with($messageMock)->willReturn($messageText);
     /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
     $collectionMock->expects($this->once())->method('getItems')->willReturn([$messageMock]);
     $this->managerMock->expects($this->once())->method('getMessages')->with(true, null)->willReturn($collectionMock);
     $this->assertEquals($resultMock, $this->model->afterRenderResult($resultMock, $resultMock));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:28,代码来源:MessagePluginTest.php

示例5: testExecuteFailedPlaceOrder

 /**
  * @param $paymentMethod
  * @param $controller
  * @param $quoteId
  * @param $result
  * @dataProvider textExecuteFailedPlaceOrderDataProvider
  */
 public function testExecuteFailedPlaceOrder($paymentMethod, $controller, $quoteId, $result)
 {
     $this->requestMock->expects($this->at(0))->method('getParam')->with('payment')->will($this->returnValue($paymentMethod));
     $this->requestMock->expects($this->at(1))->method('getParam')->with('controller')->will($this->returnValue($controller));
     $this->quoteMock->expects($this->any())->method('getId')->will($this->returnValue($quoteId));
     $this->cartManagementMock->expects($this->once())->method('placeOrder')->willThrowException(new \Exception());
     $this->jsonHelperMock->expects($this->any())->method('jsonEncode')->with($result);
     $this->placeOrderController->execute();
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:PlaceTest.php

示例6: testGenerateSimpleProducts

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGenerateSimpleProducts()
 {
     $productsData = [6 => ['image' => 'image.jpg', 'name' => 'config-red', 'configurable_attribute' => '{"new_attr":"6"}', 'sku' => 'config-red', 'quantity_and_stock_status' => ['qty' => ''], 'weight' => '333']];
     $stockData = ['manage_stock' => '0', 'use_config_enable_qty_increments' => '1', 'use_config_qty_increments' => '1', 'use_config_manage_stock' => 0, 'is_decimal_divided' => 0];
     $parentProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'hasData', 'getData', 'getNewVariationsAttributeSetId', 'getStockData', 'getQuantityAndStockStatus', 'getWebsiteIds'])->disableOriginalConstructor()->getMock();
     $newSimpleProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'save', 'getId', 'setStoreId', 'setTypeId', 'setAttributeSetId', 'getTypeInstance', 'getStoreId', 'addData', 'setWebsiteIds', 'setStatus', 'setVisibility'])->disableOriginalConstructor()->getMock();
     $attributeMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['isInSet', 'setAttributeSetId', 'setAttributeGroupId', 'save'])->disableOriginalConstructor()->getMock();
     $attributeSetMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->setMethods(['load', 'addSetInfo', 'getDefaultGroupId'])->disableOriginalConstructor()->getMock();
     $eavEntityMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity')->setMethods(['setType', 'getTypeId'])->disableOriginalConstructor()->getMock();
     $productTypeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type')->setMethods(['getEditableAttributes'])->disableOriginalConstructor()->getMock();
     $editableAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['getIsUnique', 'getAttributeCode', 'getFrontend', 'getIsVisible'])->disableOriginalConstructor()->getMock();
     $frontendAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend')->setMethods(['getInputType'])->disableOriginalConstructor()->getMock();
     $parentProductMock->expects($this->once())->method('hasData')->with('_cache_instance_used_product_attributes')->willReturn(true);
     $parentProductMock->expects($this->once())->method('getData')->with('_cache_instance_used_product_attributes')->willReturn([$attributeMock]);
     $parentProductMock->expects($this->any())->method('getNewVariationsAttributeSetId')->willReturn('new_attr_set_id');
     $this->_attributeSetFactory->expects($this->once())->method('create')->willReturn($attributeSetMock);
     $attributeSetMock->expects($this->once())->method('load')->with('new_attr_set_id')->willReturnSelf();
     $this->_entityFactoryMock->expects($this->once())->method('create')->willReturn($eavEntityMock);
     $eavEntityMock->expects($this->once())->method('setType')->with('catalog_product')->willReturnSelf();
     $eavEntityMock->expects($this->once())->method('getTypeId')->willReturn('type_id');
     $attributeSetMock->expects($this->once())->method('addSetInfo')->with('type_id', [$attributeMock]);
     $attributeMock->expects($this->once())->method('isInSet')->with('new_attr_set_id')->willReturn(false);
     $attributeMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $attributeSetMock->expects($this->once())->method('getDefaultGroupId')->with('new_attr_set_id')->willReturn('default_group_id');
     $attributeMock->expects($this->once())->method('setAttributeGroupId')->with('default_group_id')->willReturnSelf();
     $attributeMock->expects($this->once())->method('save')->willReturnSelf();
     $this->_productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
     $this->jsonHelperMock->expects($this->once())->method('jsonDecode')->with('{"new_attr":"6"}')->willReturn(['new_attr' => 6]);
     $newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getTypeInstance')->willReturn($productTypeMock);
     $productTypeMock->expects($this->once())->method('getEditableAttributes')->with($newSimpleProductMock)->willReturn([$editableAttributeMock]);
     $editableAttributeMock->expects($this->once())->method('getIsUnique')->willReturn(false);
     $editableAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn('some_code');
     $editableAttributeMock->expects($this->any())->method('getFrontend')->willReturn($frontendAttributeMock);
     $frontendAttributeMock->expects($this->any())->method('getInputType')->willReturn('input_type');
     $editableAttributeMock->expects($this->any())->method('getIsVisible')->willReturn(false);
     $parentProductMock->expects($this->once())->method('getStockData')->willReturn($stockData);
     $parentProductMock->expects($this->once())->method('getQuantityAndStockStatus')->willReturn(['is_in_stock' => 1]);
     $newSimpleProductMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
     $this->_stockConfiguration->expects($this->once())->method('getManageStock')->with('store_id')->willReturn(1);
     $newSimpleProductMock->expects($this->once())->method('addData')->willReturnSelf();
     $parentProductMock->expects($this->once())->method('getWebsiteIds')->willReturn('website_id');
     $newSimpleProductMock->expects($this->once())->method('setWebsiteIds')->with('website_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setStatus')->with(1)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setVisibility')->with(1)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('save')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getId')->willReturn('product_id');
     $this->assertEquals(['product_id'], $this->_model->generateSimpleProducts($parentProductMock, $productsData));
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:54,代码来源:ConfigurableTest.php

示例7: testExecute

 public function testExecute()
 {
     $themeId = 23;
     $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface', [], '', false);
     $jsFile = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\Theme\\FileInterface', [], '', false, true, true, ['setTheme', 'setFileName', 'setData', 'save']);
     $this->_request->expects($this->at(0))->method('getParam')->with('id')->willReturn($themeId);
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with('Magento\\Theme\\Model\\Uploader\\Service')->WillReturn($this->serviceModel);
     $this->_objectManagerMock->expects($this->at(1))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory')->WillReturn($this->themeFactory);
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\Customization\\File\\Js')->WillReturn($this->customizationJs);
     $this->_objectManagerMock->expects($this->at(4))->method('get')->with('Magento\\Framework\\Json\\Helper\\Data')->WillReturn($this->jsonHelper);
     $this->themeFactory->expects($this->once())->method('create')->willReturn($theme);
     $this->serviceModel->expects($this->once())->method('uploadJsFile')->with('js_files_uploader')->willReturn(['filename' => 'filename', 'content' => 'content']);
     $this->customizationJs->expects($this->once())->method('create')->willReturn($jsFile);
     $jsFile->expects($this->once())->method('setTheme')->with($theme);
     $jsFile->expects($this->once())->method('setFileName')->with('filename');
     $jsFile->expects($this->once())->method('setData')->with('content', 'content');
     $jsFile->expects($this->once())->method('save');
     $this->_objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\View\\Design\\Theme\\CustomizationInterface', ['theme' => $theme])->willReturn($this->themeCustomization);
     $this->themeCustomization->expects($this->once())->method('getFilesByType')->with(\Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE)->willReturn([$jsFile]);
     $this->themeCustomization->expects($this->once())->method('generateFileInfo')->with([$jsFile])->willReturn(['fileOne' => ['name' => 'name']]);
     $this->jsonHelper->expects($this->once())->method('jsonEncode')->with(['error' => false, 'files' => ['fileOne' => ['name' => 'name']]])->willReturn('{"error":false,"files":{"fileOne":{"name":"name"}}}');
     $this->response->expects($this->once())->method('representJson')->with('{"error":false,"files":{"fileOne":{"name":"name"}}}');
     $this->_model->execute();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:24,代码来源:UploadJsTest.php

示例8: testLoginFailure

 public function testLoginFailure()
 {
     $jsonRequest = '{"username":"invalid@example.com", "password":"invalid"}';
     $loginFailureResponse = '{"message":"Invalid login or password."}';
     $this->request->expects($this->any())->method('getContent')->willReturn($jsonRequest);
     $this->request->expects($this->any())->method('getMethod')->willReturn('POST');
     $this->request->expects($this->any())->method('isXmlHttpRequest')->willReturn(true);
     $this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->jsonHelperMock->expects($this->any())->method('jsonDecode')->with($jsonRequest)->willReturn(['username' => 'invalid@example.com', 'password' => 'invalid']);
     $customerMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->customerAccountManagementMock->expects($this->any())->method('authenticate')->with('invalid@example.com', 'invalid')->willThrowException(new InvalidEmailOrPasswordException(__('Invalid login or password.')));
     $this->customerSession->expects($this->never())->method('setCustomerDataAsLoggedIn')->with($customerMock);
     $this->customerSession->expects($this->never())->method('regenerateId');
     $result = ['errors' => true, 'message' => __('Invalid login or password.')];
     $this->resultJson->expects($this->once())->method('setData')->with($result)->willReturn($loginFailureResponse);
     $this->assertEquals($loginFailureResponse, $this->object->execute());
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:17,代码来源:LoginTest.php

示例9: testSaveWithFile

 public function testSaveWithFile()
 {
     $sampleId = 1;
     $productId = 1;
     $productSku = 'simple';
     $sampleFile = '/s/a/sample.jpg';
     $sampleData = ['id' => $sampleId, 'title' => 'Updated Title', 'sort_order' => 1, 'sample_type' => 'file', 'file' => $sampleFile];
     $this->repositoryMock->expects($this->once())->method('get')->with($productSku, true)->willReturn($this->productMock);
     $this->productMock->expects($this->once())->method('getTypeId')->willReturn('downloadable');
     $this->productMock->expects($this->once())->method('getData')->with('id')->willReturn($productId);
     $sampleMock = $this->getSampleMock($sampleData);
     $this->contentValidatorMock->expects($this->any())->method('isValid')->with($sampleMock)->willReturn(true);
     $sampleMock->expects($this->once())->method('setProductId')->with($productId);
     $sampleMock->expects($this->exactly(2))->method('getFile')->willReturn($sampleFile);
     $this->jsonEncoderMock->expects($this->once())->method('jsonDecode')->willReturn($sampleFile);
     $this->contentUploaderMock->expects($this->once())->method('moveFileFromTmp')->with($sampleMock->getBaseTmpPath(), $sampleMock->getBasePath(), $sampleFile)->willReturn($sampleFile);
     $sampleMock->expects($this->once())->method('setSampleFile')->with($sampleFile);
     $sampleMock->expects($this->once())->method('setSampleUrl')->with(null);
     $this->sampleResourceMock->expects($this->once())->method('save')->with($sampleMock)->willReturn($sampleId);
     $this->assertEquals($sampleId, $this->service->save($productSku, $sampleMock));
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:21,代码来源:SampleRepositoryTest.php


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