How to use mock method of name class

Best Mockery code snippet using name.mock

LayoutTest.php

Source:LayoutTest.php Github

copy

Full Screen

1<?php2/**3 * Copyright © 2016 Magento. All rights reserved.4 * See COPYING.txt for license details.5 */6namespace Magento\Framework\View\Test\Unit;7/**8 * @SuppressWarnings(PHPMD.TooManyFields)9 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)10 */11class LayoutTest extends \PHPUnit_Framework_TestCase12{13 /**14 * @var \Magento\Framework\View\Layout15 */16 protected $model;17 /**18 * @var \PHPUnit_Framework_MockObject_MockObject19 */20 protected $structureMock;21 /**22 * @var \Magento\Framework\View\Layout\ProcessorFactory|\PHPUnit_Framework_MockObject_MockObject23 */24 protected $processorFactoryMock;25 /**26 * @var \Magento\Framework\View\Design\Theme\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject27 */28 protected $themeResolverMock;29 /**30 * @var \Magento\Framework\View\Model\Layout\Merge|\PHPUnit_Framework_MockObject_MockObject31 */32 protected $processorMock;33 /**34 * @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject35 */36 protected $eventManagerMock;37 /**38 * @var \Magento\Framework\View\Layout\Generator\Block|\PHPUnit_Framework_MockObject_MockObject39 */40 protected $generatorBlockMock;41 /**42 * @var \Magento\Framework\View\Layout\Generator\Container|\PHPUnit_Framework_MockObject_MockObject43 */44 protected $generatorContainerMock;45 /**46 * @var \Magento\Framework\Cache\FrontendInterface|\PHPUnit_Framework_MockObject_MockObject47 */48 protected $cacheMock;49 /**50 * @var \Magento\Framework\View\Layout\ReaderPool|\PHPUnit_Framework_MockObject_MockObject51 */52 protected $readerPoolMock;53 /**54 * @var \Magento\Framework\View\Layout\GeneratorPool|\PHPUnit_Framework_MockObject_MockObject55 */56 protected $generatorPoolMock;57 /**58 * @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject59 */60 protected $messageManagerMock;61 /**62 * @var \Magento\Framework\View\Layout\Reader\ContextFactory|\PHPUnit_Framework_MockObject_MockObject63 */64 protected $readerContextFactoryMock;65 /**66 * @var \Magento\Framework\View\Layout\Reader\Context|\PHPUnit_Framework_MockObject_MockObject67 */68 protected $readerContextMock;69 /**70 * @var \Magento\Framework\View\Layout\Generator\ContextFactory|\PHPUnit_Framework_MockObject_MockObject71 */72 protected $generatorContextFactoryMock;73 /**74 * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject75 */76 protected $appStateMock;77 /**78 * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject79 */80 protected $loggerMock;81 protected function setUp()82 {83 $this->structureMock = $this->getMockBuilder('Magento\Framework\View\Layout\Data\Structure')84 ->disableOriginalConstructor()85 ->getMock();86 $this->processorFactoryMock = $this->getMock(87 'Magento\Framework\View\Layout\ProcessorFactory',88 ['create'],89 [],90 '',91 false92 );93 $this->themeResolverMock = $this->getMockForAbstractClass(94 'Magento\Framework\View\Design\Theme\ResolverInterface'95 );96 $this->processorMock = $this->getMock('Magento\Framework\View\Model\Layout\Merge', [], [], '', false);97 $this->eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface');98 $this->generatorBlockMock = $this->getMockBuilder('Magento\Framework\View\Layout\Generator\Block')99 ->disableOriginalConstructor()->getMock();100 $this->generatorContainerMock = $this->getMockBuilder('Magento\Framework\View\Layout\Generator\Container')101 ->disableOriginalConstructor()->getMock();102 $this->cacheMock = $this->getMockBuilder('Magento\Framework\Cache\FrontendInterface')103 ->disableOriginalConstructor()104 ->getMock();105 $this->readerPoolMock = $this->getMockBuilder('Magento\Framework\View\Layout\ReaderPool')106 ->disableOriginalConstructor()107 ->getMock();108 $this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\ManagerInterface')109 ->disableOriginalConstructor()110 ->getMock();111 $this->generatorPoolMock = $this->getMockBuilder('Magento\Framework\View\Layout\GeneratorPool')112 ->disableOriginalConstructor()->getMock();113 $this->generatorPoolMock->expects($this->any())114 ->method('getGenerator')115 ->will(116 $this->returnValueMap([117 [\Magento\Framework\View\Layout\Generator\Block::TYPE, $this->generatorBlockMock],118 [\Magento\Framework\View\Layout\Generator\Container::TYPE, $this->generatorContainerMock],119 ])120 );121 $this->readerContextFactoryMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\ContextFactory')122 ->disableOriginalConstructor()123 ->getMock();124 $this->readerContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context')125 ->disableOriginalConstructor()126 ->getMock();127 $this->generatorContextFactoryMock = $this->getMockBuilder(128 'Magento\Framework\View\Layout\Generator\ContextFactory'129 )130 ->disableOriginalConstructor()131 ->getMock();132 $this->appStateMock = $this->getMockBuilder('Magento\Framework\App\State')133 ->disableOriginalConstructor()134 ->getMock();135 $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface')136 ->getMock();137 $this->model = new \Magento\Framework\View\Layout(138 $this->processorFactoryMock,139 $this->eventManagerMock,140 $this->structureMock,141 $this->messageManagerMock,142 $this->themeResolverMock,143 $this->readerPoolMock,144 $this->generatorPoolMock,145 $this->cacheMock,146 $this->readerContextFactoryMock,147 $this->generatorContextFactoryMock,148 $this->appStateMock,149 $this->loggerMock,150 true151 );152 }153 public function testCreateBlockSuccess()154 {155 $blockMock = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock')156 ->disableOriginalConstructor()157 ->getMockForAbstractClass();158 $this->structureMock->expects($this->once())159 ->method('createStructuralElement')160 ->with(161 'blockname',162 \Magento\Framework\View\Layout\Element::TYPE_BLOCK,163 'Magento\Framework\View\Element\AbstractBlock'164 )->willReturn('blockname');165 $this->generatorBlockMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock));166 $this->model->createBlock('Magento\Framework\View\Element\AbstractBlock', 'blockname', []);167 $this->assertInstanceOf('Magento\Framework\View\Element\AbstractBlock', $this->model->getBlock('blockname'));168 $this->assertFalse($this->model->getBlock('not_exist'));169 }170 public function testGetUpdate()171 {172 $themeMock = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface');173 $this->themeResolverMock->expects($this->once())174 ->method('get')175 ->will($this->returnValue($themeMock));176 $this->processorFactoryMock->expects($this->once())177 ->method('create')178 ->with(['theme' => $themeMock])179 ->will($this->returnValue($this->processorMock));180 $this->assertEquals($this->processorMock, $this->model->getUpdate());181 $this->assertEquals($this->processorMock, $this->model->getUpdate());182 }183 public function testGenerateXml()184 {185 $themeMock = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface');186 $this->themeResolverMock->expects($this->once())187 ->method('get')188 ->will($this->returnValue($themeMock));189 $this->processorFactoryMock->expects($this->once())190 ->method('create')191 ->with(['theme' => $themeMock])192 ->will($this->returnValue($this->processorMock));193 $xmlString = '<?xml version="1.0"?><layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'194 . '<some_update>123</some_update></layout>';195 $xml = simplexml_load_string($xmlString, 'Magento\Framework\View\Layout\Element');196 $this->processorMock->expects($this->once())197 ->method('asSimplexml')198 ->will($this->returnValue($xml));199 $this->structureMock->expects($this->once())200 ->method('importElements')201 ->with($this->equalTo([]))202 ->will($this->returnSelf());203 $this->assertSame($this->model, $this->model->generateXml());204 $this->assertSame('<some_update>123</some_update>', $this->model->getNode('some_update')->asXml());205 }206 public function testGetChildBlock()207 {208 $customBlockName = 'custom_block';209 $customBlockParentName = 'custom_block_parent';210 $customBlockAlias = 'custom_block_alias';211 $blockMock = $this->getMockBuilder('Magento\Framework\View\Element\Template')212 ->disableOriginalConstructor()213 ->getMock();214 $this->structureMock->expects($this->once())215 ->method('getChildId')216 ->with($customBlockParentName, $customBlockAlias)217 ->willReturn($customBlockName);218 $this->structureMock->expects($this->once())219 ->method('hasElement')220 ->with($customBlockName)221 ->willReturn(true);222 $this->structureMock->expects($this->once())223 ->method('getAttribute')224 ->with($customBlockName, 'type')225 ->willReturn(\Magento\Framework\View\Layout\Element::TYPE_BLOCK);226 $this->model->setBlock($customBlockName, $blockMock);227 $this->assertInstanceOf(228 'Magento\Framework\View\Element\AbstractBlock',229 $this->model->getChildBlock($customBlockParentName, $customBlockAlias)230 );231 }232 public function testGetChildNonExistBlock()233 {234 $this->structureMock->expects($this->once())235 ->method('getChildId')236 ->with('non_exist_parent', 'non_exist_alias')237 ->willReturn(false);238 $this->assertFalse($this->model->getChildBlock('non_exist_parent', 'non_exist_alias'));239 }240 public function testSetChild()241 {242 $elementName = 'child';243 $parentName = 'parent';244 $alias = 'some_alias';245 $this->structureMock->expects($this->once())246 ->method('setAsChild')247 ->with($this->equalTo($elementName), $this->equalTo($parentName), $this->equalTo($alias))248 ->will($this->returnSelf());249 $this->assertSame($this->model, $this->model->setChild($parentName, $elementName, $alias));250 }251 public function testUnsetChild()252 {253 $parentName = 'parent';254 $alias = 'some_alias';255 $this->structureMock->expects($this->once())256 ->method('unsetChild')257 ->with($this->equalTo($parentName), $this->equalTo($alias))258 ->will($this->returnSelf());259 $this->assertSame($this->model, $this->model->unsetChild($parentName, $alias));260 }261 public function testGetChildNames()262 {263 $parentName = 'parent';264 $childrenArray = ['key1' => 'value1', 'key2' => 'value2'];265 $this->structureMock->expects($this->once())266 ->method('getChildren')267 ->with($this->equalTo($parentName))268 ->will($this->returnValue($childrenArray));269 $this->assertSame(['key1', 'key2'], $this->model->getChildNames($parentName));270 }271 public function testGetChildBlocks()272 {273 $parentName = 'parent';274 $childrenArray = ['block_name' => 'value1'];275 $this->structureMock->expects($this->once())276 ->method('getChildren')277 ->with($this->equalTo($parentName))278 ->will($this->returnValue($childrenArray));279 $blockMock = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock')280 ->disableOriginalConstructor()281 ->getMockForAbstractClass();282 $this->structureMock->expects($this->once())283 ->method('createStructuralElement')284 ->with(285 'block_name',286 \Magento\Framework\View\Layout\Element::TYPE_BLOCK,287 'Magento\Framework\View\Element\AbstractBlock'288 )->willReturn('block_name');289 $this->generatorBlockMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock));290 $this->assertSame(291 $blockMock,292 $this->model->createBlock('Magento\Framework\View\Element\AbstractBlock', 'block_name', [])293 );294 $this->assertSame(['value1' => $blockMock], $this->model->getChildBlocks($parentName));295 }296 public function testGetChildName()297 {298 $parentName = 'parent';299 $alias = 'some_alias';300 $this->structureMock->expects($this->once())301 ->method('getChildId')302 ->with($this->equalTo($parentName), $this->equalTo($alias))303 ->will($this->returnValue('1'));304 $this->assertSame('1', $this->model->getChildName($parentName, $alias));305 }306 public function testAddToParentGroup()307 {308 $blockName = 'block_name';309 $parentGroup = 'parent_group';310 $this->structureMock->expects($this->once())311 ->method('addToParentGroup')312 ->with($this->equalTo($blockName), $this->equalTo($parentGroup))313 ->will($this->returnSelf());314 $this->assertSame($this->structureMock, $this->model->addToParentGroup($blockName, $parentGroup));315 }316 public function testGetGroupChildNames()317 {318 $blockName = 'block_name';319 $groupName = 'group_name';320 $this->structureMock->expects($this->once())321 ->method('getGroupChildNames')322 ->with($this->equalTo($blockName), $this->equalTo($groupName))323 ->will($this->returnSelf());324 $this->assertSame($this->structureMock, $this->model->getGroupChildNames($blockName, $groupName));325 }326 public function testHasElement()327 {328 $elementName = 'name';329 $this->structureMock->expects($this->once())330 ->method('hasElement')331 ->with($this->equalTo($elementName))332 ->will($this->returnValue(true));333 $this->assertTrue($this->model->hasElement($elementName));334 }335 public function testGetElementProperty()336 {337 $elementName = 'name';338 $elementAttr = 'attribute';339 $result = 'result';340 $this->structureMock->expects($this->once())341 ->method('getAttribute')342 ->with($this->equalTo($elementName), $this->equalTo($elementAttr))343 ->will($this->returnValue($result));344 $this->assertSame($result, $this->model->getElementProperty($elementName, $elementAttr));345 }346 /**347 * @param bool $hasElement348 * @param string $attribute349 * @param bool $result350 * @dataProvider isContainerDataProvider351 */352 public function testIsContainer($hasElement, $attribute, $result)353 {354 $elementName = 'element_name';355 $this->structureMock->expects($this->once())356 ->method('hasElement')357 ->with($this->equalTo($elementName))358 ->will($this->returnValue($hasElement));359 if ($hasElement) {360 $this->structureMock->expects($this->once())361 ->method('getAttribute')362 ->with($this->equalTo($elementName), $this->equalTo('type'))363 ->will($this->returnValue($attribute));364 }365 $this->assertSame($result, $this->model->isContainer($elementName));366 }367 /**368 * @return array369 */370 public function isContainerDataProvider()371 {372 return [373 [false, '', false],374 [true, 'container', true],375 [true, 'block', false],376 [true, 'something', false],377 ];378 }379 /**380 * @param bool $parentName381 * @param array $containerConfig382 * @param bool $result383 * @dataProvider isManipulationAllowedDataProvider384 */385 public function testIsManipulationAllowed($parentName, $containerConfig, $result)386 {387 $elementName = 'element_name';388 $this->structureMock->expects($this->once())389 ->method('getParentId')390 ->with($this->equalTo($elementName))391 ->will($this->returnValue($parentName));392 if ($parentName) {393 $this->structureMock->expects($this->once())394 ->method('hasElement')395 ->with($this->equalTo($parentName))396 ->will($this->returnValue($containerConfig['has_element']));397 if ($containerConfig['has_element']) {398 $this->structureMock->expects($this->once())399 ->method('getAttribute')400 ->with($this->equalTo($parentName), $this->equalTo('type'))401 ->will($this->returnValue($containerConfig['attribute']));402 }403 }404 $this->assertSame($result, $this->model->isManipulationAllowed($elementName));405 }406 /**407 * @return array408 */409 public function isManipulationAllowedDataProvider()410 {411 return [412 ['parent', ['has_element' => true, 'attribute' => 'container'], true],413 ['parent', ['has_element' => true, 'attribute' => 'block'], false],414 [false, [], false],415 ];416 }417 /**418 * @covers \Magento\Framework\View\Layout::setBlock419 * @covers \Magento\Framework\View\Layout::getAllBlocks420 * @covers \Magento\Framework\View\Layout::unsetElement421 */422 public function testSetGetBlock()423 {424 $blockName = 'some_name';425 $blockMock = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock')426 ->disableOriginalConstructor()427 ->getMockForAbstractClass();428 $this->assertSame($this->model, $this->model->setBlock($blockName, $blockMock));429 $this->assertSame([$blockName => $blockMock], $this->model->getAllBlocks());430 $this->structureMock->expects($this->once())431 ->method('unsetElement')432 ->with($this->equalTo($blockName))433 ->will($this->returnSelf());434 $this->assertSame($this->model, $this->model->unsetElement($blockName));435 $this->assertSame([], $this->model->getAllBlocks());436 }437 public function testRenameElement()438 {439 $oldName = 'old_name';440 $newName = 'new_name';441 $blockMock = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock')442 ->disableOriginalConstructor()443 ->getMockForAbstractClass();444 $this->structureMock->expects($this->once())445 ->method('renameElement')446 ->with($this->equalTo($oldName), $this->equalTo($newName))447 ->will($this->returnSelf());448 $this->assertSame($this->model, $this->model->setBlock($oldName, $blockMock));449 $this->assertSame($this->model, $this->model->renameElement($oldName, $newName));450 $this->assertSame([$newName => $blockMock], $this->model->getAllBlocks());451 }452 public function testGetParentName()453 {454 $childName = 'child_name';455 $parentId = 'parent_id';456 $this->structureMock->expects($this->once())457 ->method('getParentId')458 ->with($this->equalTo($childName))459 ->will($this->returnValue($parentId));460 $this->assertSame($parentId, $this->model->getParentName($childName));461 }462 public function testGetElementAlias()463 {464 $name = 'child_name';465 $parentId = 'parent_id';466 $alias = 'alias';467 $this->structureMock->expects($this->once())468 ->method('getParentId')469 ->with($this->equalTo($name))470 ->will($this->returnValue($parentId));471 $this->structureMock->expects($this->once())472 ->method('getChildAlias')473 ->with($this->equalTo($parentId), $this->equalTo($name))474 ->will($this->returnValue($alias));475 $this->assertSame($alias, $this->model->getElementAlias($name));476 }477 public function testAddRemoveOutputElement()478 {479 $this->assertSame($this->model, $this->model->addOutputElement('name'));480 $this->assertSame($this->model, $this->model->removeOutputElement('name'));481 }482 public function testIsPrivate()483 {484 $this->assertFalse($this->model->isPrivate());485 $this->assertSame($this->model, $this->model->setIsPrivate(true));486 $this->assertTrue($this->model->isPrivate());487 }488 /**489 * @param array $type490 * @param array $blockInstance491 * @dataProvider getBlockSingletonDataProvider492 */493 public function testGetBlockSingleton($type, $blockInstance, $isAbstract)494 {495 $blockMock = $this->getMock($blockInstance, [], [], '', false);496 $this->generatorBlockMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock));497 if ($isAbstract) {498 $blockMock->expects($this->any())499 ->method('setLayout')500 ->with($this->equalTo($this->model))501 ->will($this->returnSelf());502 }503 $this->assertInstanceOf($blockInstance, $this->model->getBlockSingleton($type));504 // singleton test505 $this->assertInstanceOf($blockInstance, $this->model->getBlockSingleton($type));506 }507 /**508 * @return array509 */510 public function getBlockSingletonDataProvider()511 {512 return [513 [514 'some_type',515 'Magento\Framework\View\Element\Template',516 true,517 ],518 ];519 }520 /**521 * @param array $rendererData522 * @param array $getData523 * @param bool $result524 * @dataProvider getRendererOptionsDataProvider525 */526 public function testAddGetRendererOptions($rendererData, $getData, $result)527 {528 $this->assertSame(529 $this->model,530 $this->model->addAdjustableRenderer(531 $rendererData['namespace'],532 $rendererData['static_type'],533 $rendererData['dynamic_type'],534 $rendererData['type'],535 $rendererData['template'],536 $rendererData['data']537 )538 );539 $this->assertSame(540 $result,541 $this->model->getRendererOptions($getData['namespace'], $getData['static_type'], $getData['dynamic_type'])542 );543 }544 /**545 * @return array546 */547 public function getRendererOptionsDataProvider()548 {549 $rendererData = [550 'namespace' => 'namespace_value',551 'static_type' => 'static_type_value',552 'dynamic_type' => 'dynamic_type_value',553 'type' => 'type_value',554 'template' => 'template.phtml',555 'data' => ['some' => 'data'],556 ];557 return [558 'wrong namespace' => [559 $rendererData,560 [561 'namespace' => 'wrong namespace',562 'static_type' => 'static_type_value',563 'dynamic_type' => 'dynamic_type_value',564 ],565 null,566 ],567 'wrong static type' => [568 $rendererData,569 [570 'namespace' => 'namespace_value',571 'static_type' => 'wrong static type',572 'dynamic_type' => 'dynamic_type_value',573 ],574 null,575 ],576 'wrong dynamic type' => [577 $rendererData,578 [579 'namespace' => 'namespace_value',580 'static_type' => 'static_type_value',581 'dynamic_type' => 'wrong dynamic type',582 ],583 null,584 ],585 'set and get test' => [586 $rendererData,587 [588 'namespace' => 'namespace_value',589 'static_type' => 'static_type_value',590 'dynamic_type' => 'dynamic_type_value',591 ],592 [593 'type' => 'type_value',594 'template' => 'template.phtml',595 'data' => ['some' => 'data'],596 ],597 ],598 ];599 }600 /**601 * @param string $xmlString602 * @param bool $result603 * @dataProvider isCacheableDataProvider604 */605 public function testIsCacheable($xmlString, $result)606 {607 $xml = simplexml_load_string($xmlString, 'Magento\Framework\View\Layout\Element');608 $this->assertSame($this->model, $this->model->setXml($xml));609 $this->assertSame($result, $this->model->isCacheable());610 }611 /**612 * @return array613 */614 public function isCacheableDataProvider()615 {616 return [617 [618 '<?xml version="1.0"?><layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'619 . '<block></block></layout>',620 true,621 ],622 [623 '<?xml version="1.0"?><layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'624 . '<block cacheable="false"></block></layout>',625 false626 ],627 ];628 }629 public function testGenerateElementsWithoutCache()630 {631 $this->readerContextFactoryMock->expects($this->once())632 ->method('create')633 ->willReturn($this->readerContextMock);634 $layoutCacheId = 'layout_cache_id';635 $handles = ['default', 'another'];636 /** @var \Magento\Framework\View\Layout\Element $xml */637 $xml = simplexml_load_string('<layout/>', 'Magento\Framework\View\Layout\Element');638 $this->model->setXml($xml);639 $themeMock = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface');640 $this->themeResolverMock->expects($this->once())641 ->method('get')642 ->willReturn($themeMock);643 $this->processorFactoryMock->expects($this->once())644 ->method('create')645 ->with(['theme' => $themeMock])646 ->willReturn($this->processorMock);647 $this->processorMock->expects($this->once())648 ->method('getCacheId')649 ->willReturn($layoutCacheId);650 $this->processorMock->expects($this->once())651 ->method('getHandles')652 ->willReturn($handles);653 $this->cacheMock->expects($this->once())654 ->method('load')655 ->with('structure_' . $layoutCacheId)656 ->willReturn(false);657 $this->readerPoolMock->expects($this->once())658 ->method('interpret')659 ->with($this->readerContextMock, $xml)660 ->willReturnSelf();661 $this->cacheMock->expects($this->once())662 ->method('save')663 ->with(serialize($this->readerContextMock), 'structure_' . $layoutCacheId, $handles)664 ->willReturn(true);665 $generatorContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Generator\Context')666 ->disableOriginalConstructor()667 ->getMock();668 $this->generatorContextFactoryMock->expects($this->once())669 ->method('create')670 ->with(['structure' => $this->structureMock, 'layout' => $this->model])671 ->willReturn($generatorContextMock);672 $this->generatorPoolMock->expects($this->once())673 ->method('process')674 ->with($this->readerContextMock, $generatorContextMock)675 ->willReturn(true);676 $elements = [677 'name_1' => ['type' => '', 'parent' => null],678 'name_2' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => null],679 'name_3' => ['type' => '', 'parent' => 'parent'],680 'name_4' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => 'parent'],681 ];682 $this->structureMock->expects($this->once())683 ->method('exportElements')684 ->willReturn($elements);685 $this->model->generateElements();686 }687 public function testGenerateElementsWithCache()688 {689 $layoutCacheId = 'layout_cache_id';690 /** @var \Magento\Framework\View\Layout\Element $xml */691 $xml = simplexml_load_string('<layout/>', 'Magento\Framework\View\Layout\Element');692 $this->model->setXml($xml);693 $themeMock = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface');694 $this->themeResolverMock->expects($this->once())695 ->method('get')696 ->willReturn($themeMock);697 $this->processorFactoryMock->expects($this->once())698 ->method('create')699 ->with(['theme' => $themeMock])700 ->willReturn($this->processorMock);701 $this->processorMock->expects($this->once())702 ->method('getCacheId')703 ->willReturn($layoutCacheId);704 $readerContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context')705 ->disableOriginalConstructor()706 ->getMock();707 $this->cacheMock->expects($this->once())708 ->method('load')709 ->with('structure_' . $layoutCacheId)710 ->willReturn(serialize($readerContextMock));711 $this->readerPoolMock->expects($this->never())712 ->method('interpret');713 $this->cacheMock->expects($this->never())714 ->method('save');715 $generatorContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Generator\Context')716 ->disableOriginalConstructor()717 ->getMock();718 $this->generatorContextFactoryMock->expects($this->once())719 ->method('create')720 ->with(['structure' => $this->structureMock, 'layout' => $this->model])721 ->willReturn($generatorContextMock);722 $this->generatorPoolMock->expects($this->once())723 ->method('process')724 ->with($readerContextMock, $generatorContextMock)725 ->willReturn(true);726 $elements = [727 'name_1' => ['type' => '', 'parent' => null],728 'name_2' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => null],729 'name_3' => ['type' => '', 'parent' => 'parent'],730 'name_4' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => 'parent'],731 ];732 $this->structureMock->expects($this->once())733 ->method('exportElements')734 ->willReturn($elements);735 $this->model->generateElements();736 }737 public function testGetXml()738 {739 $xml = '<layout/>';740 $this->assertSame($xml, \Magento\Framework\View\Layout::LAYOUT_NODE);741 }742 /**743 * @param mixed $displayValue744 * @dataProvider renderElementDisplayDataProvider745 */746 public function testRenderElementDisplay($displayValue)747 {748 $name = 'test_container';749 $child = 'child_block';750 $children = [$child => true];751 $blockHtml = '<html/>';752 $this->structureMock->expects($this->atLeastOnce())753 ->method('getAttribute')754 ->willReturnMap(755 [756 [$name, 'display', $displayValue],757 [$child, 'display', $displayValue],758 [$child, 'type', \Magento\Framework\View\Layout\Element::TYPE_BLOCK]759 ]760 );761 $this->structureMock->expects($this->atLeastOnce())->method('hasElement')762 ->willReturnMap(763 [764 [$child, true]765 ]766 );767 $this->structureMock->expects($this->once())768 ->method('getChildren')769 ->with($name)770 ->willReturn($children);771 $block = $this->getMock('Magento\Framework\View\Element\AbstractBlock', [], [], '', false);772 $block->expects($this->once())->method('toHtml')->willReturn($blockHtml);773 $renderingOutput = new \Magento\Framework\DataObject();774 $renderingOutput->setData('output', $blockHtml);775 $this->eventManagerMock->expects($this->at(0))776 ->method('dispatch')777 ->with(778 'core_layout_render_element',779 ['element_name' => $child, 'layout' => $this->model, 'transport' => $renderingOutput]780 );781 $this->eventManagerMock->expects($this->at(1))782 ->method('dispatch')783 ->with(784 'core_layout_render_element',785 ['element_name' => $name, 'layout' => $this->model, 'transport' => $renderingOutput]786 );787 $this->model->setBlock($child, $block);788 $this->assertEquals($blockHtml, $this->model->renderElement($name, false));789 }790 /**791 * @param mixed $displayValue792 * @dataProvider renderElementDoNotDisplayDataProvider793 */794 public function testRenderElementDoNotDisplay($displayValue)795 {796 $displayValue = 'false';797 $name = 'test_container';798 $blockHtml = '';799 $this->structureMock->expects($this->atLeastOnce())800 ->method('getAttribute')801 ->willReturnMap([[$name, 'display', $displayValue]]);802 $this->assertEquals($blockHtml, $this->model->renderElement($name, false));803 }804 /**805 * @return array806 */807 public function renderElementDoNotDisplayDataProvider()808 {809 return [810 ['false'],811 ['0'],812 [0]813 ];814 }815 /**816 * @return array817 */818 public function renderElementDisplayDataProvider()819 {820 return [821 [true],822 ['1'],823 [1],824 ['true'],825 [false],826 [null]827 ];828 }829}...

