protected function runCommand(InputInterface $input, OutputInterface $output) { $migration = $input->getArgument('migration'); $migrationNameCreator = new MigrationNameCreator($migration); $filename = $migrationNameCreator->getFileName(); $dir = $input->getArgument('dir'); $migrationDir = $this->config->getMigrationDir($dir); $templatePath = $input->getOption('template') ?: __DIR__ . '/../Templates/DefaultTemplate.phoenix'; if (!file_exists($templatePath)) { throw new PhoenixException('Template "' . $templatePath . '" not found'); } $template = file_get_contents($templatePath); $namespace = ''; if ($migrationNameCreator->getNamespace()) { $namespace .= "namespace {$migrationNameCreator->getNamespace()};\n\n"; } $template = str_replace('###NAMESPACE###', $namespace, $template); $template = str_replace('###CLASSNAME###', $migrationNameCreator->getClassName(), $template); file_put_contents($migrationDir . '/' . $filename, $template); $output->writeln(''); $output->writeln('<info>Migration "' . $migration . '" created</info>'); }
public function testCreateMigrationName() { $className = 'AddSomethingToTable'; $migrationNameCreator = new MigrationNameCreator($className); $this->assertEquals(date('YmdHis') . '_add_something_to_table.php', $migrationNameCreator->getFileName()); $this->assertEquals('AddSomethingToTable', $migrationNameCreator->getClassName()); $this->assertEquals('', $migrationNameCreator->getNamespace()); $className = '\\AddSomethingToTable'; $migrationNameCreator = new MigrationNameCreator($className); $this->assertEquals(date('YmdHis') . '_add_something_to_table.php', $migrationNameCreator->getFileName()); $this->assertEquals('AddSomethingToTable', $migrationNameCreator->getClassName()); $this->assertEquals('', $migrationNameCreator->getNamespace()); $className = 'MyNamespace\\AddSomethingToTable'; $migrationNameCreator = new MigrationNameCreator($className); $this->assertEquals(date('YmdHis') . '_add_something_to_table.php', $migrationNameCreator->getFileName()); $this->assertEquals('AddSomethingToTable', $migrationNameCreator->getClassName()); $this->assertEquals('MyNamespace', $migrationNameCreator->getNamespace()); $className = '\\MyNamespace\\SecondLevel\\AddSomethingToTable'; $migrationNameCreator = new MigrationNameCreator($className); $this->assertEquals(date('YmdHis') . '_add_something_to_table.php', $migrationNameCreator->getFileName()); $this->assertEquals('AddSomethingToTable', $migrationNameCreator->getClassName()); $this->assertEquals('MyNamespace\\SecondLevel', $migrationNameCreator->getNamespace()); }