Example #1
0
 public function testFileComposta()
 {
     $dir_temp = __DIR__ . '/../../src/Database/Migration/Templates';
     $dir_target = __DIR__ . '/Ola';
     $t = new \Bugotech\IO\Template();
     try {
         $t->make($dir_temp, $dir_target);
         //Verificar se o Diretório foi criado
         $this->assertFileExists($dir_target);
         //Pegar conteúdo do dir_temp
         $files_dir = [];
         $arquivos_dir = $this->file->allFiles($dir_temp);
         foreach ($arquivos_dir as $item) {
             $i = new stdClass();
             $i->nome = $item->getPathname();
             $i->valor = $item->getContents();
             $i->trocado = str_replace('{{class}}', 'OlaMundo', str_replace('{{table}}', 'Tabela', $i->valor));
             $files_dir[] = $i;
         }
         //Pegar conteúdo do dir_target
         $files_target = [];
         $arquivos_target = $this->file->allFiles($dir_target);
         foreach ($arquivos_target as $item) {
             $i = new stdClass();
             $i->nome = $item->getPathname();
             $i->valor = $item->getContents();
             $files_target[] = $i;
         }
         //Comparando os dois valores
         $ret = $this->compararArrays($files_dir, $files_target);
         $this->assertTrue($ret);
         /*Param não funcionando para mais de um File
         
                     //Atribuindo o Param
                     $t->param('class', 'OlaMundo');
                     $t->param('table', 'Tabela');
         
                     //Pegar conteúdo do dir_target
                     $files_target = [];
                     $arquivos_target = $this->file->allFiles($dir_target);
                     foreach ($arquivos_target as $item) {
                         $i = new stdClass();
                         $i->nome = $item->getPathname();
                         $i->valor = $item->getContents();
                         $i->trocado = $item->getContents();
         
                         $files_target[] = $i;
                     }
         
                     $ret = $this->compararArrays($files_dir, $files_target, 'trocado');
                     $this->assertTrue($ret);*/
         $this->file->deleteDirectory($dir_target, false);
     } catch (Exception $e) {
         $this->file->deleteDirectory($dir_target, false);
         print_r($e->getMessage());
     }
 }
Example #2
0
 protected function writeMigration($name, $table, $create)
 {
     $with_prefix = $this->input->getOption('no-prefix') === false;
     $name = $with_prefix ? sprintf('migration_%s', $name) : $name;
     $path = $this->getMigrationPath();
     $target = $this->makeName($name, $path);
     $class = studly_case($name);
     $t = new \Bugotech\IO\Template();
     $t->file($this->getStub($table, $create), $target);
     $t->param('class', $class);
     $t->param('table', $table);
     $file = pathinfo($target, PATHINFO_FILENAME);
     $this->line("<info>Created Migration:</info> {$file}");
     return true;
 }