public function testValidUpdateCapfile() { $originalContent = <<<ORIGINAL set :first_name, 'foo' set :last_name, 'bar' ORIGINAL; $expectedContent = <<<EXPECTED set :first_name, 'John' set :last_name, 'Doe' EXPECTED; $tempFile = tempnam(sys_get_temp_dir(), 'test'); file_put_contents($tempFile, $originalContent); $this->installer->updateCapfile($tempFile, array('first_name' => 'John', 'last_name' => 'Doe')); $this->assertEquals($expectedContent, file_get_contents($tempFile)); unlink($tempFile); }
/** * Create the initial configuration for our project * * @param Event $event */ public static function createInitialConfig(Event $event) { $installer = new Installer(); $io = $event->getIO(); // check if parameters.yml exists $rootDir = realpath(__DIR__ . '/../../../../'); if (file_exists($rootDir . '/app/config/parameters.yml')) { $io->write($installer->getDecoratedMessage('Skipping creating the initial config as parameters.yml already exists', 'info', $io->isDecorated())); } else { $information = $installer->extractInformationFromPath($rootDir); // ask all the information we need $config = array(); $config['client'] = $installer->ask($io, 'client name', $information['client']); $config['project'] = $installer->ask($io, 'project name', $information['project']); $config['database_name'] = substr($config['client'], 0, 8) . '_' . substr($config['project'], 0, 7); $config['database_user'] = $config['database_name']; if ($information['is_local']) { // this is the ip-address of our Vagrantbox $config['database_host'] = '10.11.12.13'; $config['database_user'] = '******'; $config['database_password'] = '******'; } $config['secret'] = md5(uniqid()); // create the database if requested if ($installer->askConfirmation($io, 'Should I create the database?')) { passthru('mysqladmin create ' . $config['database_name']); } // alter the Capfile if requested $capfilePath = $rootDir . '/Capfile'; if (file_exists($capfilePath)) { if ($installer->askConfirmation($io, 'Should I alter the Capfile?')) { $installer->updateCapfile($capfilePath, $config); } } // alter the dist file if requested $parameterYmlDistPath = $rootDir . '/app/config/parameters.yml.dist'; if (file_exists($parameterYmlDistPath)) { if ($installer->askConfirmation($io, 'Should I alter parameters.yml.dist?')) { $installer->updateYmlFile($parameterYmlDistPath, $config); } } } }