AbstractCommandTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Test\Unit\Model\Menu\Builder;
  7. class AbstractCommandTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Backend\Model\Menu\Builder\AbstractCommand
  11. */
  12. protected $_model;
  13. protected function setUp()
  14. {
  15. $this->_model = $this->getMockForAbstractClass(
  16. \Magento\Backend\Model\Menu\Builder\AbstractCommand::class,
  17. [['id' => 'item']]
  18. );
  19. }
  20. /**
  21. * @expectedException \InvalidArgumentException
  22. */
  23. public function testConstructorRequiresObligatoryParams()
  24. {
  25. $this->getMockForAbstractClass(\Magento\Backend\Model\Menu\Builder\AbstractCommand::class);
  26. }
  27. public function testChainAddsNewCommandAsNextInChain()
  28. {
  29. $command1 = $this->getMockBuilder(\Magento\Backend\Model\Menu\Builder\Command\Update::class)
  30. ->setConstructorArgs([['id' => 1]])
  31. ->getMock();
  32. $command2 = $this->getMockBuilder(\Magento\Backend\Model\Menu\Builder\Command\Remove::class)
  33. ->setConstructorArgs([['id' => 1]])
  34. ->getMock();
  35. $command1->expects($this->once())->method('chain')->with($this->equalTo($command2));
  36. $this->_model->chain($command1);
  37. $this->_model->chain($command2);
  38. }
  39. public function testExecuteCallsNextCommandInChain()
  40. {
  41. $itemParams = [];
  42. $this->_model->expects(
  43. $this->once()
  44. )->method(
  45. '_execute'
  46. )->with(
  47. $this->equalTo($itemParams)
  48. )->will(
  49. $this->returnValue($itemParams)
  50. );
  51. $command1 = $this->getMockBuilder(\Magento\Backend\Model\Menu\Builder\Command\Update::class)
  52. ->setConstructorArgs([['id' => 1]])
  53. ->getMock();
  54. $command1->expects(
  55. $this->once()
  56. )->method(
  57. 'execute'
  58. )->with(
  59. $this->equalTo($itemParams)
  60. )->will(
  61. $this->returnValue($itemParams)
  62. );
  63. $this->_model->chain($command1);
  64. $this->assertEquals($itemParams, $this->_model->execute($itemParams));
  65. }
  66. }