本文整理汇总了PHP中Magento\Framework\Json\EncoderInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP EncoderInterface::expects方法的具体用法?PHP EncoderInterface::expects怎么用?PHP EncoderInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Json\EncoderInterface
的用法示例。
在下文中一共展示了EncoderInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAfterGetOptions
public function testAfterGetOptions()
{
$resultJson = '[]';
$this->jsonDecoder->expects($this->once())->method('decode')->with('[]')->willReturn([]);
$expected = ['configurable_attribute_1' => [['mediaType' => 'type', 'videoUrl' => 'url', 'isBase' => true]]];
$this->jsonEncoder->expects($this->any())->method('encode')->with($expected)->willReturn(json_encode($expected));
$blockMock = $this->getMockBuilder('\\Magento\\ProductVideo\\Block\\Product\\View\\Gallery')->disableOriginalConstructor()->getMock();
$result = $this->plugin->afterGetOptionsMediaGalleryDataJson($blockMock, $resultJson);
$this->assertEquals(json_encode($expected), $result);
}
示例2: testGetWidgetOptions
public function testGetWidgetOptions()
{
$rand = rand();
$this->mathRandom->expects($this->any())->method('getUniqueHash')->with('id_')->willReturn('id_' . $rand);
$saveVideoUrl = 'http://host/index.php/admin/catalog/product_gallery/upload/key/';
$saveRemoteVideoUrl = 'http://host/index.php/admin/product_video/product_gallery/retrieveImage/';
$this->urlBuilder->expects($this->exactly(2))->method('getUrl')->willReturnOnConsecutiveCalls($saveVideoUrl, $saveRemoteVideoUrl);
$value = ['saveVideoUrl' => $saveVideoUrl, 'saveRemoteVideoUrl' => $saveRemoteVideoUrl, 'htmlId' => 'id_' . $rand];
$this->jsonEncoderMock->expects($this->once())->method('encode')->with($value)->willReturn(json_encode($value));
$this->block->getWidgetOptions();
}
示例3: setUp
/**
* Setup
*
* @return void
*/
public function setUp()
{
$this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
$this->collectMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Module\\Collect')->disableOriginalConstructor()->setMethods(['getModuleData'])->getMock();
$this->systemFactoryMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\SystemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
$this->systemModelMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\System')->disableOriginalConstructor()->getMock();
$this->jsonEncoderMock = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
$this->systemFactoryMock->expects($this->any())->method('create')->willReturn($this->systemModelMock);
$this->jsonEncoderMock->expects($this->any())->method('encode')->willReturn('json_string');
$this->model = new ReportModulesInfo($this->config, $this->collectMock, $this->systemFactoryMock, $this->jsonEncoderMock);
}
示例4: testReportSystemCacheFlush
/**
* Test case when module is enabled in config
*
* @return void
*/
public function testReportSystemCacheFlush()
{
$testType = 'systemCacheFlush';
$testAction = 'JSON string';
/** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
$eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
$this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
$this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
$this->systemModel->expects($this->once())->method('setData')->with(['type' => $testType, 'action' => $testAction])->willReturnSelf();
$this->systemModel->expects($this->once())->method('save');
$this->model->execute($eventObserver);
}
示例5: setUp
/**
* Setup
*
* @return void
*/
public function setUp()
{
$this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
$this->collect = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Module\\Collect')->disableOriginalConstructor()->setMethods(['getModuleData'])->getMock();
$this->systemFactory = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\SystemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
$this->systemModel = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\System')->disableOriginalConstructor()->getMock();
$this->jsonEncoder = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
$this->dateTime = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->disableOriginalConstructor()->setMethods(['formatDate'])->getMock();
$this->systemFactory->expects($this->any())->method('create')->willReturn($this->systemModel);
$this->jsonEncoder->expects($this->any())->method('encode')->willReturn('json_string');
$this->dateTime->expects($this->any())->method('formatDate')->willReturn('1970-01-01 00:00:00');
$this->model = new ReportModulesInfo($this->config, $this->collect, $this->systemFactory, $this->jsonEncoder, $this->dateTime);
}
示例6: testGetUsersPositiveNumberOfRolesAndJsonTrue
public function testGetUsersPositiveNumberOfRolesAndJsonTrue()
{
$roleId = 1;
$roles = ['role1', 'role2', 'role3'];
/** @var \Magento\Authorization\Model\Role|\PHPUnit_Framework_MockObject_MockObject */
$roleModelMock = $this->getMockBuilder('Magento\\Authorization\\Model\\Role')->disableOriginalConstructor()->setMethods([])->getMock();
$this->requestInterfaceMock->expects($this->at(0))->method('getParam')->willReturn("");
$this->requestInterfaceMock->expects($this->at(1))->method('getParam')->willReturn($roleId);
$this->requestInterfaceMock->expects($this->at(2))->method('getParam')->willReturn($roleId);
$this->registryMock->expects($this->once())->method('registry')->with(\Magento\User\Controller\Adminhtml\User\Role\SaveRole::IN_ROLE_USER_FORM_DATA_SESSION_KEY)->willReturn('role1=value1&role2=value2&role3=value3');
$this->roleFactoryMock->expects($this->never())->method('create')->willReturn($roleModelMock);
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($roles);
$this->assertEquals($roles, $this->model->getUsers(true));
}
示例7: testGetUsersPositiveNumberOfRolesAndJsonTrue
public function testGetUsersPositiveNumberOfRolesAndJsonTrue()
{
$roleId = 1;
$roles = ['role1', 'role2', 'role3'];
/** @var \Magento\Authorization\Model\Role|\PHPUnit_Framework_MockObject_MockObject */
$roleModelMock = $this->getMockBuilder('Magento\\Authorization\\Model\\Role')->disableOriginalConstructor()->setMethods([])->getMock();
$this->requestInterfaceMock->expects($this->at(0))->method('getParam')->willReturn("");
$this->requestInterfaceMock->expects($this->at(1))->method('getParam')->willReturn($roleId);
$this->requestInterfaceMock->expects($this->at(2))->method('getParam')->willReturn($roleId);
$this->roleFactoryMock->expects($this->once())->method('create')->willReturn($roleModelMock);
$roleModelMock->expects($this->once())->method('setId')->willReturnSelf();
$roleModelMock->expects($this->once())->method('getRoleUsers')->willReturn($roles);
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($roles);
$this->assertEquals($roles, $this->model->getUsers(true));
}
示例8: testReportProductDeleted
/**
* Test case when module is enabled in config
*
* @return void
*/
public function testReportProductDeleted()
{
$testType = 'adminProductChange';
$testAction = 'JSON string';
/** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
$eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
$this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
$event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getProduct'])->disableOriginalConstructor()->getMock();
$eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
$product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getId'])->disableOriginalConstructor()->getMock();
$event->expects($this->once())->method('getProduct')->willReturn($product);
$this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
$this->systemModel->expects($this->once())->method('setData')->with(['type' => $testType, 'action' => $testAction])->willReturnSelf();
$this->systemModel->expects($this->once())->method('save');
$this->model->execute($eventObserver);
}
示例9: testSendRequestStatusBad
/**
* Tests client request with Bad status
*
* @return void
*/
public function testSendRequestStatusBad()
{
$json = '{"eventType":"Cron","appName":"app_name","appId":"app_id"}';
$statusBad = '401';
$uri = 'https://example.com/listener';
$method = ZendClient::POST;
$headers = ['X-Insert-Key' => 'insert_key_value', 'Content-Type' => 'application/json'];
$accId = 'acc_id';
$appId = 'app_id';
$appName = 'app_name';
$insightApiKey = 'insert_key_value';
$this->zendClientMock->expects($this->once())->method('setUri')->with($uri)->willReturnSelf();
$this->zendClientMock->expects($this->once())->method('setMethod')->with($method)->willReturnSelf();
$this->zendClientMock->expects($this->once())->method('setHeaders')->with($headers)->willReturnSelf();
$this->zendClientMock->expects($this->once())->method('setRawData')->with($json)->willReturnSelf();
$this->configMock->expects($this->once())->method('getNewRelicAccountId')->willReturn($accId);
$this->configMock->expects($this->once())->method('getInsightsApiUrl')->willReturn($uri);
$this->configMock->expects($this->once())->method('getInsightsInsertKey')->willReturn($insightApiKey);
$this->configMock->expects($this->once())->method('getNewRelicAppName')->willReturn($appName);
$this->configMock->expects($this->once())->method('getNewRelicAppId')->willReturn($appId);
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($json);
$zendHttpResponseMock = $this->getMockBuilder('Zend_Http_Response')->disableOriginalConstructor()->getMock();
$zendHttpResponseMock->expects($this->any())->method('getStatus')->willReturn($statusBad);
$this->zendClientMock->expects($this->once())->method('request')->willReturn($zendHttpResponseMock);
$this->zendClientFactoryMock->expects($this->once())->method('create')->willReturn($this->zendClientMock);
$this->assertInternalType('bool', $this->model->sendRequest());
}
示例10: testGetImagesJson
public function testGetImagesJson()
{
$url = [['file_1.jpg', 'url_to_the_image/image_1.jpg'], ['file_2.jpg', 'url_to_the_image/image_2.jpg']];
$mediaPath = [['file_1.jpg', 'catalog/product/image_1.jpg'], ['file_2.jpg', 'catalog/product/image_2.jpg']];
$sizeMap = [['catalog/product/image_1.jpg', ['size' => 399659]], ['catalog/product/image_2.jpg', ['size' => 879394]]];
$imagesResult = [['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0', 'url' => 'url_to_the_image/image_2.jpg', 'size' => 879394], ['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1', 'url' => 'url_to_the_image/image_1.jpg', 'size' => 399659]];
$images = ['images' => [['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1'], ['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0']]];
$this->content->setElement($this->galleryMock);
$this->galleryMock->expects($this->once())->method('getImages')->willReturn($images);
$this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
$this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
$this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturnMap($mediaPath);
$this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
$this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
}
示例11: testGetJsonSwatchUsedInProductListing
/**
* @covers Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData
*/
public function testGetJsonSwatchUsedInProductListing()
{
$products = [1 => 'testA', 3 => 'testB'];
$expected = ['type' => null, 'value' => 'hello', 'label' => $products[3]];
$this->prepareGetJsonSwatchConfig();
$this->configurable->setProduct($this->product);
$this->swatchHelper->expects($this->once())->method('getSwatchAttributesAsArray')->with($this->product)->willReturn([1 => ['options' => $products, 'use_product_image_for_swatch' => true, 'used_in_product_listing' => true, 'attribute_code' => 'code']]);
$this->swatchHelper->expects($this->once())->method('getSwatchesByOptionsId')->with([1, 3])->willReturn([3 => ['type' => $expected['type'], 'value' => $expected['value']]]);
$this->jsonEncoder->expects($this->once())->method('encode');
$this->configurable->getJsonSwatchConfig();
}
示例12: testGetImagesJson
public function testGetImagesJson()
{
$url = [['file_1.jpg', 'url_to_the_image/image_1.jpg'], ['file_2.jpg', 'url_to_the_image/image_2.jpg']];
$mediaPath = [['file_1.jpg', 'catalog/product/image_1.jpg'], ['file_2.jpg', 'catalog/product/image_2.jpg']];
// @codingStandardsIgnoreStart
$encodedString = '[{"value_id":"1","file":"image_1.jpg","media_type":"image","url":"http:\\/\\/magento2.dev\\/pub\\/media\\/catalog\\/product\\/image_1.jpg","size":879394},{"value_id":"2","file":"image_2.jpg","media_type":"image","url":"http:\\/\\/magento2.dev\\/pub\\/media\\/catalog\\/product\\/image`_2.jpg","size":399659}]';
// @codingStandardsIgnoreEnd
$images = ['images' => [['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image'], ['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image']]];
$firstStat = ['size' => 879394];
$secondStat = ['size' => 399659];
$this->content->setElement($this->galleryMock);
$this->galleryMock->expects($this->any())->method('getImages')->willReturn($images);
$this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
$this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
$this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturn($mediaPath);
$this->readMock->expects($this->at(0))->method('stat')->willReturn($firstStat);
$this->readMock->expects($this->at(1))->method('stat')->willReturn($secondStat);
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($encodedString);
$this->assertSame($encodedString, $this->content->getImagesJson());
}
示例13: testGetJsonSwatchConfigWithoutVisualImageType
public function testGetJsonSwatchConfigWithoutVisualImageType()
{
$this->configurable->setProduct($this->product);
$this->swatchHelper->expects($this->once())->method('getSwatchAttributesAsArray')->with($this->product)->willReturn([1 => ['options' => [1 => 'testA', 3 => 'testB'], 'use_product_image_for_swatch' => true, 'attribute_code' => 'code']]);
$this->swatchHelper->expects($this->once())->method('getSwatchesByOptionsId')->with([1, 3])->willReturn([3 => ['type' => Swatch::SWATCH_TYPE_VISUAL_IMAGE, 'value' => 'hello']]);
$this->swatchHelper->expects($this->once())->method('loadFirstVariationWithSwatchImage')->with($this->product, ['code' => 3])->willReturn($this->product);
$this->swatchMediaHelper->expects($this->exactly(2))->method('getSwatchAttributeImage')->withConsecutive(['swatch_image', 'hello'], ['swatch_thumb', 'hello'])->willReturn('/path');
$this->product->expects($this->exactly(4))->method('getData')->withConsecutive(['swatch_image'], ['image'], ['swatch_image'], ['image'])->will($this->onConsecutiveCalls(null, null, null, null));
$this->imageHelper->expects($this->never())->method('init');
$this->imageHelper->expects($this->never())->method('resize');
$this->jsonEncoder->expects($this->once())->method('encode');
$this->configurable->getJsonSwatchConfig();
}
示例14: testReportConcurrentAdmins
/**
* Test case when module is enabled and user is logged in
*
* @return void
*/
public function testReportConcurrentAdmins()
{
$testAction = 'JSON string';
/** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
$eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
$this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
$this->backendAuthSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
$userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
$this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
$this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
$this->usersModel->expects($this->once())->method('setData')->with(['type' => 'admin_activity', 'action' => $testAction])->willReturnSelf();
$this->usersModel->expects($this->once())->method('save');
$this->model->execute($eventObserver);
}
示例15: testReportConcurrentUsers
/**
* Test case when module is enabled and user is logged in
*
* @return void
*/
public function testReportConcurrentUsers()
{
$testCustomerId = 1;
$testAction = 'JSON string';
/** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
$eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
$this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
$this->customerSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
$this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($testCustomerId);
$customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
$this->customerRepository->expects($this->once())->method('getById')->willReturn($customerMock);
$storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
$this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
$websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
$this->storeManager->expects($this->once())->method('getWebsite')->willReturn($websiteMock);
$this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
$this->usersModel->expects($this->once())->method('setData')->with(['type' => 'user_action', 'action' => $testAction])->willReturnSelf();
$this->usersModel->expects($this->once())->method('save');
$this->model->execute($eventObserver);
}