AbstractTestCase.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Test\Unit\Controller\Adminhtml\Dashboard;
  7. /**
  8. * Abstract test class
  9. */
  10. class AbstractTestCase extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * Assertions for controller execute method
  14. *
  15. * @param $controllerName
  16. * @param $blockName
  17. */
  18. protected function assertExecute($controllerName, $blockName)
  19. {
  20. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  21. $outPut = "data";
  22. $resultRawMock = $this->createPartialMock(\Magento\Framework\Controller\Result\Raw::class, ['setContents'])
  23. ;
  24. $resultRawFactoryMock =
  25. $this->createPartialMock(\Magento\Framework\Controller\Result\RawFactory::class, ['create']);
  26. $layoutFactoryMock = $this->createPartialMock(\Magento\Framework\View\LayoutFactory::class, ['create']);
  27. $layoutMock = $this->createPartialMock(\Magento\Framework\View\Layout::class, ['createBlock', 'toHtml']);
  28. $layoutFactoryMock->expects($this->once())->method('create')->will($this->returnValue($layoutMock));
  29. $layoutMock->expects($this->once())->method('createBlock')->with($blockName)->will($this->returnSelf());
  30. $layoutMock->expects($this->once())->method('toHtml')->will($this->returnValue($outPut));
  31. $resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRawMock));
  32. $resultRawMock->expects($this->once())->method('setContents')->with($outPut)->will($this->returnSelf());
  33. $controller = $objectManager->getObject(
  34. $controllerName,
  35. [
  36. 'resultRawFactory' => $resultRawFactoryMock,
  37. 'layoutFactory' => $layoutFactoryMock
  38. ]
  39. );
  40. $result = $controller->execute();
  41. $this->assertInstanceOf(\Magento\Framework\Controller\Result\Raw::class, $result);
  42. }
  43. }