10 use PHPUnit\Framework\TestCase;
11 use Symfony\Component\Console\Output\OutputInterface;
20 $maintenanceMode = $this->createMaintenanceMode($maintenanceModeEnabledInitially);
22 $successTask =
function () {
26 $enabler->executeInMaintenanceMode(
28 $this->createOutput(),
33 $maintenanceModeEnabledInitially,
34 $maintenanceMode->isOn(),
35 'Initial state is not restored' 44 $maintenanceMode = $this->createMaintenanceMode($maintenanceModeEnabledInitially);
46 $failedTask =
function () {
47 throw new \Exception(
'Woops!');
51 $enabler->executeInMaintenanceMode(
53 $this->createOutput(),
56 }
catch (\Exception $e) {
59 $maintenanceMode->isOn(),
60 'Maintenance mode is not active after failure' 70 $maintenanceMode = $this->createMaintenanceMode($maintenanceModeEnabledInitially);
72 $failedTask =
function () {
73 throw new \Exception(
'Woops!');
77 $enabler->executeInMaintenanceMode(
79 $this->createOutput(),
82 }
catch (\Exception $e) {
84 $maintenanceModeEnabledInitially,
85 $maintenanceMode->isOn(),
86 'Initial state is not restored' 97 'Maintenance mode disabled initially' => [
false],
98 'Maintenance mode enabled initially' => [
true],
108 $maintenanceMode = $this->getMockBuilder(MaintenanceMode::class)
109 ->disableOriginalConstructor()
112 $maintenanceMode->method(
'isOn')->willReturnCallback(
function () use (&$isOn) {
115 $maintenanceMode->method(
'set')->willReturnCallback(
function ($newValue) use (&$isOn) {
116 $isOn = (bool)$newValue;
120 return $maintenanceMode;
126 private function createOutput(): OutputInterface
128 $output = $this->getMockBuilder(OutputInterface::class)
129 ->getMockForAbstractClass();
testFailedTaskWithMaintenanceModeOnFailure(bool $maintenanceModeEnabledInitially)
testSuccessfulTask(bool $maintenanceModeEnabledInitially)
testFailedTaskWithRestoredModeOnFailure(bool $maintenanceModeEnabledInitially)
initialAppStateProvider()