/** * 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; } }
public function testGetAvailableGenerators() { $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); $this->assertTrue(is_array($reader->getAvailableGenerators(ConfigReader::CONFIG_TYPE_HEXAGONAL))); $this->assertEquals(ConfigReader::CONFIG_TYPE_HEXAGONAL, $reader->getConfigType()); $this->assertFalse($reader->getAvailableGenerators('foo')); }