Esempio n. 1
0
 /**
  * @param $name
  * @param array $moduleData
  * @return Module
  */
 private function buildModule($name, array $moduleData)
 {
     $module = new Module();
     $module->setName($name);
     $module->setPackage($moduleData['package']);
     $module->setVersion($moduleData['version']);
     $module->setIsEnable(true);
     return $module;
 }
Esempio n. 2
0
 /**
  * @param Module $module
  * @return string
  */
 private function mapModule(Module $module)
 {
     $result = '';
     foreach ($module->toArray() as $property => $value) {
         if (is_scalar($value) || is_null($value)) {
             $result .= "{$property}: {$value}\n";
         }
     }
     return trim($result);
 }
Esempio n. 3
0
 /**
  * @param Module $module
  * @param $hasModule
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 private function provideModuleManager(Module $module, $hasModule)
 {
     $moduleManager = $this->getMockBuilder('Samurai\\Module\\ModuleManager')->disableOriginalConstructor()->getMock();
     $moduleManager->expects($this->once())->method('has')->with($module->getName())->will($this->returnValue($hasModule));
     if ($hasModule) {
         $moduleManager->expects($this->once())->method('get')->will($this->returnValue($module));
     } else {
         $moduleManager->expects($this->never())->method('get');
     }
     return $moduleManager;
 }
Esempio n. 4
0
 public function testExecute()
 {
     $modules = new Modules();
     $moduleA = new Module();
     $moduleA->setTasks(['Samurai\\Module\\resources\\TaskA', 'Samurai\\Module\\resources\\TaskB']);
     $modules[] = $moduleA;
     $moduleB = new Module();
     $moduleB->setTasks(['Samurai\\Module\\resources\\TaskC']);
     $modules[] = $moduleB;
     $input = new ArrayInput([]);
     $output = new BufferedOutput();
     $questionHelper = $this->getQuestionHelperMock();
     $adapter = new PlannerAdapter(new ModulesPlannerBuilder(new Container(), $modules, $questionHelper), $questionHelper);
     $this->assertSame(ITask::NO_ERROR_CODE, $adapter->execute($input, $output));
     $this->assertSame('ABC', $output->fetch());
 }
Esempio n. 5
0
 /**
  * @param Module $module
  * @return \Samurai\Module\ModuleManager
  */
 private function provideModuleManagerForNotExisting(Module $module)
 {
     $aliasManager = $this->getMockBuilder('Samurai\\Module\\ModuleManager')->disableOriginalConstructor()->getMock();
     $aliasManager->expects($this->once())->method('has')->with('my-module')->will($this->returnValue(false));
     $aliasManager->expects($this->never())->method('get');
     $aliasManager->expects($this->atLeastOnce())->method('getAll')->will($this->returnValue(new Modules([$module->getName() => $module])));
     return $aliasManager;
 }
Esempio n. 6
0
 /**
  * @param Module $newModule
  * @param $hasModule
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 private function provideModuleManager(Module $newModule, $hasModule)
 {
     $oldModule = clone $newModule;
     $oldModule->setDescription($newModule->getDescription() . '_old');
     $oldModule->setPackage($newModule->getPackage() . '_old');
     $oldModule->setVersion($newModule->getVersion() . '_old');
     $moduleManager = $this->getMockBuilder('Balloon\\Balloon')->disableOriginalConstructor()->getMock();
     $moduleManager->expects($this->once())->method('has')->with($newModule->getName())->will($this->returnValue($hasModule));
     $moduleManager->expects($this->any())->method('get')->with($newModule->getName())->will($this->returnValue($oldModule));
     return $moduleManager;
 }
Esempio n. 7
0
 /**
  * @return Modules
  */
 private function providesModules()
 {
     $modules = new Modules();
     $moduleA = new Module();
     $moduleA->setName('name of A');
     $moduleA->setIsEnable(true);
     $moduleA->setTasks(['Samurai\\Module\\resources\\TaskA', 'Samurai\\Module\\resources\\TaskB']);
     $modules[] = $moduleA;
     $moduleB = new Module();
     $moduleB->setName('name of B');
     $moduleB->setIsEnable(true);
     $moduleB->setTasks(['Samurai\\Module\\resources\\TaskB']);
     $modules[] = $moduleB;
     $moduleC = new Module();
     $moduleC->setName('name of C');
     $moduleC->setTasks(['Samurai\\Module\\resources\\TaskC']);
     $modules[] = $moduleC;
     return $modules;
 }
Esempio n. 8
0
 /**
  * @return int
  */
 public function count()
 {
     return count($this->module->getTasks());
 }
Esempio n. 9
0
 /**
  * @param Module $newModule
  * @return Module
  */
 private function getInitialModule(Module $newModule)
 {
     return $this->getService('module_manager')->get($newModule->getName());
 }
