BackupFactoryTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backup\Test\Unit\Model;
  7. class BackupFactoryTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Backup\Model\BackupFactory
  11. */
  12. protected $_instance;
  13. /**
  14. * @var \Magento\Framework\ObjectManagerInterface
  15. */
  16. protected $_objectManager;
  17. /**
  18. * @var \Magento\Backup\Model\Fs\Collection
  19. */
  20. protected $_fsCollection;
  21. /**
  22. * @var \Magento\Backup\Model\Backup
  23. */
  24. protected $_backupModel;
  25. /**
  26. * @var array
  27. */
  28. protected $_data;
  29. protected function setUp()
  30. {
  31. $this->_data = [
  32. 'id' => '1385661590_snapshot',
  33. 'time' => 1385661590,
  34. 'path' => 'C:\test\test\var\backups',
  35. 'name' => '',
  36. 'type' => 'snapshot',
  37. ];
  38. $this->_fsCollection = $this->createMock(\Magento\Backup\Model\Fs\Collection::class);
  39. $this->_fsCollection->expects(
  40. $this->at(0)
  41. )->method(
  42. 'getIterator'
  43. )->will(
  44. $this->returnValue(new \ArrayIterator([new \Magento\Framework\DataObject($this->_data)]))
  45. );
  46. $this->_backupModel = $this->createMock(\Magento\Backup\Model\Backup::class);
  47. $this->_objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  48. $this->_objectManager->expects(
  49. $this->at(0)
  50. )->method(
  51. 'create'
  52. )->with(
  53. \Magento\Backup\Model\Fs\Collection::class
  54. )->will(
  55. $this->returnValue($this->_fsCollection)
  56. );
  57. $this->_objectManager->expects(
  58. $this->at(1)
  59. )->method(
  60. 'create'
  61. )->with(
  62. \Magento\Backup\Model\Backup::class
  63. )->will(
  64. $this->returnValue($this->_backupModel)
  65. );
  66. $this->_instance = new \Magento\Backup\Model\BackupFactory($this->_objectManager);
  67. }
  68. public function testCreate()
  69. {
  70. $this->_backupModel->expects($this->once())
  71. ->method('setType')
  72. ->with($this->_data['type'])
  73. ->will($this->returnSelf());
  74. $this->_backupModel->expects($this->once())
  75. ->method('setTime')
  76. ->with($this->_data['time'])
  77. ->will($this->returnSelf());
  78. $this->_backupModel->expects($this->once())
  79. ->method('setName')
  80. ->with($this->_data['name'])
  81. ->will($this->returnSelf());
  82. $this->_backupModel->expects($this->once())
  83. ->method('setPath')
  84. ->with($this->_data['path'])
  85. ->will($this->returnSelf());
  86. $this->_backupModel->expects($this->once())
  87. ->method('setData')
  88. ->will($this->returnSelf());
  89. $this->_instance->create('1385661590', 'snapshot');
  90. }
  91. public function testCreateInvalid()
  92. {
  93. $this->_backupModel->expects($this->never())->method('setType');
  94. $this->_backupModel->expects($this->never())->method('setTime');
  95. $this->_backupModel->expects($this->never())->method('setName');
  96. $this->_backupModel->expects($this->never())->method('setPath');
  97. $this->_instance->create('451094400', 'snapshot');
  98. }
  99. }