/**
  * @param array $maintenanceData
  * @param string $expectedMessage
  * @dataProvider executeDataProvider
  */
 public function testExecute(array $maintenanceData, $expectedMessage)
 {
     $this->maintenanceMode->expects($this->once())->method('isOn')->willReturn($maintenanceData[0]);
     $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($maintenanceData[1]);
     $tester = new CommandTester($this->command);
     $tester->execute([]);
     $this->assertEquals($expectedMessage, $tester->getDisplay());
 }
 /**
  * @param array $input
  * @param string $expectedMessage
  * @dataProvider executeDataProvider
  */
 public function testExecute(array $input, $expectedMessage)
 {
     $return = isset($input['--ip']) ? $input['--ip'] !== ['none'] ? $input['--ip'] : [] : [];
     $this->maintenanceMode->expects($this->any())->method('getAddressInfo')->willReturn($return);
     $tester = new CommandTester($this->command);
     $tester->execute($input);
     $this->assertEquals($expectedMessage, $tester->getDisplay());
 }
예제 #3
0
 public function testIndexActionWithExceptions()
 {
     $this->maintenanceMode->expects($this->once())->method('set')->will($this->throwException(new \Exception("Test error message")));
     $jsonModel = $this->controller->indexAction();
     $this->assertInstanceOf('Zend\\View\\Model\\JsonModel', $jsonModel);
     $variables = $jsonModel->getVariables();
     $this->assertArrayHasKey('responseType', $variables);
     $this->assertEquals(ResponseTypeInterface::RESPONSE_TYPE_ERROR, $variables['responseType']);
     $this->assertArrayHasKey('error', $variables);
     $this->assertEquals("Test error message", $variables['error']);
 }
 /**
  * @param array $input
  * @param array $validatorMessages
  * @param string $expectedMessage
  * @dataProvider executeDataProvider
  */
 public function testExecute(array $input, array $validatorMessages, $expectedMessage)
 {
     if (isset($input['--none']) && !$input['--none'] && isset($input['ip'])) {
         $this->ipValidator->expects($this->once())->method('validateIps')->willReturn($validatorMessages);
         if (empty($validatorMessages) && !empty($input['ip'])) {
             $this->maintenanceMode->expects($this->once())->method('setAddresses')->with(implode(',', $input['ip']));
             $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($input['ip']);
         }
     } elseif (isset($input['--none']) && $input['--none']) {
         $this->ipValidator->expects($this->never())->method('validateIps')->willReturn($validatorMessages);
         $this->maintenanceMode->expects($this->once())->method('setAddresses')->with('');
     }
     $tester = new CommandTester($this->command);
     $tester->execute($input);
     $this->assertEquals($expectedMessage, $tester->getDisplay());
 }
 /**
  * @param array $addresses
  * @param int $logCount
  * @param int $setAddressesCount
  *
  * @dataProvider maintenanceActionWithAddressDataProvider
  */
 public function testMaintenanceActionWithAddress($addresses, $logCount, $setAddressesCount)
 {
     $mapGetParam = [['set', null, true], ['addresses', null, $addresses]];
     $this->request->expects($this->exactly(2))->method('getParam')->will($this->returnValueMap($mapGetParam));
     $this->maintenanceMode->expects($this->exactly(1))->method('set');
     $this->maintenanceMode->expects($this->exactly($setAddressesCount))->method('setAddresses');
     $this->maintenanceMode->expects($this->once())->method('isOn')->willReturn(true);
     $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($addresses);
     $this->consoleLogger->expects($this->exactly($logCount))->method('log');
     $this->controller->maintenanceAction();
 }