Esempio n. 10
0
 public function testImportWithDependenciesButComposerError()
 {
     $data = new DummyFileReader();
     $data->write('{
       "package": "raphhh/samurai-module-git",
       "description": "Git module",
       "dependencies": [
             {
                 "package": "dependency/1",
                 "version": "1"
             },
             {
                 "package": "dependency/2",
                 "version": "2",
                 "dependencies": [
                     {
                         "package": "dependency/1",
                         "version": "1"
                     }
               ]
             }
       ],
       "tasks": [
         "Samurai\\\\Git\\\\GitTask"
       ]
     }');
     $dependency1Data = new DummyFileReader();
     $dependency1Data->write('{
       "package": "dependency/1",
       "description": "dependency 1",
       "dependencies": [
       ],
       "tasks": [
       ]
     }');
     $dependency2Data = new DummyFileReader();
     $dependency2Data->write('{
       "package": "dependency/2",
       "description": "dependency 2",
       "dependencies": [
       ],
       "tasks": [
       ]
     }');
     $module = new Module();
     $module->setName('name');
     $module->setPackage('none/none');
     $module->setVersion('@dev');
     $module->setIsEnable(true);
     $modules = new Modules();
     $output = new BufferedOutput();
     $moduleManager = $this->getMockBuilder('Samurai\\Module\\ModuleManager')->disableOriginalConstructor()->getMock();
     $composer = $this->getMockBuilder('Samurai\\Project\\Composer\\Composer')->disableOriginalConstructor()->getMock();
     $balloonFactory = $this->getMockBuilder('Balloon\\Factory\\BalloonFactory')->disableOriginalConstructor()->getMock();
     $modulesSorter = $this->getMockBuilder('Samurai\\Module\\ModulesSorter')->disableOriginalConstructor()->getMock();
     $balloonFactory->expects($this->at(0))->method('create')->with('COMPOSER_HOME/vendor/none/none/.samurai.json')->will($this->returnValue((new BalloonFactory(new DummyFileReaderFactory($data)))->create('.json')));
     $composer->expects($this->at(0))->method('requirePackage')->with('none/none', '@dev', true)->will($this->returnValue(0));
     $composer->expects($this->at(2))->method('requirePackage')->with('dependency/1', '1', true)->will($this->returnValue(1));
     //error
     $composer->expects($this->exactly(1))->method('getHomePath')->will($this->returnValue('COMPOSER_HOME'));
     $moduleManager->expects($this->exactly(1))->method('add');
     $moduleManager->expects($this->never())->method('set')->with($this->identicalTo($modules));
     $moduleManager->expects($this->once())->method('clear');
     $moduleManager->expects($this->any())->method('getAll')->will($this->returnValue($modules));
     $modulesSorter->expects($this->never())->method('sort');
     $moduleProcedure = new ModuleProcedure($moduleManager, $composer, $balloonFactory, $modulesSorter);
     $moduleProcedure->setOutput($output);
     $this->assertFalse($moduleProcedure->import($module));
     $this->assertSame("Starting installation of none/none\nStarting installation of dependency/1\nAn error occurred during the installation of dependency/1\nRoll-backing installation of none/none\n", $output->fetch());
     $this->assertSame(['name' => 'name', 'description' => 'Git module', 'package' => 'none/none', 'version' => '@dev', 'source' => null, 'isEnable' => true, 'tasks' => ['Samurai\\Git\\GitTask'], 'dependencies' => [['name' => '', 'description' => '', 'package' => 'dependency/1', 'version' => '1', 'source' => '', 'isEnable' => true, 'tasks' => [], 'dependencies' => []], ['name' => '', 'description' => '', 'package' => 'dependency/2', 'version' => '2', 'source' => '', 'isEnable' => true, 'tasks' => [], 'dependencies' => []]]], $module->toArray());
 }
Esempio n. 11
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param Module $module
  * @return int|null
  */
 private function runModule(InputInterface $input, OutputInterface $output, Module $module)
 {
     $output->writeln('<info>Running the module "' . $module->getName() . '"</info>');
     $planner = new PlannerAdapter(new ModulePlannerBuilder($this->getServices(), $module), $this->getService('helper_set')->get('question'));
     return $planner->execute($input, $output);
 }
Esempio n. 12
0
 /**
  * @param Module $module
  * @return string
  */
 private function buildConfigPath(Module $module)
 {
     return $this->composer->getHomePath() . '/vendor/' . $module->getPackage() . '/.samurai.json';
 }
Esempio n. 13
0
 /**
  * @param array $data
  * @return Module
  */
 private function buildModuleFromData(array $data)
 {
     $module = new Module();
     $module->setName(!empty($data['name']) ? $data['name'] : null);
     $module->setPackage(!empty($data['package']) ? $data['package'] : null);
     $module->setVersion(!empty($data['version']) ? $data['version'] : null);
     $module->setDescription(!empty($data['description']) ? $data['description'] : null);
     $module->setSource(!empty($data['source']) ? $data['source'] : null);
     $module->setIsEnable(true);
     return $module;
 }