├── .github └── workflows │ └── php-tests.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── boilerplates ├── css.boilerplate.txt ├── js.boilerplate.txt ├── php__class.boilerplate.txt ├── php__trait.boilerplate.txt └── view.boilerplate.txt ├── composer.json ├── phpunit.xml ├── src ├── FileGenCommand.php ├── FileGenListCommand.php ├── FileGenNewCommand.php ├── FileGeneratorException.php ├── FileGeneratorServiceProvider.php ├── FileHelper.php ├── FileList.php ├── FileParser.php ├── Format.php └── config │ └── filegen.php └── tests ├── BoilerplateFileParserTest.php ├── FormatterTests.php └── fixtures ├── flags.boilerplate.txt ├── php_tag.boilerplate.txt ├── required_opt.boilerplate.txt └── simple.boilerplate.txt /.github/workflows/php-tests.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build-test: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v3 10 | - uses: php-actions/composer@v6 11 | - uses: php-actions/phpunit@v3 12 | with: 13 | configuration: phpunit.xml -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | .idea 3 | .DS_Store 4 | composer.lock 5 | .phpunit.result.cache 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### 0.1.6 2 | 3 | * Added new boilerplates for View, CSS, etc 4 | 5 | ### 0.1.5 6 | 7 | * Namespace generator didn't work properly. Hopefully does better now. 8 | 9 | ### 0.1.4 10 | 11 | * Changed name to "file-generator" 12 | * Still has some issues to work out. 13 | 14 | ### 0.1.3 15 | 16 | * Improved Vue boilerplate templates 17 | * Fixed major issue where artisan commands won't run if boilerplate has syntax issue 18 | 19 | ### 0.1.2 20 | 21 | * Removed critical code out of constructor which would cause other commands to fail 22 | * Fixed bug where missing boilerplate dir would prevent install 23 | * Changed instruction warning message on `bake:list` 24 | 25 | ### 0.1.1 26 | 27 | * Initial Release 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2017 Anirudh Sanjeev 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel file generator 2 | 3 | This is a Laravel package which helps you automate creation of files. 4 | 5 | ### Benefits 6 | 7 | * If you create a type of file frequently, you can automate it and improve productivity. 8 | * Prevent "context switching" where you lose focus for 30 seconds while you create new files, directories and populate it with boilerplate. 9 | * Comes with several built-in boilerplates. Easy to share your own as github gists. 10 | * All boilerplates and generators are part of your repository, letting you share standard templates with your team. 11 | * Find things like `artisan make:model` and `artisan make:controller` useful? You can make your own. 12 | * All boilerplates can be written as blade templates. 13 | 14 | ## Quick Start 15 | 16 | **Step 1**: Install the package 17 | 18 | ```bash 19 | $ composer require skyronic/laravel-file-generator 20 | ``` 21 | 22 | **Step 2**: Publish the "boilerplates" - an included set of useful boilerplates like PHP Classes. 23 | 24 | ```bash 25 | $ php artisan vendor:publish --tag='boilerplates' 26 | ``` 27 | 28 | **Step 3**: You can list all the installed boilerplates 29 | 30 | ```bash 31 | $ php artisan generate:list 32 | 33 | +---------------+------------------------------+ 34 | | Type | Name | 35 | +---------------+------------------------------+ 36 | | css | CSS File | 37 | | js | JavaScript File | 38 | | php:class | PHP Class in 'app' Directory | 39 | | php:trait | PHP Trait in 'app' Directory | 40 | | view | Blade Template | 41 | +---------------+------------------------------+ 42 | 43 | Use `artisan generate ` to create a new file! 44 | ``` 45 | 46 | **Step 5**: You can create a php class now: 47 | 48 | ```bash 49 | $ php artisan generate php:class "Support/Helpers/AwesomeHelper" --extends "BaseHelper" --constructor 50 | 51 | Created file [ app/Support/Helpers/AwesomeHelper.php ] 52 | ``` 53 | 54 | The generator `php:class` creates one by default in. You can now open app/Support/Helpers/AwesomeHelper.php 55 | 56 | ```php 57 | "App\Support\Helpers" 277 | 278 | // For non `app` directories, you need to manually specify namespace routes 279 | // $path = "tests/Unit/HelperTests/AwesomeHelperTest.php" 280 | Format::getNamespace ($path, 'tests', "Tests") 281 | // -> "Tests\Unit\HelperTests" 282 | ``` 283 | 284 | ## Example: PHP Class generator 285 | 286 | First, be sure that you've run `php artisan vendor:publish --tag='boilerplates'` and check `app/resources/boilerplates/php__class.boilerplate.txt` 287 | 288 | ``` 289 | { 290 | "name": "PHP Class in 'app' Directory", 291 | "out": "app/{{ $name }}.php", 292 | "params": { 293 | "extends": "optional", 294 | "constructor": "flag" 295 | } 296 | } 297 | --- 298 | =8.2", 17 | "illuminate/support": "^8.0|^9.0|^10.0|^11.0", 18 | "illuminate/console": "^8.0|^9.0|^10.0|^11.0", 19 | "illuminate/view": "^8.0|^9.0|^10.0|^11.0", 20 | "illuminate/filesystem": "^8.0|^9.0|^10.0|^11.0", 21 | "symfony/finder": "^6.0|^7.0" 22 | }, 23 | "require-dev": { 24 | "phpunit/phpunit": "^9.0|^10.5" 25 | }, 26 | "autoload-dev": { 27 | "psr-4": { 28 | "Tests\\": "tests/" 29 | } 30 | }, 31 | "autoload": { 32 | "psr-4": { 33 | "Skyronic\\FileGenerator\\": "src/" 34 | } 35 | }, 36 | "minimum-stability": "dev", 37 | "prefer-stable": true, 38 | "extra": { 39 | "laravel": { 40 | "providers": [ 41 | "Skyronic\\FileGenerator\\FileGeneratorServiceProvider" 42 | ] 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | ./tests/ 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/FileGenCommand.php: -------------------------------------------------------------------------------- 1 | fileList = new FileList($config); 32 | if (file_exists(config('filegen.dir'))) { 33 | $this->fileList->readDirectory(config('filegen.dir')); 34 | } 35 | 36 | // Add the type and name parameters 37 | $allParams = $this->fileList->getAllParams(); 38 | $options = []; 39 | foreach ($allParams as $param) { 40 | $type = $param['type']; 41 | $key = $param['key']; 42 | $fileKey = $param['fileKey']; 43 | $name = $param['name']; 44 | $optType = InputOption::VALUE_OPTIONAL; 45 | if($type === 'flag') { 46 | $optType = InputOption::VALUE_NONE; 47 | } 48 | $options []= [$key, null, $optType, "For `$fileKey` [ $name ]"]; 49 | $this->addOption($key, null, $optType, "For `$fileKey` [ $name ]"); 50 | } 51 | } 52 | catch (\Exception $e) { 53 | $this->configException = $e; 54 | return; 55 | } 56 | } 57 | 58 | public function handle () { 59 | if ($this->configException !== null) { 60 | throw $this->configException; 61 | } 62 | // get the appropriate file parser 63 | /** @var FileParser $fp */ 64 | $fp = $this->fileList->getItem($this->argument('type')); 65 | 66 | // Make a list of params 67 | $params = $this->options(); 68 | $params['name'] = $this->argument('name'); 69 | $params['path'] = ''; 70 | 71 | $fp->render($params); 72 | $friendlyOutPath = $fp->getOutPath(); 73 | 74 | // set the path as the friendly path 75 | $params['path'] = $friendlyOutPath; 76 | 77 | // do another render with the new params 78 | $fp->render($params); 79 | 80 | $outPath = base_path($friendlyOutPath); 81 | $contents = $fp->getContents(); 82 | $outDir = dirname($outPath); 83 | 84 | if ($this->option('dry-run')) { 85 | $this->info ("Doing a dry run."); 86 | $this->info ("The following will be written to [ $friendlyOutPath ]:"); 87 | $this->line($contents); 88 | exit (); 89 | } 90 | 91 | if (!file_exists($outDir)) { 92 | mkdir($outDir, 0777, true); 93 | } 94 | 95 | if (file_exists($outPath) && !$this->option('force')) { 96 | $this->error("File [ $friendlyOutPath ] already exists. Use --force to replace"); 97 | exit(); 98 | } 99 | 100 | file_put_contents($outPath, $contents); 101 | $this->info("Created file [ $friendlyOutPath ] "); 102 | } 103 | } -------------------------------------------------------------------------------- /src/FileGenListCommand.php: -------------------------------------------------------------------------------- 1 | readDirectory($baseDir); 24 | 25 | $items = $fileList->listItems(); 26 | $this->table(["Type", "Name"], $items); 27 | $this->line("\n\nUse `artisan generate ` to create a new file!"); 28 | } 29 | } -------------------------------------------------------------------------------- /src/FileGenNewCommand.php: -------------------------------------------------------------------------------- 1 | argument('type'); 15 | $desc = $this->option('description'); 16 | 17 | $extension = config('filegen.extension'); 18 | $separator = config('filegen.separator'); 19 | 20 | $baseDir = rtrim(FileHelper::fixDirSeparator(config('filegen.dir')), DIRECTORY_SEPARATOR); 21 | 22 | $outPath = $baseDir.DIRECTORY_SEPARATOR.$type.$extension; 23 | 24 | $outDir = dirname($outPath); 25 | if(!file_exists($outDir)) { 26 | mkdir($outDir,0777, true); 27 | } 28 | if (file_exists($outPath)) { 29 | throw new FileGeneratorException("Boilerplate file already exists [ $outPath ]"); 30 | } 31 | 32 | $content = <<info ("Created new boilerplate at [ $friendlyPath ]"); 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /src/FileGeneratorException.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole ()) { 17 | $this->mergeConfigFrom(__DIR__."/config/filegen.php", 'filegen'); 18 | $this->commands([ 19 | FileGenListCommand::class, 20 | FileGenNewCommand::class, 21 | FileGenCommand::class 22 | ]); 23 | } 24 | 25 | $this->publishes([ 26 | __DIR__.'/../boilerplates/' => resource_path('boilerplates'), 27 | ], 'boilerplates'); 28 | 29 | $this->publishes([ 30 | __DIR__.'/config/filegen.php' => config_path('filegen.php'), 31 | ], 'config'); 32 | } 33 | 34 | /** 35 | * Register the service provider. 36 | * 37 | * @return void 38 | */ 39 | public function register() 40 | { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/FileHelper.php: -------------------------------------------------------------------------------- 1 | config = $config; 25 | } 26 | 27 | /** 28 | * source directory 29 | * 30 | * @var string 31 | */ 32 | protected $dir; 33 | 34 | /** 35 | * All the items 36 | * 37 | * @var array 38 | */ 39 | protected $items = []; 40 | 41 | /** 42 | * All items indexed by key 43 | * 44 | * @var array 45 | */ 46 | protected $itemsByKey = []; 47 | 48 | /** 49 | * @param $dir 50 | */ 51 | public function readDirectory ($dir) { 52 | $finder = new Finder(); 53 | $fileList = $finder->in($dir) 54 | ->name("*".$this->config['extension']) 55 | ->files(); 56 | 57 | 58 | foreach ($fileList as $file) { 59 | $fp = new FileParser($this->config); 60 | $fp->readFile($file); 61 | $name = $fp->getBasename(); 62 | 63 | $this->items []= $fp; 64 | $this->itemsByKey[$name] = $fp; 65 | } 66 | } 67 | 68 | public function getAllParams () { 69 | $allParams = []; 70 | 71 | foreach ($this->items as $item) { 72 | /** @var FileParser $item */ 73 | $pList = $item->getParams(); 74 | foreach ($pList as $key => $type) { 75 | $param = []; 76 | $param['key'] = $key; 77 | $param['fileKey'] = $item->getBasename(); 78 | $param['name'] = $item->getName(); 79 | if ($type === 'flag') { 80 | $param['type'] = 'flag'; 81 | } 82 | else { 83 | // important, mark all of them as optional for now... 84 | $param['type'] = 'optional'; 85 | } 86 | $allParams []= $param; 87 | } 88 | } 89 | 90 | return $allParams; 91 | } 92 | 93 | public function listItems () { 94 | $result = []; 95 | 96 | foreach ($this->items as $item) { 97 | /** @var FileParser $item */ 98 | $result []= [ 99 | 'key' => $item->getBasename(), 100 | 'label' => $item->getName() 101 | ]; 102 | } 103 | 104 | return $result; 105 | } 106 | 107 | public function getItem ($key) { 108 | if (!isset($this->itemsByKey[$key])) { 109 | throw new FileGeneratorException("No such generator [ $key ]"); 110 | } 111 | 112 | return $this->itemsByKey[$key]; 113 | } 114 | } -------------------------------------------------------------------------------- /src/FileParser.php: -------------------------------------------------------------------------------- 1 | config = $config; 56 | } 57 | 58 | public function readFile ($path) { 59 | $this->path = $path; 60 | $this->raw_content = file_get_contents($path); 61 | $this->firstPassParse(); 62 | return $this; 63 | } 64 | 65 | /** 66 | * Does a first parse and extracts the meta. 67 | * @throws FileGeneratorException 68 | */ 69 | protected function firstPassParse () { 70 | $this->baseName = basename($this->path, $this->config['extension']); 71 | $this->meta = $this->getMeta($this->raw_content); 72 | } 73 | 74 | /** 75 | * Extract meta from given content 76 | * @param $content 77 | * @return mixed 78 | * @throws FileGeneratorException 79 | */ 80 | protected function getMeta ($content) { 81 | $meta = json_decode($this->getHeader($content), true); 82 | 83 | if(json_last_error() !== JSON_ERROR_NONE) { 84 | throw new FileGeneratorException("JSON Exception: [$this->baseName] ".json_last_error_msg()); 85 | } 86 | 87 | return $meta; 88 | } 89 | 90 | /** 91 | * @param $text 92 | * @return mixed 93 | */ 94 | protected function getHeader ($text) { 95 | $separator = $this->config['separator']; 96 | $parts = preg_split("/[\r\n|\r|\n]".$separator."[\r\n|\r|\n]/", $text); 97 | return $parts[0]; 98 | } 99 | 100 | /** 101 | * Gets the name 102 | */ 103 | public function getName () { 104 | return $this->meta['name']; 105 | } 106 | 107 | /** 108 | * Gets the base name 109 | * 110 | * @return string 111 | */ 112 | public function getBasename () { 113 | return str_replace("__", ":", $this->baseName); 114 | } 115 | 116 | public function getParams () { 117 | return $this->meta['params']; 118 | } 119 | 120 | /** 121 | * Evaluates the template with the parameters 122 | * 123 | * @param $params 124 | */ 125 | public function render($params) { 126 | $params = $this->cleanParams ($params); 127 | $this->evaluateTemplate($params); 128 | 129 | // get new meta 130 | $this->meta = $this->getMeta($this->eval_content); 131 | } 132 | 133 | protected function cleanParams ($input) { 134 | $result = []; 135 | $params = $this->getParams(); 136 | 137 | // add some extra ones 138 | $params['name'] = 'required'; 139 | $params['path'] = 'optional'; 140 | 141 | foreach ($params as $key => $type) { 142 | if ($type === 'flag') { 143 | if (isset($input[$key])) { 144 | $result[$key] = $input[$key]; 145 | } 146 | else { 147 | $result[$key] = false; 148 | } 149 | } 150 | else if ($type === 'optional') { 151 | if (isset($input[$key])) { 152 | $result[$key] = $input[$key]; 153 | } 154 | else { 155 | $result[$key] = false; 156 | } 157 | } 158 | else if ($type === 'required') { 159 | if (!isset($input[$key])) { 160 | throw new FileGeneratorException("Needs argument [ $key ]"); 161 | } 162 | $result[$key] = $input[$key]; 163 | } 164 | else { 165 | // type is the default value 166 | if(isset($input[$key])) { 167 | $result[$key] = $input[$key]; 168 | } 169 | else { 170 | $result[$key] = $type; 171 | } 172 | } 173 | 174 | 175 | } 176 | 177 | return $result; 178 | } 179 | 180 | /** 181 | * Takes the entire boilerplate file and 182 | * renders it using blade to 183 | * 184 | * @param $params 185 | */ 186 | protected function evaluateTemplate ($params) { 187 | $contents = $this->raw_content; 188 | 189 | $contents = str_replace("", "END_PHP", $contents); 191 | $contents = str_replace("bladeCompile($contents, $params); 194 | 195 | $result = str_replace("START_PHP", "", $result); 197 | $result = str_replace("START_SHORT", "eval_content = $result; 200 | } 201 | 202 | /** 203 | * Do the actual blade compilation 204 | * 205 | * @param $value 206 | * @param $args 207 | * @return string 208 | * @throws \Exception 209 | */ 210 | protected function bladeCompile ($value, $args) { 211 | $fs = new Filesystem(); 212 | $x = new BladeCompiler ($fs, sys_get_temp_dir()); 213 | $generated = $x->compileString($value); 214 | 215 | // TODO: is there a way to do this better? 216 | $generated = str_replace("Format::", "\\Skyronic\\FileGenerator\\Format::", $generated); 217 | 218 | ob_start() and extract($args, EXTR_SKIP); 219 | 220 | try 221 | { 222 | eval('?>'.$generated); 223 | } 224 | catch (\Exception $e) 225 | { 226 | ob_get_clean(); throw $e; 227 | } 228 | 229 | $content = ob_get_clean(); 230 | 231 | return $content; 232 | } 233 | 234 | public function getOutPath () { 235 | return FileHelper::fixDirSeparator($this->meta['out']); 236 | } 237 | 238 | public function getContents () { 239 | return $this->getBody($this->eval_content); 240 | } 241 | 242 | protected function getBody ($text) { 243 | $separator = $this->config['separator']; 244 | $parts = preg_split("/[\r\n|\r|\n]".$separator."[\r\n|\r|\n]/", $text); 245 | return $parts[1]; 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /src/Format.php: -------------------------------------------------------------------------------- 1 | base_path ("resources/boilerplates/"), 5 | 'extension' => '.boilerplate.txt', 6 | 'separator' => '---' 7 | ]; 8 | -------------------------------------------------------------------------------- /tests/BoilerplateFileParserTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(1, 1); 12 | } 13 | 14 | protected function makeFileParser () { 15 | return new FileParser([ 16 | 'extension' => '.boilerplate.txt', 17 | 'separator' => '---' 18 | ]); 19 | } 20 | 21 | public function testSimple1 () { 22 | $fp = $this->makeFileParser()->readFile(__DIR__."/fixtures/simple.boilerplate.txt"); 23 | $this->assertEquals('simple', $fp->getBasename()); 24 | $this->assertEquals($fp->getName(), "Simple Test 1"); 25 | 26 | $params = $fp->getParams(); 27 | $this->assertArrayHasKey('username', $params); 28 | 29 | $fp->render([ 30 | 'name' => 'bar', 31 | 'username' => "World" 32 | ]); 33 | $this->assertEquals($fp->getOutPath(), "foo/bar.txt"); 34 | $this->assertEquals($fp->getContents(), "Hello, World!\n"); 35 | } 36 | 37 | public function testFlags () { 38 | $fp = $this->makeFileParser()->readFile(__DIR__."/fixtures/flags.boilerplate.txt"); 39 | 40 | $fp->render([ 41 | 'name' => 'something' 42 | ]); 43 | $content1 = $fp->getContents(); 44 | $this->assertStringContainsString("ALWAYS_VISIBLE", $content1); 45 | $this->assertStringNotContainsString("FLAG1_SET", $content1); 46 | 47 | $fp->render([ 48 | 'name' => 'something', 49 | 'flag1' => true 50 | ]); 51 | $content2 = $fp->getContents(); 52 | $this->assertStringContainsString("ALWAYS_VISIBLE", $content2); 53 | $this->assertStringContainsString("FLAG1_SET", $content2); 54 | } 55 | 56 | public function testMissingRequiredArgException () { 57 | $fp = $this->makeFileParser()->readFile(__DIR__."/fixtures/required_opt.boilerplate.txt"); 58 | 59 | // we'll expect an exception to be thrown here. 60 | $this->expectExceptionMessage("Needs argument [ req1 ]"); 61 | $fp->render([ 62 | 'name' => 'foo' 63 | ]); 64 | } 65 | 66 | public function testParamTypes() { 67 | $fp = $this->makeFileParser()->readFile(__DIR__."/fixtures/required_opt.boilerplate.txt"); 68 | 69 | // we'll expect an exception to be thrown here. 70 | $fp->render([ 71 | 'name' => 'foo', 72 | 'req1' => "MY_REQUIRED_VALUE", 73 | ]); 74 | $content1 = $fp->getContents(); 75 | $this->assertStringContainsString("MY_REQUIRED_VALUE", $content1); 76 | $this->assertStringContainsString("MY_DEFAULT_VALUE", $content1); 77 | $this->assertStringContainsString("ALWAYS_VISIBLE", $content1); 78 | 79 | $fp->render([ 80 | 'name' => 'foo', 81 | 'req1' => "MY_REQUIRED_VALUE", 82 | 'opt1' => "MY_OPTIONAL_VALUE" 83 | ]); 84 | $content1 = $fp->getContents(); 85 | $this->assertStringContainsString("MY_OPTIONAL_VALUE", $content1); 86 | $this->assertStringContainsString("HAS_OPT_VALUE", $content1); 87 | 88 | $fp->render([ 89 | 'name' => 'foo', 90 | 'req1' => "MY_REQUIRED_VALUE", 91 | 'def1' => "MY_OVERRIDDEN_VALUE" 92 | ]); 93 | $content1 = $fp->getContents(); 94 | $this->assertStringContainsString("MY_OVERRIDDEN_VALUE", $content1); 95 | $this->assertStringNotContainsString("MY_DEFAULT_VALUE", $content1); 96 | } 97 | 98 | public function testPhpTagHandling () { 99 | $fp = $this->makeFileParser()->readFile(__DIR__."/fixtures/php_tag.boilerplate.txt"); 100 | $fp->render([ 101 | 'name' => 'foo' 102 | ]); 103 | $content = $fp->getContents(); 104 | $this->assertStringContainsString("", $content); 105 | $this->assertStringContainsString("", $content); 106 | $this->assertStringContainsString("", $content); 107 | $this->assertStringContainsString('', $content); 108 | } 109 | 110 | } -------------------------------------------------------------------------------- /tests/FormatterTests.php: -------------------------------------------------------------------------------- 1 | assertEquals('input', Format::baseName("foo/bar/input.txt")); 12 | $this->assertEquals('input', Format::baseName("FOO/BAr/input")); 13 | $this->assertEquals('input', Format::baseName("foo\\bar\\input")); 14 | } 15 | 16 | public function testNamespace () { 17 | $this->assertEquals("App\\Tmp", Format::getNamespace("app/Tmp/Foo.php")); 18 | $this->assertEquals("Test\\Unit\\Tmp", Format::getNamespace("test/Tmp/Foo.php", "test", "Test\\Unit")); 19 | 20 | $this->assertEquals("App\\Tmp", Format::getNamespace("app\\Tmp\\Foo.php")); 21 | $this->assertEquals("Test\\Unit\\Tmp", Format::getNamespace("test\\Tmp\\Foo.php", "test", "Test\\Unit")); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /tests/fixtures/flags.boilerplate.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Simple Test 1", 3 | "out": "foo/{{ $name }}.txt", 4 | "params": { 5 | "flag1": "flag" 6 | } 7 | } 8 | --- 9 | ALWAYS_VISIBLE 10 | 11 | @if($flag1) 12 | FLAG1_SET 13 | @endif 14 | 15 | -------------------------------------------------------------------------------- /tests/fixtures/php_tag.boilerplate.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "php tag test", 3 | "out": "foo/{{ $name }}.txt", 4 | "params": { 5 | "opt1": "optional" 6 | } 7 | } 8 | --- 9 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/fixtures/required_opt.boilerplate.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "required/opt test", 3 | "out": "foo/{{ $name }}.txt", 4 | "params": { 5 | "req1": "required", 6 | "opt1": "optional", 7 | "def1": "MY_DEFAULT_VALUE" 8 | } 9 | } 10 | --- 11 | ALWAYS_VISIBLE 12 | 13 | {{ $req1 }} 14 | 15 | @if($opt1) 16 | HAS_OPT_VALUE 17 | {{ $opt1 }} 18 | @endif 19 | 20 | {{ $def1 }} 21 | -------------------------------------------------------------------------------- /tests/fixtures/simple.boilerplate.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Simple Test 1", 3 | "out": "foo/{{ $name }}.txt", 4 | "params": { 5 | "username": "optional" 6 | } 7 | } 8 | --- 9 | Hello, {{ $username }}! 10 | --------------------------------------------------------------------------------