Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into PR-Vanilla-Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirZaets committed Jul 19, 2016
2 parents 259ff1c + f262529 commit 7b04b5c
Show file tree
Hide file tree
Showing 19 changed files with 916 additions and 121 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Backup/Cron/SystemBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function __construct(
* Create Backup
*
* @return $this
* @throws \Exception
*/
public function execute()
{
Expand Down Expand Up @@ -138,8 +139,7 @@ public function execute()
} catch (\Exception $e) {
$this->_errors[] = $e->getMessage();
$this->_errors[] = $e->getTrace();
$this->_logger->info($e->getMessage());
$this->_logger->critical($e);
throw $e;
}

if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
Expand Down
136 changes: 136 additions & 0 deletions app/code/Magento/Backup/Test/Unit/Cron/SystemBackupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backup\Test\Unit\Cron;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

class SystemBackupTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
private $objectManager;

/**
* @var \Magento\Backup\Cron\SystemBackup
*/
private $systemBackup;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $scopeConfigMock;

/**
* @var \Magento\Backup\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
*/
private $backupDataMock;

/**
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
*/
private $registryMock;

/**
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $loggerMock;

/**
* Filesystem facade
*
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
*/
private $filesystemMock;

/**
* @var \Magento\Framework\Backup\Factory|\PHPUnit_Framework_MockObject_MockObject
*/
private $backupFactoryMock;

/**
* @var \Magento\Framework\App\MaintenanceMode|\PHPUnit_Framework_MockObject_MockObject
*/
private $maintenanceModeMock;

/**
* @var \Magento\Framework\Backup\Db|\PHPUnit_Framework_MockObject_MockObject
*/
private $backupDbMock;

/**
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $objectManagerMock;

protected function setUp()
{
$this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
->getMock();
$this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
->getMock();
$this->backupDataMock = $this->getMockBuilder(\Magento\Backup\Helper\Data::class)
->disableOriginalConstructor()
->getMock();
$this->registryMock = $this->getMockBuilder(\Magento\Framework\Registry::class)
->disableOriginalConstructor()
->getMock();
$this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
->getMock();
$this->filesystemMock = $this->getMockBuilder(\Magento\Framework\Filesystem::class)
->disableOriginalConstructor()
->getMock();
$this->backupFactoryMock = $this->getMockBuilder(\Magento\Framework\Backup\Factory::class)
->disableOriginalConstructor()
->getMock();
$this->maintenanceModeMock = $this->getMockBuilder(\Magento\Framework\App\MaintenanceMode::class)
->disableOriginalConstructor()
->getMock();

$this->backupDbMock = $this->getMockBuilder(\Magento\Framework\Backup\Db::class)
->disableOriginalConstructor()
->getMock();
$this->backupDbMock->expects($this->any())->method('setBackupExtension')->willReturnSelf();
$this->backupDbMock->expects($this->any())->method('setTime')->willReturnSelf();
$this->backupDbMock->expects($this->any())->method('setBackupsDir')->willReturnSelf();

$this->objectManager = new ObjectManager($this);
$this->systemBackup = $this->objectManager->getObject(
\Magento\Backup\Cron\SystemBackup::class,
[
'backupData' => $this->backupDataMock,
'coreRegistry' => $this->registryMock,
'logger' => $this->loggerMock,
'scopeConfig' => $this->scopeConfigMock,
'filesystem' => $this->filesystemMock,
'backupFactory' => $this->backupFactoryMock,
'maintenanceMode' => $this->maintenanceModeMock,
]
);
}

/**
* @expectedException \Exception
*/
public function testExecuteThrowsException()
{
$type = 'db';
$this->scopeConfigMock->expects($this->any())->method('isSetFlag')->willReturn(true);

$this->scopeConfigMock->expects($this->once())->method('getValue')
->with('system/backup/type', 'store')
->willReturn($type);

$this->backupFactoryMock->expects($this->once())->method('create')->willReturn($this->backupDbMock);

$this->backupDbMock->expects($this->once())->method('create')->willThrowException(new \Exception);

$this->backupDataMock->expects($this->never())->method('getCreateSuccessMessageByType')->with($type);
$this->loggerMock->expects($this->never())->method('info');

$this->systemBackup->execute();
}
}
38 changes: 35 additions & 3 deletions app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace Magento\Cron\Observer;

use Magento\Framework\App\State;
use Magento\Framework\Console\CLI;
use Magento\Framework\Event\ObserverInterface;
use \Magento\Cron\Model\Schedule;
Expand Down Expand Up @@ -105,16 +106,28 @@ class ProcessCronQueueObserver implements ObserverInterface
*/
protected $phpExecutableFinder;

/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;

/**
* @var \Magento\Framework\App\State
*/
private $state;

/**
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param ScheduleFactory $scheduleFactory
* @param \Magento\Cron\Model\ScheduleFactory $scheduleFactory
* @param \Magento\Framework\App\CacheInterface $cache
* @param ConfigInterface $config
* @param \Magento\Cron\Model\ConfigInterface $config
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Framework\App\Console\Request $request
* @param \Magento\Framework\ShellInterface $shell
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
* @param \Magento\Framework\Process\PhpExecutableFinderFactory $phpExecutableFinderFactory
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\App\State $state
*/
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
Expand All @@ -125,7 +138,9 @@ public function __construct(
\Magento\Framework\App\Console\Request $request,
\Magento\Framework\ShellInterface $shell,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
\Magento\Framework\Process\PhpExecutableFinderFactory $phpExecutableFinderFactory
\Magento\Framework\Process\PhpExecutableFinderFactory $phpExecutableFinderFactory,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\App\State $state
) {
$this->_objectManager = $objectManager;
$this->_scheduleFactory = $scheduleFactory;
Expand All @@ -136,6 +151,8 @@ public function __construct(
$this->_shell = $shell;
$this->timezone = $timezone;
$this->phpExecutableFinder = $phpExecutableFinderFactory->create();
$this->logger = $logger;
$this->state = $state;
}

/**
Expand Down Expand Up @@ -196,6 +213,21 @@ public function execute(\Magento\Framework\Event\Observer $observer)
}
} catch (\Exception $e) {
$schedule->setMessages($e->getMessage());
if ($schedule->getStatus() === Schedule::STATUS_ERROR) {
$this->logger->critical($e);
}
if ($schedule->getStatus() === Schedule::STATUS_MISSED
&& $this->state->getMode() === State::MODE_DEVELOPER
) {
$this->logger->info(
sprintf(
"%s Schedule Id: %s Job Code: %s",
$schedule->getMessages(),
$schedule->getScheduleId(),
$schedule->getJobCode()
)
);
}
}
$schedule->save();
}
Expand Down
Loading

0 comments on commit 7b04b5c

Please sign in to comment.