/** * Function to run the delegated operations and return boolean * status of result. If false the command should comment out * the reasons for the failure. * * @return bool success / failure of operations */ public function run() { //check if the loaded config is valid if (!$this->config->validateConfig()) { $this->command->comment('Error', 'The loaded configuration file is invalid', true); return false; } //get possible generations $possible_generations = $this->config->getAvailableGenerators($this->config->getConfigType()); //see if passed in command is one that is available if (!in_array($this->generation_request, $possible_generations)) { $this->command->comment('Error', "{$this->generation_request} is not a valid option", true); $this->command->comment('Error Details', "Please choose from: " . implode(", ", $possible_generations), true); return false; } //should be good to generate, get the config values $settings = $this->config->getConfigValue($this->generation_request); $tplFile = $settings[ConfigReader::CONFIG_VAL_TEMPLATE]; $template = implode(DIRECTORY_SEPARATOR, [$this->config->getConfigDirectory(), $tplFile]); $directory = $settings[ConfigReader::CONFIG_VAL_DIRECTORY]; $filename = $settings[ConfigReader::CONFIG_VAL_FILENAME]; //run generator $success = $this->generator->make($this->generate_for_entity, $template, $directory, $filename, $this->optionReader); if ($success) { $this->command->comment('Blacksmith', 'Success, I generated the code for you in ' . $this->generator->getTemplateDestination()); return true; } else { $this->command->comment('Blacksmith', 'An unknown error occured, nothing was generated', true); return false; } }
/** * Function to run the delegated operations and return boolean * status of result. If false the command should comment out * the reasons for the failure. * * @return bool success / failure of operations */ public function run() { //check if the loaded config is valid if (!$this->config->validateConfig()) { $this->command->comment('Error', 'The loaded configuration file is invalid', true); return false; } //get possible generations $possible_aggregates = $this->config->getAvailableAggregates(); //see if passed in command is one that is available if (!in_array($this->generation_request, $possible_aggregates)) { $this->command->comment('Error', "{$this->generation_request} is not a valid option", true); $this->command->comment('Error Details', "Please choose from: " . implode(", ", $possible_aggregates), true); return false; } //get all the generators for this aggregate $generators = $this->config->getAggregateValues($this->generation_request); foreach ($generators as $to_generate) { //get the settings, options etc. $settings = $this->config->getConfigValue($to_generate); if ($settings === false) { $this->command->comment('Blacksmith', 'I skipped "' . $to_generate . '"'); continue; } $tplFile = $settings[ConfigReader::CONFIG_VAL_TEMPLATE]; $template = implode(DIRECTORY_SEPARATOR, [$this->config->getConfigDirectory(), $tplFile]); $directory = $settings[ConfigReader::CONFIG_VAL_DIRECTORY]; $filename = $settings[ConfigReader::CONFIG_VAL_FILENAME]; //create the generator $generator = $this->generator_factory->make($to_generate, $this->optionReader); //run generator $success = $generator->make($this->generate_for_entity, $template, $directory, $filename, $this->optionReader); if ($success) { $this->command->comment('Blacksmith', 'Success, I generated the code for you in ' . $generator->getTemplateDestination()); } else { $this->command->comment('Blacksmith', "An unknown error occurred, nothing was generated for {$to_generate}", true); } } //end foreach $collectionName = Str::plural(Str::snake($this->generate_for_entity)); $this->updateRoutesFile($collectionName, getcwd()); return true; }
public function testGetAggregateShoulFail() { $path = realpath(__DIR__ . '/../../src/lib/Generators/templates/hexagonal/config.json'); $json = file_get_contents($path); $fs = m::mock('Illuminate\\Filesystem\\Filesystem'); $fs->shouldReceive('get')->once()->withAnyArgs()->andReturn($json); $reader = new ConfigReader($fs); $result = $reader->getAggregateValues('something-invalid'); $this->assertFalse($result); }