/** * {@inheritdoc} * @return Response * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function launch() { $output = []; $types = $this->getRequestedTypes(); $enabledTypes = []; if (isset($this->requestArgs[self::KEY_SET])) { $isEnabled = (bool) (int) $this->requestArgs[self::KEY_SET]; $changedTypes = $this->cacheManager->setEnabled($types, $isEnabled); if ($isEnabled) { $enabledTypes = $changedTypes; } if ($changedTypes) { $output[] = 'Changed cache status:'; foreach ($changedTypes as $type) { $output[] = sprintf('%30s: %d -> %d', $type, !$isEnabled, $isEnabled); } } else { $output[] = 'There is nothing to change in cache status'; } } if (isset($this->requestArgs[self::KEY_FLUSH])) { $this->cacheManager->flush($types); $output[] = 'Flushed cache types:'; $output[] = join("\n", $types); } elseif (isset($this->requestArgs[self::KEY_CLEAN])) { $this->cacheManager->clean($types); $output[] = 'Cleaned cache types:'; $output[] = join("\n", $types); } elseif (isset($this->requestArgs[self::KEY_STATUS])) { $output[] = 'Current status:'; foreach ($this->cacheManager->getStatus() as $cache => $status) { $output[] = sprintf('%30s: %d', $cache, $status); } } elseif (!empty($enabledTypes)) { $this->cacheManager->clean($enabledTypes); $output[] = 'Cleaned cache types:'; $output[] = join("\n", $enabledTypes); } $output[] = ''; $this->response->setBody(join("\n", $output)); return $this->response; }
public function testGetStatus() { $types = [['id' => 'foo', 'status' => true], ['id' => 'bar', 'status' => false]]; $this->cacheTypeList->expects($this->once())->method('getTypes')->willReturn($types); $this->assertSame(['foo' => true, 'bar' => false], $this->model->getStatus()); }