/**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The following requested cache types are not supported:
  */
 public function testExecuteInvalidCacheType()
 {
     $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
     $param = ['types' => ['A', 'D']];
     $commandTester = new CommandTester($this->command);
     $commandTester->execute($param);
 }
Example #2
0
 public function testExecuteAllCacheType()
 {
     $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
     $this->cacheManager->expects($this->once())->method('clean')->with(['A', 'B', 'C']);
     $param = ['--all' => true];
     $commandTester = new CommandTester($this->command);
     $commandTester->execute($param);
     $expect = 'Cleaned cache types:' . PHP_EOL . 'A' . PHP_EOL . 'B' . PHP_EOL . 'C' . PHP_EOL;
     $this->assertEquals($expect, $commandTester->getDisplay());
 }
 public function testLaunchAll()
 {
     $requestArgs = [ManagerApp::KEY_SET => true, ManagerApp::KEY_FLUSH => true, ManagerApp::KEY_CLEAN => true, ManagerApp::KEY_TYPES => 'foo,baz'];
     $this->cacheManager->expects($this->once())->method('setEnabled')->with(['foo', 'baz'], true)->will($this->returnValue(['baz']));
     $this->cacheManager->expects($this->once())->method('flush')->with(['foo', 'baz']);
     $this->cacheManager->expects($this->never())->method('clean');
     $this->response->expects($this->once())->method('setBody')->with($this->matches("Changed cache status:\n%abaz: 0 -> 1%aFlushed cache types:\nfoo\nbaz"));
     $model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
     $model->launch();
 }
 public function testExecute()
 {
     $cacheTypes = ['A' => 0, 'B' => 1, 'C' => 1];
     $this->cacheManager->expects($this->once())->method('getStatus')->willReturn($cacheTypes);
     $commandTester = new CommandTester($this->command);
     $commandTester->execute([]);
     $expect = 'Current status:' . PHP_EOL;
     foreach ($cacheTypes as $cacheType => $status) {
         $expect .= sprintf('%30s: %d', $cacheType, $status) . PHP_EOL;
     }
     $this->assertEquals($expect, $commandTester->getDisplay());
 }
 /**
  * Returns plugin list:
  * ['concrete class name' => ['plugin name' => [instance => 'instance name', 'order' => 'Order Number']]]
  *
  * @param array $interceptedInstances
  * @return array
  */
 private function getPluginsList($interceptedInstances)
 {
     $this->cacheManager->setEnabled([CompiledConfig::TYPE_IDENTIFIER], true);
     $this->pluginList->setInterceptedClasses($interceptedInstances);
     $inheritedConfig = [];
     foreach ($this->areaCodesList as $areaKey) {
         $scopePriority = [Area::AREA_GLOBAL];
         $pluginListCloned = clone $this->pluginList;
         if ($areaKey != Area::AREA_GLOBAL) {
             $scopePriority[] = $areaKey;
             $pluginListCloned->setScopePriorityScheme($scopePriority);
         }
         $key = implode('', $scopePriority);
         $inheritedConfig[$key] = $this->filterNullInheritance($pluginListCloned->getPluginsConfig());
     }
     return $inheritedConfig;
 }
Example #6
0
 /**
  * Maps requested type from request into the current registry of types
  *
  * @return string[]
  * @throws \InvalidArgumentException
  */
 private function getRequestedTypes()
 {
     $requestedTypes = [];
     if (isset($this->requestArgs[self::KEY_TYPES])) {
         $requestedTypes = explode(',', $this->requestArgs[self::KEY_TYPES]);
         $requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen');
     }
     $availableTypes = $this->cacheManager->getAvailableTypes();
     if (empty($requestedTypes)) {
         return $availableTypes;
     } else {
         $unsupportedTypes = array_diff($requestedTypes, $availableTypes);
         if ($unsupportedTypes) {
             throw new \InvalidArgumentException("The following requested cache types are not supported: '" . join("', '", $unsupportedTypes) . "'.\nSupported types: " . join(", ", $availableTypes) . "");
         }
         return array_values(array_intersect($availableTypes, $requestedTypes));
     }
 }
Example #7
0
 public function testGetAvailableTypes()
 {
     $types = [['id' => 'foo', 'status' => true], ['id' => 'bar', 'status' => false]];
     $this->cacheTypeList->expects($this->once())->method('getTypes')->willReturn($types);
     $this->assertSame(['foo', 'bar'], $this->model->getAvailableTypes());
 }