Full Screen

Full Screen

SubscriptionTest.php

Source:SubscriptionTest.php Github

copy

Full Screen

...8use \Magento\Framework\Mview\View\Subscription;9class SubscriptionTest extends \PHPUnit_Framework_TestCase10{11 /**12 * Mysql PDO DB adapter mock13 *14 * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DB\Adapter\Pdo\Mysql15 */16 protected $connectionMock;17 /** @var \Magento\Framework\Mview\View\Subscription */18 protected $model;19 /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\ResourceConnection */20 protected $resourceMock;21 /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DB\Ddl\TriggerFactory */22 protected $triggerFactoryMock;23 /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Mview\View\CollectionInterface */24 protected $viewCollectionMock;25 /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Mview\ViewInterface */26 protected $viewMock;...

Full Screen

Full Screen

mock

Using AI Code Generation

copy

Full Screen

1$mock = $this->getMock('name', array('method1', 'method2'));2$mock->expects($this->any())3->method('method1')4->will($this->returnValue('value'));5$mock->expects($this->any())6->method('method2')7->will($this->returnValue('value'));8$mock = $this->getMock('name', array('method1', 'method2'));9$mock->expects($this->any())10->method('method1')11->will($this->returnValue('value'));12$mock->expects($this->any())13->method('method2')14->will($this->returnValue('value'));15$mock = $this->getMock('name', array('method1', 'method2'));16$mock->expects($this->any())17->method('method1')18->will($this->returnValue('value'));19$mock->expects($this->any())20->method('method2')21->will($this->returnValue('value'));22$mock = $this->getMock('name', array('method1', 'method2'));23$mock->expects($this->any())24->method('method1')25->will($this->returnValue('value'));26$mock->expects($this->any())27->method('method2')28->will($this->returnValue('value'));

Full Screen

Full Screen

mock

Using AI Code Generation

copy

Full Screen

1$obj = new name();2$obj->method();3$obj = new name();4$obj->method();5$obj = new name();6$obj->method();7$obj = new name();8$obj->method();9Now, if you want to change the behavior of method() in 1.php, you can modify the mock method of name class. The same applies to 2.php

Full Screen

Full Screen

mock

Using AI Code Generation

copy

Full Screen

1$mock = $this->getMockBuilder('class')2->setMethods(array('name'))3->getMock();4$mock->expects($this->any())5->method('name')6->will($this->returnValue('test'));7$this->assertEquals('test', $mock->name());8$mock = $this->getMockBuilder('class')9->setMethods(array('name'))10->getMock();11$mock->expects($this->any())12->method('name')13->will($this->returnValue('test'));14$this->assertEquals('test', $mock->name());15$mock = $this->getMockBuilder('class')16->setMethods(array('name'))17->getMock();18$mock->expects($this->any())19->method('name')20->will($this->returnValue('test'));21$this->assertEquals('test', $mock->name());22$mock = $this->getMockBuilder('class')23->setMethods(array('name'))24->getMock();25$mock->expects($this->any())26->method('name')27->will($this->returnValue('test'));28$this->assertEquals('test', $mock->name());29$mock = $this->getMockBuilder('class')30->setMethods(array('name'))31->getMock();32$mock->expects($this->any())33->method('name')34->will($this->returnValue('test'));35$this->assertEquals('test', $mock->name());36$mock = $this->getMockBuilder('class')37->setMethods(array('name'))38->getMock();39$mock->expects($this->any())40->method('name')41->will($this->returnValue('test'));42$this->assertEquals('test', $mock->name());43$mock = $this->getMockBuilder('class')44->setMethods(array('name'))45->getMock();46$mock->expects($this->any())47->method('name')48->will($this->returnValue('test'));49$this->assertEquals('test', $mock->name());

Full Screen

Full Screen

mock

Using AI Code Generation

copy

Full Screen

1require_once 'name.php';2{3 public function testGetName()4 {5 $name = $this->getMock('name');6 $name->expects($this->any())7 ->method('getName')8 ->will($this->returnValue('John'));9 $this->assertEquals('John', $name->getName());10 }11}12{13 public function getName()14 {15 return 'John';16 }17}

Full Screen

Full Screen

mock

Using AI Code Generation

copy

Full Screen

1$mock = $this->getMockBuilder('name')->getMock();2$mock->expects($this->once())->method('method')->will($this->returnValue('value'));3$mock = $this->getMockBuilder('name')->getMock();4$mock->expects($this->once())->method('method')->will($this->returnValue('value'));5$mock = $this->getMockBuilder('name')->getMock();6$mock->expects($this->once())->method('method')->will($this->returnValue('value'));7$mock = $this->getMockBuilder('name')->getMock();8$mock->expects($this->once())->method('method')->will($this->returnValue('value'));9$mock = $this->getMockBuilder('name')->getMock();10$mock->expects($this->once())->method('method')->will($this->returnValue('value'));11$mock = $this->getMockBuilder('name')->getMock();12$mock->expects($this->once())->method('method')->will($this->returnValue('value'));13$mock = $this->getMockBuilder('name')->getMock();14$mock->expects($this->once())->method('method')->will($this->returnValue('value'));15$mock = $this->getMockBuilder('name')->getMock();16$mock->expects($this->once())->method('method')->will($this->returnValue('value'));17$mock = $this->getMockBuilder('name')->getMock();18$mock->expects($this->once())->method('method')->will($this->returnValue('value'));19$mock = $this->getMockBuilder('name')->getMock();20$mock->expects($this->once())->method('method')->will($this->returnValue('value'));21$mock = $this->getMockBuilder('name')->getMock();22$mock->expects($this->once())->method('method')->will($this->returnValue('value'));

Full Screen

Full Screen

mock

Using AI Code Generation

copy

Full Screen

1$mock = $this->getMockBuilder('name')->setMethods(array('method1'))->getMock();2$mock->expects($this->any())->method('method1')->will($this->returnValue('ok'));3$this->assertEquals('ok', $mock->method1());4$mock = $this->getMockBuilder('name')->setMethods(array('method2'))->getMock();5$mock->expects($this->any())->method('method2')->will($this->returnValue('ok'));6$this->assertEquals('ok', $mock->method2());7$mock = $this->getMockBuilder('name')->setMethods(array('method3'))->getMock();8$mock->expects($this->any())->method('method3')->will($this->returnValue('ok'));9$this->assertEquals('ok', $mock->method3());10$mock = $this->getMockBuilder('name')->setMethods(array('method4'))->getMock();11$mock->expects($this->any())->method('method4')->will($this->returnValue('ok'));12$this->assertEquals('ok', $mock->method4());13$mock = $this->getMockBuilder('name')->setMethods(array('method5'))->getMock();14$mock->expects($this->any())->method('method5')->will($this->returnValue('ok'));15$this->assertEquals('ok', $mock->method5());16$mock = $this->getMockBuilder('name')->setMethods(array('method6'))->getMock();17$mock->expects($this->any())->method('method6')->will($this->returnValue('ok'));18$this->assertEquals('ok', $mock->method6());19$mock = $this->getMockBuilder('name')->setMethods(array('method7'))->getMock();20$mock->expects($this->any())->method('method7')->will($this->returnValue('ok'));21$this->assertEquals('ok', $mock->method7());22$mock = $this->getMockBuilder('

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mockery automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger mock code on LambdaTest Cloud Grid

Execute automation tests with mock on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful