public function testCreateFromLog() { $contents = ['[Progress: 1 / 5] Installing A...', 'Output from A...', '[Progress: 2 / 5] Installing B...', 'Output from B...', '[Progress: 3 / 5] Installing C...', 'Output from C...']; $logger = $this->getMock('Magento\\Setup\\Model\\WebLogger', [], [], '', false); $logger->expects($this->once())->method('get')->will($this->returnValue($contents)); $progressFactory = new ProgressFactory(); $progress = $progressFactory->createFromLog($logger); $this->assertEquals(3, $progress->getCurrent()); $this->assertEquals(5, $progress->getTotal()); }
/** * Checks progress of installation * * @return JsonModel */ public function progressAction() { $percent = 0; $success = false; $contents = []; $json = new JsonModel(); // Depending upon the install environment and network latency, there is a possibility that // "progress" check request may arrive before the Install POST request. In that case // "install.log" file may not be created yet. Check the "install.log" is created before // trying to read from it. if (!$this->log->logfileExists()) { return $json->setVariables(['progress' => $percent, 'success' => true, 'console' => $contents]); } try { $progress = $this->progressFactory->createFromLog($this->log); $percent = sprintf('%d', $progress->getRatio() * 100); $success = true; $contents = $this->log->get(); if ($this->sampleDataState->hasError()) { $json->setVariable('isSampleDataError', true); } } catch (\Exception $e) { $contents = [(string) $e]; } return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]); }
public function testProgressActionWithSampleDataError() { $this->progressFactory->expects($this->once())->method('createFromLog') ->willThrowException($this->getMock('\Magento\Setup\SampleDataException')); $jsonModel = $this->controller->progressAction(); $this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); $this->assertArrayHasKey('success', $variables); $this->assertArrayHasKey('console', $variables); $this->assertFalse($variables['success']); $this->assertTrue($jsonModel->getVariable('isSampleDataError')); }
public function testProgressActionWithError() { $e = 'Some exception message'; $this->progressFactory->expects($this->once())->method('createFromLog')->will($this->throwException(new \LogicException($e))); $jsonModel = $this->controller->progressAction(); $this->assertInstanceOf('\\Zend\\View\\Model\\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); $this->assertArrayHasKey('success', $variables); $this->assertArrayHasKey('console', $variables); $this->assertFalse($variables['success']); $this->assertStringStartsWith('exception \'LogicException\' with message \'' . $e, $variables['console'][0]); }
/** * Checks progress of installation * * @return JsonModel */ public function progressAction() { $percent = 0; $success = false; try { $progress = $this->progressFactory->createFromLog($this->log); $percent = sprintf('%d', $progress->getRatio() * 100); $success = true; $contents = $this->log->get(); } catch (\Exception $e) { $contents = [(string) $e]; } return new JsonModel(['progress' => $percent, 'success' => $success, 'console' => $contents]); }
public function testProgressActionWithSampleDataError() { $numValue = 42; $progress = $this->getMock('\\Magento\\Setup\\Model\\Installer\\Progress', [], [], '', false); $progress->expects($this->once())->method('getRatio')->willReturn($numValue); $this->progressFactory->expects($this->once())->method('createFromLog')->willReturn($progress); $this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true); $jsonModel = $this->controller->progressAction(); $this->assertInstanceOf('\\Zend\\View\\Model\\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); $this->assertArrayHasKey('success', $variables); $this->assertArrayHasKey('console', $variables); $this->assertTrue($variables['success']); $this->assertTrue($jsonModel->getVariable('isSampleDataError')); $this->assertSame(sprintf('%d', $numValue * 100), $variables['progress']); }
/** * Checks progress of installation * * @return JsonModel */ public function progressAction() { $percent = 0; $success = false; $json = new JsonModel(); try { $progress = $this->progressFactory->createFromLog($this->log); $percent = sprintf('%d', $progress->getRatio() * 100); $success = true; $contents = $this->log->get(); } catch (\Exception $e) { $contents = [(string)$e]; if ($e instanceof \Magento\Setup\SampleDataException) { $json->setVariable('isSampleDataError', true); } } return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]); }