/** * Execute the command. * * @return void */ protected function fire() { $file = $this->argument('file'); $tw = new TemplateWriter($file, new Filesystem()); $output = $tw->write(); $this->comment("Success", "Template written to {$output}"); }
public function testWriteOutTemplateFileGivenADirectory() { $path = '/some/path'; $file = '/some/path/template.json'; $fsMock = m::mock('Illuminate\\Filesystem\\Filesystem'); //call isDir on a dir $fsMock->shouldReceive('isDirectory')->once()->with($path)->andReturn(true); //should write to default file at given path $fsMock->shouldReceive('put')->once()->with($path . '/foreman-tpl.json', json_encode($this->getStructureArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); //call isDir on a file $fsMock->shouldReceive('isDirectory')->once()->with($file)->andReturn(false); //should write to given file $fsMock->shouldReceive('put')->once()->with($file, json_encode($this->getStructureArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); $tw = new TemplateWriter($path, $fsMock); $pathWritten = $tw->write(); $this->assertEquals($path . '/foreman-tpl.json', $pathWritten); $tw = new TemplateWriter($file, $fsMock); $fileWritten = $tw->write(); $this->assertEquals($file, $fileWritten); }