PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/update/dev/tests/integration/testsuite/Magento/Update/Queue/JobBackupTest.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 92 lines | 72 code | 13 blank | 7 comment | 7 complexity | e0791b77aae4f2a8883c32da53c6cd59 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Update\Queue;
  7. use Magento\Update\MaintenanceMode;
  8. class JobBackupTest extends \PHPUnit_Framework_TestCase
  9. {
  10. /** @var string */
  11. protected $backupFilename;
  12. /** @var string */
  13. protected $backupPath;
  14. /** @var array */
  15. protected $dirList = [];
  16. protected function setUp()
  17. {
  18. parent::setUp();
  19. $this->backupFilename = uniqid('test_backup') . '.zip';
  20. $this->backupPath = TESTS_TEMP_DIR . '/backup/';
  21. if (!is_dir($this->backupPath)) {
  22. mkdir($this->backupPath);
  23. }
  24. }
  25. protected function tearDown()
  26. {
  27. if (is_dir($this->backupPath)) {
  28. rmdir($this->backupPath);
  29. }
  30. if (file_exists(TESTS_TEMP_DIR . '/maintenanceMode.flag')) {
  31. unlink(TESTS_TEMP_DIR . '/maintenanceMode.flag');
  32. }
  33. if (file_exists(TESTS_TEMP_DIR . '/maintenanceAddress.flag')) {
  34. unlink(TESTS_TEMP_DIR . '/maintenanceAddress.flag');
  35. }
  36. parent::tearDown();
  37. }
  38. public function testArchive()
  39. {
  40. if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
  41. $this->markTestSkipped();
  42. }
  43. $jobName = 'Backup';
  44. $jobStatus = new \Magento\Update\Status();
  45. $jobStatus->clear();
  46. $backupInfo = $this->getMockBuilder('Magento\Update\Backup\BackupInfo')
  47. ->disableOriginalConstructor()
  48. ->getMock();
  49. $backupInfo->expects($this->any())
  50. ->method('generateBackupFilename')
  51. ->willReturn($this->backupFilename);
  52. $backupInfo->expects($this->any())
  53. ->method('getArchivedDirectory')
  54. ->willReturn(UPDATER_BP);
  55. $backupInfo->expects($this->any())
  56. ->method('getBlacklist')
  57. ->willReturn(['var/backup', 'vendor', 'app/code']);
  58. $backupInfo->expects($this->any())
  59. ->method('getBackupPath')
  60. ->willReturn($this->backupPath);
  61. $maintenanceMode = new MaintenanceMode(
  62. TESTS_TEMP_DIR . '/maintenanceMode.flag',
  63. TESTS_TEMP_DIR . '/maintenanceAddress.flag'
  64. );
  65. $jobBackup = new \Magento\Update\Queue\JobBackup($jobName, [], $jobStatus, $maintenanceMode, $backupInfo);
  66. $this->dirList = scandir($this->backupPath);
  67. $jobBackup->execute();
  68. $tmpFiles = array_diff(scandir($this->backupPath), $this->dirList);
  69. $actualBackupFile = array_pop($tmpFiles);
  70. $this->assertEquals($this->backupFilename, $actualBackupFile);
  71. $actualJobStatus = $jobStatus->get();
  72. $fullBackupFileName = $this->backupPath . $this->backupFilename;
  73. $this->assertContains(sprintf('Creating backup archive "%s" ...', $fullBackupFileName), $actualJobStatus);
  74. $this->assertContains(sprintf('Backup archive "%s" has been created.', $fullBackupFileName), $actualJobStatus);
  75. if (file_exists($this->backupPath . $actualBackupFile)) {
  76. unlink($this->backupPath . $actualBackupFile);
  77. }
  78. }
  79. }