diff --git a/composer.json b/composer.json index 11f055b0..d7b7d830 100644 --- a/composer.json +++ b/composer.json @@ -8,27 +8,20 @@ ], "license": "MIT", "require": { + "doctrine/dbal": "^2.9 || ^3.0", + "illuminate/console": "^6.0 || ^7.0 || ^8.0", + "illuminate/filesystem": "^6.0 || ^7.0 || ^8.0", + "illuminate/support": "^6.0 || ^7.0 || ^8.0", "laravel-shift/faker-registry": "^0.1", - "symfony/yaml": "^4.3|^5.0", - "illuminate/console": "^6.0|^7.0|^8.0", - "illuminate/filesystem": "^6.0|^7.0|^8.0", - "illuminate/support": "^6.0|^7.0|^8.0", - "doctrine/dbal": "^2.9|^3.0" + "symfony/yaml": "^4.3 || ^5.0" }, "require-dev": { - "phpunit/phpunit": "^8.0|^9.3", "mockery/mockery": "^1.3", - "orchestra/testbench": "^4.0|^5.0|^6.0" + "orchestra/testbench": "^4.0 || ^5.0 || ^6.0", + "phpunit/phpunit": "^8.0 || ^9.3" }, - "autoload": { - "psr-4": { - "Blueprint\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/" - } + "suggest": { + "jasonmccreary/laravel-test-assertions": "Required to use additional assertions in generated tests (^1.0)." }, "config": { "sort-packages": true @@ -40,7 +33,14 @@ ] } }, - "suggest": { - "jasonmccreary/laravel-test-assertions": "Required to use additional assertions in generated tests (^1.0)." + "autoload": { + "psr-4": { + "Blueprint\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } } } diff --git a/src/Blueprint.php b/src/Blueprint.php index cab8aab1..d716627a 100644 --- a/src/Blueprint.php +++ b/src/Blueprint.php @@ -53,25 +53,45 @@ public function parse($content, $strip_dashes = true) $content = preg_replace('/^(\s*)-\s*/m', '\1', $content); } - $content = preg_replace_callback('/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?)$/mi', function ($matches) { - return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2]; - }, $content); - - $content = preg_replace_callback('/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?): true$/mi', function ($matches) { - return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2]; - }, $content); - - $content = preg_replace_callback('/^(\s+)resource?$/mi', function ($matches) { - return $matches[1] . 'resource: web'; - }, $content); - - $content = preg_replace_callback('/^(\s+)invokable?$/mi', function ($matches) { - return $matches[1].'invokable: true'; - }, $content); - - $content = preg_replace_callback('/^(\s+)uuid(: true)?$/mi', function ($matches) { - return $matches[1] . 'id: uuid primary'; - }, $content); + $content = preg_replace_callback( + '/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?)$/mi', + function ($matches) { + return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2]; + }, + $content + ); + + $content = preg_replace_callback( + '/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?): true$/mi', + function ($matches) { + return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2]; + }, + $content + ); + + $content = preg_replace_callback( + '/^(\s+)resource?$/mi', + function ($matches) { + return $matches[1] . 'resource: web'; + }, + $content + ); + + $content = preg_replace_callback( + '/^(\s+)invokable?$/mi', + function ($matches) { + return $matches[1] . 'invokable: true'; + }, + $content + ); + + $content = preg_replace_callback( + '/^(\s+)uuid(: true)?$/mi', + function ($matches) { + return $matches[1] . 'id: uuid primary'; + }, + $content + ); return Yaml::parse($content); } diff --git a/src/Builder.php b/src/Builder.php index b73aa708..17507d9c 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -6,14 +6,14 @@ class Builder { - public function execute(Blueprint $blueprint, Filesystem $files, string $draft, string $only = '', string $skip = '', $overwriteMigrations = false) + public function execute(Blueprint $blueprint, Filesystem $filesystem, string $draft, string $only = '', string $skip = '', $overwriteMigrations = false) { $cache = []; - if ($files->exists('.blueprint')) { - $cache = $blueprint->parse($files->get('.blueprint')); + if ($filesystem->exists('.blueprint')) { + $cache = $blueprint->parse($filesystem->get('.blueprint')); } - $contents = $files->get($draft); + $contents = $filesystem->get($draft); $using_indexes = preg_match('/^\s+indexes:\R/m', $contents) !== 1; $tokens = $blueprint->parse($contents, $using_indexes); @@ -27,7 +27,7 @@ public function execute(Blueprint $blueprint, Filesystem $files, string $draft, $models = array_merge($tokens['cache'], $tokens['models'] ?? []); - $files->put( + $filesystem->put( '.blueprint', $blueprint->dump($generated + ($models ? ['models' => $models] : [])) ); diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index 2f05f4d8..01ae708e 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -31,20 +31,20 @@ class BuildCommand extends Command protected $description = 'Build components from a Blueprint draft'; /** @var Filesystem */ - protected $files; + protected $filesystem; /** @var Builder */ private $builder; /** - * @param Filesystem $files - * @param Builder $builder + * @param Filesystem $filesystem + * @param Builder $builder */ - public function __construct(Filesystem $files, Builder $builder) + public function __construct(Filesystem $filesystem, Builder $builder) { parent::__construct(); - $this->files = $files; + $this->filesystem = $filesystem; $this->builder = $builder; } @@ -52,7 +52,7 @@ public function handle() { $file = $this->argument('draft') ?? $this->defaultDraftFile(); - if (!$this->files->exists($file)) { + if (!$this->filesystem->exists($file)) { $this->error('Draft file could not be found: ' . ($file ?: 'draft.yaml')); return 1; } @@ -62,16 +62,20 @@ public function handle() $overwriteMigrations = $this->option('overwrite-migrations') ?: false; $blueprint = resolve(Blueprint::class); - $generated = $this->builder->execute($blueprint, $this->files, $file, $only, $skip, $overwriteMigrations); - - collect($generated)->each(function ($files, $action) { - $this->line(Str::studly($action) . ':', $this->outputStyle($action)); - collect($files)->each(function ($file) { - $this->line('- ' . $file); - }); - - $this->line(''); - }); + $generated = $this->builder->execute($blueprint, $this->filesystem, $file, $only, $skip, $overwriteMigrations); + + collect($generated)->each( + function ($files, $action) { + $this->line(Str::studly($action) . ':', $this->outputStyle($action)); + collect($files)->each( + function ($file) { + $this->line('- ' . $file); + } + ); + + $this->line(''); + } + ); } /** diff --git a/src/Commands/EraseCommand.php b/src/Commands/EraseCommand.php index 95474836..106c80db 100644 --- a/src/Commands/EraseCommand.php +++ b/src/Commands/EraseCommand.php @@ -23,18 +23,14 @@ class EraseCommand extends Command */ protected $description = 'Erase components created from last Blueprint build'; - /** @var Filesystem $files */ - protected $files; + /** @var Filesystem */ + protected $filesystem; - /** - * @param Filesystem $files - * @param \Illuminate\Contracts\View\Factory $view - */ - public function __construct(Filesystem $files) + public function __construct(Filesystem $filesystem) { parent::__construct(); - $this->files = $files; + $this->filesystem = $filesystem; } /** @@ -44,33 +40,37 @@ public function __construct(Filesystem $files) */ public function handle() { - $contents = $this->files->get('.blueprint'); + $contents = $this->filesystem->get('.blueprint'); $blueprint = resolve(Blueprint::class); $generated = $blueprint->parse($contents, false); - collect($generated)->each(function ($files, $action) { - if ($action === 'created') { - $this->line('Deleted:', $this->outputStyle($action)); - $this->files->delete($files); - } elseif ($action === 'updated') { - $this->comment('The updates to the following files can not be erased automatically.'); - } else { - return; + collect($generated)->each( + function ($files, $action) { + if ($action === 'created') { + $this->line('Deleted:', $this->outputStyle($action)); + $this->filesystem->delete($files); + } elseif ($action === 'updated') { + $this->comment('The updates to the following files can not be erased automatically.'); + } else { + return; + } + + collect($files)->each( + function ($file) { + $this->line('- ' . $file); + } + ); + + $this->line(''); } - - collect($files)->each(function ($file) { - $this->line('- ' . $file); - }); - - $this->line(''); - }); + ); unset($generated['created']); unset($generated['updated']); - $this->files->put('.blueprint', $blueprint->dump($generated)); + $this->filesystem->put('.blueprint', $blueprint->dump($generated)); $this->call('blueprint:trace'); } diff --git a/src/Commands/NewCommand.php b/src/Commands/NewCommand.php index 3bb67591..76384bfd 100644 --- a/src/Commands/NewCommand.php +++ b/src/Commands/NewCommand.php @@ -22,16 +22,16 @@ class NewCommand extends Command protected $description = 'Create a draft.yaml file and load existing models'; /** @var Filesystem $files */ - protected $files; + protected $filesystem; /** - * @param Filesystem $files + * @param Filesystem $filesystem */ - public function __construct(Filesystem $files) + public function __construct(Filesystem $filesystem) { parent::__construct(); - $this->files = $files; + $this->filesystem = $filesystem; } /** @@ -41,8 +41,8 @@ public function __construct(Filesystem $files) */ public function handle() { - if (!$this->files->exists('draft.yaml')) { - $this->files->put('draft.yaml', $this->files->stub('draft.stub')); + if (!$this->filesystem->exists('draft.yaml')) { + $this->filesystem->put('draft.yaml', $this->filesystem->stub('draft.stub')); $this->info('Created example draft.yaml'); } diff --git a/src/Commands/TraceCommand.php b/src/Commands/TraceCommand.php index 41ddcdcc..57e0f57c 100644 --- a/src/Commands/TraceCommand.php +++ b/src/Commands/TraceCommand.php @@ -25,20 +25,20 @@ class TraceCommand extends Command protected $description = 'Create definitions for existing models to reference in new drafts'; /** @var Filesystem $files */ - protected $files; + protected $filesystem; /** @var Tracer */ private $tracer; /** - * @param Filesystem $files - * @param Tracer $tracer + * @param Filesystem $filesystem + * @param Tracer $tracer */ - public function __construct(Filesystem $files, Tracer $tracer) + public function __construct(Filesystem $filesystem, Tracer $tracer) { parent::__construct(); - $this->files = $files; + $this->filesystem = $filesystem; $this->tracer = $tracer; } @@ -50,7 +50,7 @@ public function __construct(Filesystem $files, Tracer $tracer) public function handle() { $blueprint = resolve(Blueprint::class); - $definitions = $this->tracer->execute($blueprint, $this->files); + $definitions = $this->tracer->execute($blueprint, $this->filesystem); if (empty($definitions)) { $this->error('No models found'); diff --git a/src/Contracts/Generator.php b/src/Contracts/Generator.php index 660e1b0b..775cd211 100644 --- a/src/Contracts/Generator.php +++ b/src/Contracts/Generator.php @@ -3,13 +3,11 @@ namespace Blueprint\Contracts; use Blueprint\Tree; +use Illuminate\Filesystem\Filesystem; interface Generator { - /** - * @param \Illuminate\Contracts\Filesystem\Filesystem - */ - public function __construct($files); + public function __construct(Filesystem $files); public function output(Tree $tree): array; diff --git a/src/EnumType.php b/src/EnumType.php index 3abe232b..3c6f5b51 100644 --- a/src/EnumType.php +++ b/src/EnumType.php @@ -13,9 +13,12 @@ class EnumType extends Type public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { - $values = array_map(function ($val) { - return "'" . $val . "'"; - }, $this->values); + $values = array_map( + function ($val) { + return "'" . $val . "'"; + }, + $this->values + ); return "ENUM(" . implode(", ", $values) . ")"; } @@ -42,14 +45,17 @@ public static function extractOptions($definition) { $options = explode(',', preg_replace('/enum\((?P(.*))\)/', '$1', $definition)); - return array_map(function ($option) { - $raw_value = str_replace("''", "'", trim($option, "'")); + return array_map( + function ($option) { + $raw_value = str_replace("''", "'", trim($option, "'")); - if (!preg_match('/\s/', $raw_value)) { - return $raw_value; - } + if (!preg_match('/\s/', $raw_value)) { + return $raw_value; + } - return sprintf('"%s"', $raw_value); - }, $options); + return sprintf('"%s"', $raw_value); + }, + $options + ); } } diff --git a/src/Generators/ControllerGenerator.php b/src/Generators/ControllerGenerator.php index a9985a0e..15e7908e 100644 --- a/src/Generators/ControllerGenerator.php +++ b/src/Generators/ControllerGenerator.php @@ -17,23 +17,28 @@ use Blueprint\Models\Statements\SessionStatement; use Blueprint\Models\Statements\ValidateStatement; use Blueprint\Tree; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; class ControllerGenerator implements Generator { const INDENT = ' '; - /** @var \Illuminate\Contracts\Filesystem\Filesystem */ - private $files; + /** + * @var Filesystem + */ + protected $filesystem; private $imports = []; - /** @var Tree */ + /** + * @var Tree + */ private $tree; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree): array @@ -42,7 +47,7 @@ public function output(Tree $tree): array $output = []; - $stub = $this->files->stub('controller.class.stub'); + $stub = $this->filesystem->stub('controller.class.stub'); /** @var \Blueprint\Models\Controller $controller */ foreach ($tree->controllers() as $controller) { @@ -54,11 +59,11 @@ public function output(Tree $tree): array $path = $this->getPath($controller); - if (!$this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (!$this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $controller)); + $this->filesystem->put($path, $this->populateStub($stub, $controller)); $output['created'][] = $path; } @@ -83,7 +88,7 @@ protected function populateStub(string $stub, Controller $controller) protected function buildMethods(Controller $controller) { - $template = $this->files->stub('controller.method.stub'); + $template = $this->filesystem->stub('controller.method.stub'); $methods = ''; @@ -185,9 +190,15 @@ protected function buildImports(Controller $controller) $imports = array_unique($this->imports[$controller->name()]); sort($imports); - return implode(PHP_EOL, array_map(function ($class) { - return 'use ' . $class . ';'; - }, $imports)); + return implode( + PHP_EOL, + array_map( + function ($class) { + return 'use ' . $class . ';'; + }, + $imports + ) + ); } private function addImport(Controller $controller, $class) diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index 2f8219a5..cad0498c 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -7,6 +7,7 @@ use Blueprint\Models\Column; use Blueprint\Models\Model; use Blueprint\Tree; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; use Shift\Faker\Registry as FakerRegistry; @@ -14,17 +15,21 @@ class FactoryGenerator implements Generator { const INDENT = ' '; - /** @var \Illuminate\Contracts\Filesystem\Filesystem */ - private $files; + /** + * @var Filesystem + */ + protected $filesystem; - /** @var Tree */ + /** + * @var Tree + */ private $tree; private $imports = []; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree): array @@ -34,12 +39,14 @@ public function output(Tree $tree): array $output = []; if (Blueprint::isLaravel8OrHigher()) { - $stub = $this->files->stub('factory.stub'); + $stub = $this->filesystem->stub('factory.stub'); } else { - $stub = $this->files->stub('factory.closure.stub'); + $stub = $this->filesystem->stub('factory.closure.stub'); } - /** @var \Blueprint\Models\Model $model */ + /** + * @var \Blueprint\Models\Model $model +*/ foreach ($tree->models() as $model) { if (!Blueprint::isLaravel8OrHigher()) { $this->addImport($model, 'Faker\Generator as Faker'); @@ -48,11 +55,11 @@ public function output(Tree $tree): array $path = $this->getPath($model); - if (!$this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (!$this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $model)); + $this->filesystem->put($path, $this->populateStub($stub, $model)); $output['created'][] = $path; } @@ -81,10 +88,14 @@ protected function populateStub(string $stub, Model $model) $stub = str_replace('//', $this->buildDefinition($model), $stub); if (!Blueprint::isLaravel8OrHigher()) { - $stub = str_replace([ + $stub = str_replace( + [ "use Faker\Generator as Faker;\r\nuse", "use Faker\Generator as Faker;\nuse" - ], "use", $stub); + ], + "use", + $stub + ); } if (Blueprint::supportsReturnTypeHits()) { @@ -102,7 +113,9 @@ protected function buildDefinition(Model $model) $fillable = $this->fillableColumns($model->columns()); - /** @var \Blueprint\Models\Column $column */ + /** + * @var \Blueprint\Models\Column $column +*/ foreach ($fillable as $column) { if ($column->name() === 'id') { continue; @@ -273,9 +286,15 @@ protected function buildImports(Model $model) $imports = array_unique($this->imports[$model->name()]); sort($imports); - return implode(PHP_EOL, array_map(function ($class) { - return 'use ' . $class . ';'; - }, $imports)); + return implode( + PHP_EOL, + array_map( + function ($class) { + return 'use ' . $class . ';'; + }, + $imports + ) + ); } private function addImport(Model $model, $class) @@ -289,9 +308,12 @@ private function fillableColumns(array $columns): array return $columns; } - return array_filter($columns, function (Column $column) { - return !in_array('nullable', $column->modifiers()); - }); + return array_filter( + $columns, + function (Column $column) { + return !in_array('nullable', $column->modifiers()); + } + ); } private function fullyQualifyModelReference(string $model_name) diff --git a/src/Generators/MigrationGenerator.php b/src/Generators/MigrationGenerator.php index eb93b3fd..4d8abc71 100644 --- a/src/Generators/MigrationGenerator.php +++ b/src/Generators/MigrationGenerator.php @@ -10,6 +10,7 @@ use Illuminate\Support\Facades\App; use Illuminate\Support\Str; use Symfony\Component\Finder\SplFileInfo; +use Illuminate\Filesystem\Filesystem; class MigrationGenerator implements Generator { @@ -43,25 +44,29 @@ class MigrationGenerator implements Generator 'tinyInteger', ]; - /** @var \Illuminate\Contracts\Filesystem\Filesystem */ - private $files; + /** + * @var Filesystem + */ + protected $filesystem; private $output = []; private $hasForeignKeyConstraints = false; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree, $overwrite = false): array { $tables = ['tableNames' => [], 'pivotTableNames' => []]; - $stub = $this->files->stub('migration.stub'); + $stub = $this->filesystem->stub('migration.stub'); - /** @var \Blueprint\Models\Model $model */ + /** + * @var \Blueprint\Models\Model $model +*/ foreach ($tree->models() as $model) { $tables['tableNames'][$model->tableName()] = $this->populateStub($stub, $model); @@ -91,16 +96,16 @@ protected function createMigrations(array $tables, $overwrite = false): array foreach ($tables['tableNames'] as $tableName => $data) { $path = $this->getTablePath($tableName, $sequential_timestamp->addSecond(), $overwrite); - $action = $this->files->exists($path) ? 'updated' : 'created'; - $this->files->put($path, $data); + $action = $this->filesystem->exists($path) ? 'updated' : 'created'; + $this->filesystem->put($path, $data); $output[$action][] = $path; } foreach ($tables['pivotTableNames'] as $tableName => $data) { $path = $this->getTablePath($tableName, $sequential_timestamp->addSecond(), $overwrite); - $action = $this->files->exists($path) ? 'updated' : 'created'; - $this->files->put($path, $data); + $action = $this->filesystem->exists($path) ? 'updated' : 'created'; + $this->filesystem->put($path, $data); $output[$action][] = $path; } @@ -142,7 +147,9 @@ protected function buildDefinition(Model $model) { $definition = ''; - /** @var \Blueprint\Models\Column $column */ + /** + * @var \Blueprint\Models\Column $column +*/ foreach ($model->columns() as $column) { $dataType = $column->dataType(); @@ -200,13 +207,15 @@ protected function buildDefinition(Model $model) } // TODO: unset the proper modifier - $modifiers = collect($modifiers)->reject(function ($modifier) { - return (is_array($modifier) && key($modifier) === 'foreign') + $modifiers = collect($modifiers)->reject( + function ($modifier) { + return (is_array($modifier) && key($modifier) === 'foreign') || (is_array($modifier) && key($modifier) === 'onDelete') || (is_array($modifier) && key($modifier) === 'onUpdate') || $modifier === 'foreign' || ($modifier === 'nullable' && $this->isLaravel7orNewer()); - }); + } + ); } foreach ($modifiers as $modifier) { @@ -366,23 +375,27 @@ protected function getTablePath($tableName, Carbon $timestamp, $overwrite = fals $name = '_create_' . $tableName . '_table.php'; if ($overwrite) { - $migrations = collect($this->files->files($dir)) - ->filter(function (SplFileInfo $file) use ($name) { - return str_contains($file->getFilename(), $name); - }) + $migrations = collect($this->filesystem->files($dir)) + ->filter( + function (SplFileInfo $file) use ($name) { + return str_contains($file->getFilename(), $name); + } + ) ->sort(); if ($migrations->isNotEmpty()) { $migration = $migrations->first()->getPathname(); $migrations->diff($migration) - ->each(function (SplFileInfo $file) { - $path = $file->getPathname(); + ->each( + function (SplFileInfo $file) { + $path = $file->getPathname(); - $this->files->delete($path); + $this->filesystem->delete($path); - $this->output['deleted'][] = $path; - }); + $this->output['deleted'][] = $path; + } + ); return $migration; } @@ -404,9 +417,11 @@ protected function getPivotClassName(array $segments) protected function getPivotTableName(array $segments) { $isCustom = collect($segments) - ->filter(function ($segment) { - return Str::contains($segment, ':'); - })->first(); + ->filter( + function ($segment) { + return Str::contains($segment, ':'); + } + )->first(); if ($isCustom) { $table = Str::after($isCustom, ':'); @@ -414,9 +429,12 @@ protected function getPivotTableName(array $segments) return $table; } - $segments = array_map(function ($name) { - return Str::snake($name); - }, $segments); + $segments = array_map( + function ($name) { + return Str::snake($name); + }, + $segments + ); sort($segments); return strtolower(implode('_', $segments)); @@ -447,8 +465,10 @@ protected function isNumericDefault(string $type, string $value): bool } return collect(self::UNSIGNABLE_TYPES) - ->contains(function ($value) use ($type) { - return strtolower($value) === strtolower($type); - }); + ->contains( + function ($value) use ($type) { + return strtolower($value) === strtolower($type); + } + ); } } diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index bb64a830..efbf9025 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -7,19 +7,24 @@ use Blueprint\Models\Column; use Blueprint\Models\Model; use Blueprint\Tree; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; class ModelGenerator implements Generator { - /** @var \Illuminate\Contracts\Filesystem\Filesystem */ - private $files; - - /** @var Tree */ + /** + * @var Filesystem + */ + protected $filesystem; + + /** + * @var Tree + */ private $tree; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree): array @@ -29,20 +34,22 @@ public function output(Tree $tree): array $output = []; if (Blueprint::isLaravel8OrHigher()) { - $stub = $this->files->stub('model.class.stub'); + $stub = $this->filesystem->stub('model.class.stub'); } else { - $stub = $this->files->stub('model.class.no-factory.stub'); + $stub = $this->filesystem->stub('model.class.no-factory.stub'); } - /** @var \Blueprint\Models\Model $model */ + /** + * @var \Blueprint\Models\Model $model +*/ foreach ($tree->models() as $model) { $path = $this->getPath($model); - if (! $this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (! $this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $model)); + $this->filesystem->put($path, $this->populateStub($stub, $model)); $output['created'][] = $path; } @@ -94,7 +101,9 @@ protected function buildClassPhpDoc(Model $model) $phpDoc = PHP_EOL; $phpDoc .= '/**'; $phpDoc .= PHP_EOL; - /** @var Column $column */ + /** + * @var Column $column +*/ foreach ($model->columns() as $column) { if ($column->dataType() === 'morphs') { $phpDoc .= ' * @property int $' . $column->name() . '_id'; @@ -144,34 +153,34 @@ protected function buildProperties(Model $model) $properties = ''; if (! $model->usesTimestamps()) { - $properties .= $this->files->stub('model.timestamps.stub'); + $properties .= $this->filesystem->stub('model.timestamps.stub'); } if (config('blueprint.use_guarded')) { - $properties .= $this->files->stub('model.guarded.stub'); + $properties .= $this->filesystem->stub('model.guarded.stub'); } else { $columns = $this->fillableColumns($model->columns()); if (! empty($columns)) { - $properties .= PHP_EOL . str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model.fillable.stub')); + $properties .= PHP_EOL . str_replace('[]', $this->pretty_print_array($columns, false), $this->filesystem->stub('model.fillable.stub')); } else { - $properties .= $this->files->stub('model.fillable.stub'); + $properties .= $this->filesystem->stub('model.fillable.stub'); } } $columns = $this->hiddenColumns($model->columns()); if (! empty($columns)) { - $properties .= PHP_EOL . str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model.hidden.stub')); + $properties .= PHP_EOL . str_replace('[]', $this->pretty_print_array($columns, false), $this->filesystem->stub('model.hidden.stub')); } $columns = $this->castableColumns($model->columns()); if (! empty($columns)) { - $properties .= PHP_EOL . str_replace('[]', $this->pretty_print_array($columns), $this->files->stub('model.casts.stub')); + $properties .= PHP_EOL . str_replace('[]', $this->pretty_print_array($columns), $this->filesystem->stub('model.casts.stub')); } if (! Blueprint::isLaravel8OrHigher()) { $columns = $this->dateColumns($model->columns()); if (! empty($columns)) { - $properties .= PHP_EOL . str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model.dates.stub')); + $properties .= PHP_EOL . str_replace('[]', $this->pretty_print_array($columns, false), $this->filesystem->stub('model.dates.stub')); } } @@ -181,11 +190,11 @@ protected function buildProperties(Model $model) protected function buildRelationships(Model $model) { $methods = ''; - $template = $this->files->stub('model.method.stub'); + $template = $this->filesystem->stub('model.method.stub'); $commentTemplate = ''; if (config('blueprint.generate_phpdocs')) { - $commentTemplate = $this->files->stub('model.method.comment.stub'); + $commentTemplate = $this->filesystem->stub('model.method.comment.stub'); } foreach ($model->relationships() as $type => $references) { @@ -281,31 +290,39 @@ protected function addTraits(Model $model, $stub) private function fillableColumns(array $columns) { - return array_diff(array_keys($columns), [ + return array_diff( + array_keys($columns), + [ 'id', 'deleted_at', 'created_at', 'updated_at', 'remember_token', - ]); + ] + ); } private function hiddenColumns(array $columns) { - return array_intersect(array_keys($columns), [ + return array_intersect( + array_keys($columns), + [ 'password', 'remember_token', - ]); + ] + ); } private function castableColumns(array $columns) { - return array_filter(array_map( - function (Column $column) { - return $this->castForColumn($column); - }, - $columns - )); + return array_filter( + array_map( + function (Column $column) { + return $this->castForColumn($column); + }, + $columns + ) + ); } private function dateColumns(array $columns) @@ -314,11 +331,14 @@ private function dateColumns(array $columns) function (Column $column) { return $column->name(); }, - array_filter($columns, function (Column $column) { - return $column->dataType() === 'date' + array_filter( + $columns, + function (Column $column) { + return $column->dataType() === 'date' || stripos($column->dataType(), 'datetime') !== false || stripos($column->dataType(), 'timestamp') !== false; - }) + } + ) ); } @@ -421,7 +441,9 @@ private function fullyQualifyModelReference(string $model_name) // If not found, assume parallel namespace as controller. // Use respond-statement.php as test case. - /** @var \Blueprint\Models\Model $model */ + /** + * @var \Blueprint\Models\Model $model +*/ $model = $this->tree->modelForContext($model_name); if (isset($model)) { diff --git a/src/Generators/RouteGenerator.php b/src/Generators/RouteGenerator.php index 74667c2d..e381c734 100644 --- a/src/Generators/RouteGenerator.php +++ b/src/Generators/RouteGenerator.php @@ -9,12 +9,14 @@ class RouteGenerator implements Generator { - /** @var \Illuminate\Contracts\Filesystem\Filesystem */ - private $files; + /** + * @var \Illuminate\Filesystem\Filesystem + */ + private $filesystem; - public function __construct($files) + public function __construct($filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree): array @@ -25,7 +27,9 @@ public function output(Tree $tree): array $routes = ['api' => '', 'web' => '']; - /** @var \Blueprint\Models\Controller $controller */ + /** + * @var \Blueprint\Models\Controller $controller +*/ foreach ($tree->controllers() as $controller) { $type = $controller->isApiResource() ? 'api' : 'web'; $routes[$type] .= PHP_EOL . PHP_EOL . $this->buildRoutes($controller); @@ -35,7 +39,7 @@ public function output(Tree $tree): array foreach (array_filter($routes) as $type => $definitions) { $path = 'routes/' . $type . '.php'; - $this->files->append($path, $definitions . PHP_EOL); + $this->filesystem->append($path, $definitions . PHP_EOL); $paths[] = $path; } diff --git a/src/Generators/SeederGenerator.php b/src/Generators/SeederGenerator.php index 3ed75675..3e11401b 100644 --- a/src/Generators/SeederGenerator.php +++ b/src/Generators/SeederGenerator.php @@ -5,20 +5,25 @@ use Blueprint\Blueprint; use Blueprint\Contracts\Generator; use Blueprint\Tree; +use Illuminate\Filesystem\Filesystem; class SeederGenerator implements Generator { - /** @var \Illuminate\Contracts\Filesystem\Filesystem */ - private $files; - - /** @var Tree */ + /** + * @var Filesystem + */ + protected $filesystem; + + /** + * @var Tree + */ private $tree; private $imports = []; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree): array @@ -32,14 +37,14 @@ public function output(Tree $tree): array $output = []; if (Blueprint::isLaravel8OrHigher()) { - $stub = $this->files->stub('seeder.stub'); + $stub = $this->filesystem->stub('seeder.stub'); } else { - $stub = $this->files->stub('seeder.no-factory.stub'); + $stub = $this->filesystem->stub('seeder.no-factory.stub'); } foreach ($tree->seeders() as $model) { $path = $this->getPath($model); - $this->files->put($path, $this->populateStub($stub, $model)); + $this->filesystem->put($path, $this->populateStub($stub, $model)); $output['created'][] = $path; } @@ -90,9 +95,15 @@ protected function buildImports(string $model) $imports = array_unique($this->imports[$model]); sort($imports); - return implode(PHP_EOL, array_map(function ($class) { - return 'use ' . $class . ';'; - }, $imports)); + return implode( + PHP_EOL, + array_map( + function ($class) { + return 'use ' . $class . ';'; + }, + $imports + ) + ); } private function addImport(string $model, $class) diff --git a/src/Generators/StatementGenerator.php b/src/Generators/StatementGenerator.php index b48df0f6..6895870b 100644 --- a/src/Generators/StatementGenerator.php +++ b/src/Generators/StatementGenerator.php @@ -4,22 +4,23 @@ use Blueprint\Blueprint; use Blueprint\Contracts\Generator; +use Illuminate\Filesystem\Filesystem; abstract class StatementGenerator implements Generator { /** - * @var \Illuminate\Contracts\Filesystem\Filesystem + * @var Filesystem */ - protected $files; + protected $filesystem; /** * @var string */ protected $new_instance = 'new instance'; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } protected function buildConstructor($statement) @@ -27,7 +28,7 @@ protected function buildConstructor($statement) static $constructor = null; if (is_null($constructor)) { - $constructor = str_replace('new instance', $this->new_instance, $this->files->stub('constructor.stub')); + $constructor = str_replace('new instance', $this->new_instance, $this->filesystem->stub('constructor.stub')); } if (empty($statement->data())) { @@ -43,27 +44,42 @@ protected function buildConstructor($statement) protected function buildProperties(array $data) { - return trim(array_reduce($data, function ($output, $property) { - $output .= ' public $' . $property . ';' . PHP_EOL . PHP_EOL; + return trim( + array_reduce( + $data, + function ($output, $property) { + $output .= ' public $' . $property . ';' . PHP_EOL . PHP_EOL; - return $output; - }, '')); + return $output; + }, + '' + ) + ); } protected function buildAssignments(array $data) { - return trim(array_reduce($data, function ($output, $property) { - $output .= ' $this->' . $property . ' = $' . $property . ';' . PHP_EOL; + return trim( + array_reduce( + $data, + function ($output, $property) { + $output .= ' $this->' . $property . ' = $' . $property . ';' . PHP_EOL; - return $output; - }, '')); + return $output; + }, + '' + ) + ); } protected function buildParameters(array $data) { - $parameters = array_map(function ($parameter) { - return '$' . $parameter; - }, $data); + $parameters = array_map( + function ($parameter) { + return '$' . $parameter; + }, + $data + ); return implode(', ', $parameters); } diff --git a/src/Generators/Statements/EventGenerator.php b/src/Generators/Statements/EventGenerator.php index f64ce15b..0fc045ba 100644 --- a/src/Generators/Statements/EventGenerator.php +++ b/src/Generators/Statements/EventGenerator.php @@ -15,9 +15,11 @@ public function output(Tree $tree): array { $output = []; - $stub = $this->files->stub('event.stub'); + $stub = $this->filesystem->stub('event.stub'); - /** @var \Blueprint\Models\Controller $controller */ + /** + * @var \Blueprint\Models\Controller $controller +*/ foreach ($tree->controllers() as $controller) { foreach ($controller->methods() as $method => $statements) { foreach ($statements as $statement) { @@ -31,15 +33,15 @@ public function output(Tree $tree): array $path = $this->getPath($statement->event()); - if ($this->files->exists($path)) { + if ($this->filesystem->exists($path)) { continue; } - if (! $this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (! $this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $statement)); + $this->filesystem->put($path, $this->populateStub($stub, $statement)); $output['created'][] = $path; } diff --git a/src/Generators/Statements/FormRequestGenerator.php b/src/Generators/Statements/FormRequestGenerator.php index 6b6c6810..6d39bb41 100644 --- a/src/Generators/Statements/FormRequestGenerator.php +++ b/src/Generators/Statements/FormRequestGenerator.php @@ -8,6 +8,7 @@ use Blueprint\Models\Statements\ValidateStatement; use Blueprint\Translators\Rules; use Blueprint\Tree; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; class FormRequestGenerator implements Generator @@ -15,16 +16,18 @@ class FormRequestGenerator implements Generator private const INDENT = ' '; /** - * @var \Illuminate\Contracts\Filesystem\Filesystem + * @var Filesystem */ - private $files; + protected $filesystem; - /** @var Tree */ + /** + * @var Tree + */ private $tree; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree): array @@ -33,9 +36,11 @@ public function output(Tree $tree): array $output = []; - $stub = $this->files->stub('request.stub'); + $stub = $this->filesystem->stub('request.stub'); - /** @var \Blueprint\Models\Controller $controller */ + /** + * @var \Blueprint\Models\Controller $controller +*/ foreach ($tree->controllers() as $controller) { foreach ($controller->methods() as $method => $statements) { foreach ($statements as $statement) { @@ -47,15 +52,15 @@ public function output(Tree $tree): array $name = $this->getName($context, $method); $path = $this->getPath($controller, $name); - if ($this->files->exists($path)) { + if ($this->filesystem->exists($path)) { continue; } - if (! $this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (! $this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $name, $context, $statement, $controller)); + $this->filesystem->put($path, $this->populateStub($stub, $name, $context, $statement, $controller)); $output['created'][] = $path; } @@ -90,23 +95,29 @@ protected function populateStub(string $stub, string $name, $context, ValidateSt protected function buildRules(string $context, ValidateStatement $validateStatement) { - return trim(array_reduce($validateStatement->data(), function ($output, $field) use ($context) { - [$qualifier, $column] = $this->splitField($field); - - if (is_null($qualifier)) { - $qualifier = $context; - } + return trim( + array_reduce( + $validateStatement->data(), + function ($output, $field) use ($context) { + [$qualifier, $column] = $this->splitField($field); + + if (is_null($qualifier)) { + $qualifier = $context; + } - $validationRules = $this->validationRules($qualifier, $column); + $validationRules = $this->validationRules($qualifier, $column); - foreach ($validationRules as $name => $rule) { - $formattedRule = implode("', '", $rule); + foreach ($validationRules as $name => $rule) { + $formattedRule = implode("', '", $rule); - $output .= self::INDENT . "'{$name}' => ['{$formattedRule}']," . PHP_EOL; - } + $output .= self::INDENT . "'{$name}' => ['{$formattedRule}']," . PHP_EOL; + } - return $output; - }, '')); + return $output; + }, + '' + ) + ); } private function getName(string $context, string $method) @@ -125,7 +136,9 @@ private function splitField($field) private function validationRules(string $qualifier, string $column) { - /** @var \Blueprint\Models\Model $model */ + /** + * @var \Blueprint\Models\Model $model +*/ $model = $this->tree->modelForContext($qualifier); $rules = []; @@ -138,7 +151,9 @@ private function validationRules(string $qualifier, string $column) return $rules; } else { - /** @var \Blueprint\Models\Model $column */ + /** + * @var \Blueprint\Models\Model $column +*/ foreach ($model->columns() as $column) { if ($column->name() === 'id') { continue; diff --git a/src/Generators/Statements/JobGenerator.php b/src/Generators/Statements/JobGenerator.php index 3acc80e0..dc416e79 100644 --- a/src/Generators/Statements/JobGenerator.php +++ b/src/Generators/Statements/JobGenerator.php @@ -15,9 +15,11 @@ public function output(Tree $tree): array { $output = []; - $stub = $this->files->stub('job.stub'); + $stub = $this->filesystem->stub('job.stub'); - /** @var \Blueprint\Models\Controller $controller */ + /** + * @var \Blueprint\Models\Controller $controller +*/ foreach ($tree->controllers() as $controller) { foreach ($controller->methods() as $method => $statements) { foreach ($statements as $statement) { @@ -27,15 +29,15 @@ public function output(Tree $tree): array $path = $this->getPath($statement->job()); - if ($this->files->exists($path)) { + if ($this->filesystem->exists($path)) { continue; } - if (! $this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (! $this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $statement)); + $this->filesystem->put($path, $this->populateStub($stub, $statement)); $output['created'][] = $path; } diff --git a/src/Generators/Statements/MailGenerator.php b/src/Generators/Statements/MailGenerator.php index 2a1dbcbf..f8454467 100644 --- a/src/Generators/Statements/MailGenerator.php +++ b/src/Generators/Statements/MailGenerator.php @@ -15,9 +15,11 @@ public function output(Tree $tree): array { $output = []; - $stub = $this->files->stub('mail.stub'); + $stub = $this->filesystem->stub('mail.stub'); - /** @var \Blueprint\Models\Controller $controller */ + /** + * @var \Blueprint\Models\Controller $controller +*/ foreach ($tree->controllers() as $controller) { foreach ($controller->methods() as $method => $statements) { foreach ($statements as $statement) { @@ -31,15 +33,15 @@ public function output(Tree $tree): array $path = $this->getPath($statement->mail()); - if ($this->files->exists($path)) { + if ($this->filesystem->exists($path)) { continue; } - if (! $this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (! $this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $statement)); + $this->filesystem->put($path, $this->populateStub($stub, $statement)); $output['created'][] = $path; } diff --git a/src/Generators/Statements/NotificationGenerator.php b/src/Generators/Statements/NotificationGenerator.php index ed1419f7..08cd30e0 100644 --- a/src/Generators/Statements/NotificationGenerator.php +++ b/src/Generators/Statements/NotificationGenerator.php @@ -15,9 +15,11 @@ public function output(Tree $tree): array { $output = []; - $stub = $this->files->stub('notification.stub'); + $stub = $this->filesystem->stub('notification.stub'); - /** @var \Blueprint\Models\Controller $controller */ + /** + * @var \Blueprint\Models\Controller $controller +*/ foreach ($tree->controllers() as $controller) { foreach ($controller->methods() as $method => $statements) { foreach ($statements as $statement) { @@ -31,15 +33,15 @@ public function output(Tree $tree): array $path = $this->getPath($statement->mail()); - if ($this->files->exists($path)) { + if ($this->filesystem->exists($path)) { continue; } - if (!$this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (!$this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $statement)); + $this->filesystem->put($path, $this->populateStub($stub, $statement)); $output['created'][] = $path; } diff --git a/src/Generators/Statements/ResourceGenerator.php b/src/Generators/Statements/ResourceGenerator.php index 5ab46b82..d2d2d2ef 100644 --- a/src/Generators/Statements/ResourceGenerator.php +++ b/src/Generators/Statements/ResourceGenerator.php @@ -8,22 +8,26 @@ use Blueprint\Models\Model; use Blueprint\Models\Statements\ResourceStatement; use Blueprint\Tree; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; class ResourceGenerator implements Generator { const INDENT = ' '; + /** - * @var \Illuminate\Contracts\Filesystem\Filesystem + * @var Filesystem */ - private $files; + protected $filesystem; - /** @var Tree */ + /** + * @var Tree + */ private $tree; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree): array @@ -32,9 +36,11 @@ public function output(Tree $tree): array $output = []; - $stub = $this->files->stub('resource.stub'); + $stub = $this->filesystem->stub('resource.stub'); - /** @var \Blueprint\Models\Controller $controller */ + /** + * @var \Blueprint\Models\Controller $controller +*/ foreach ($tree->controllers() as $controller) { foreach ($controller->methods() as $method => $statements) { foreach ($statements as $statement) { @@ -44,15 +50,15 @@ public function output(Tree $tree): array $path = $this->getPath(($controller->namespace() ? $controller->namespace() . '/' : '') . $statement->name()); - if ($this->files->exists($path)) { + if ($this->filesystem->exists($path)) { continue; } - if (! $this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (! $this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $controller, $statement)); + $this->filesystem->put($path, $this->populateStub($stub, $controller, $statement)); $output['created'][] = $path; } @@ -96,7 +102,9 @@ protected function buildData(ResourceStatement $resource) { $context = Str::singular($resource->reference()); - /** @var \Blueprint\Models\Model $model */ + /** + * @var \Blueprint\Models\Model $model +*/ $model = $this->tree->modelForContext($context); $data = []; @@ -119,9 +127,12 @@ protected function buildData(ResourceStatement $resource) private function visibleColumns(Model $model) { - return array_diff(array_keys($model->columns()), [ + return array_diff( + array_keys($model->columns()), + [ 'password', 'remember_token', - ]); + ] + ); } } diff --git a/src/Generators/Statements/ViewGenerator.php b/src/Generators/Statements/ViewGenerator.php index bfde26d4..2500b887 100644 --- a/src/Generators/Statements/ViewGenerator.php +++ b/src/Generators/Statements/ViewGenerator.php @@ -5,26 +5,29 @@ use Blueprint\Contracts\Generator; use Blueprint\Models\Statements\RenderStatement; use Blueprint\Tree; +use Illuminate\Filesystem\Filesystem; class ViewGenerator implements Generator { /** - * @var \Illuminate\Contracts\Filesystem\Filesystem + * @var Filesystem */ - private $files; + protected $filesystem; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree): array { $output = []; - $stub = $this->files->stub('view.stub'); + $stub = $this->filesystem->stub('view.stub'); - /** @var \Blueprint\Models\Controller $controller */ + /** + * @var \Blueprint\Models\Controller $controller +*/ foreach ($tree->controllers() as $controller) { foreach ($controller->methods() as $method => $statements) { foreach ($statements as $statement) { @@ -34,16 +37,16 @@ public function output(Tree $tree): array $path = $this->getPath($statement->view()); - if ($this->files->exists($path)) { + if ($this->filesystem->exists($path)) { // TODO: mark skipped... continue; } - if (! $this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (! $this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $statement)); + $this->filesystem->put($path, $this->populateStub($stub, $statement)); $output['created'][] = $path; } diff --git a/src/Generators/TestGenerator.php b/src/Generators/TestGenerator.php index 5f6e8202..c64274ee 100644 --- a/src/Generators/TestGenerator.php +++ b/src/Generators/TestGenerator.php @@ -18,6 +18,7 @@ use Blueprint\Models\Statements\SessionStatement; use Blueprint\Models\Statements\ValidateStatement; use Blueprint\Tree; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\App; use Illuminate\Support\Str; use Shift\Faker\Registry as FakerRegistry; @@ -30,8 +31,8 @@ class TestGenerator implements Generator const TESTS_DELETE = 8; const TESTS_RESPONDS = 16; - /** @var \Illuminate\Contracts\Filesystem\Filesystem */ - private $files; + /** @var Filesystem */ + protected $filesystem; /** @var Tree */ private $tree; @@ -40,9 +41,9 @@ class TestGenerator implements Generator private $stubs = []; private $traits = []; - public function __construct($files) + public function __construct(Filesystem $filesystem) { - $this->files = $files; + $this->filesystem = $filesystem; } public function output(Tree $tree): array @@ -51,17 +52,17 @@ public function output(Tree $tree): array $output = []; - $stub = $this->files->stub('test.class.stub'); + $stub = $this->filesystem->stub('test.class.stub'); /** @var \Blueprint\Models\Controller $controller */ foreach ($tree->controllers() as $controller) { $path = $this->getPath($controller); - if (! $this->files->exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0755, true); + if (! $this->filesystem->exists(dirname($path))) { + $this->filesystem->makeDirectory(dirname($path), 0755, true); } - $this->files->put($path, $this->populateStub($stub, $controller)); + $this->filesystem->put($path, $this->populateStub($stub, $controller)); $output['created'][] = $path; } @@ -559,7 +560,7 @@ private function buildTraits(Controller $controller) private function testCaseStub() { if (empty($this->stubs['test-case'])) { - $this->stubs['test-case'] = $this->files->stub('test.case.stub'); + $this->stubs['test-case'] = $this->filesystem->stub('test.case.stub'); } return $this->stubs['test-case']; diff --git a/src/Tracer.php b/src/Tracer.php index 6d087e49..a3ba9fff 100644 --- a/src/Tracer.php +++ b/src/Tracer.php @@ -3,17 +3,17 @@ namespace Blueprint; use Doctrine\DBAL\Types\Type; -use Illuminate\Database\Eloquent\Model; use Illuminate\Filesystem\Filesystem; +use Illuminate\Database\Eloquent\Model; class Tracer { /** @var Filesystem */ - private $files; + private $filesystem; - public function execute(Blueprint $blueprint, Filesystem $files): array + public function execute(Blueprint $blueprint, Filesystem $filesystem): array { - $this->files = $files; + $this->filesystem = $filesystem; $definitions = []; foreach ($this->appClasses() as $class) { @@ -30,13 +30,13 @@ public function execute(Blueprint $blueprint, Filesystem $files): array } $cache = []; - if ($files->exists('.blueprint')) { - $cache = $blueprint->parse($files->get('.blueprint')); + if ($filesystem->exists('.blueprint')) { + $cache = $blueprint->parse($filesystem->get('.blueprint')); } $cache['models'] = $definitions; - $files->put('.blueprint', $blueprint->dump($cache)); + $filesystem->put('.blueprint', $blueprint->dump($cache)); return $definitions; } @@ -49,7 +49,7 @@ private function appClasses() $dir .= '/' . str_replace('\\', '/', config('blueprint.models_namespace')); } - if (!$this->files->exists($dir)) { + if (!$this->filesystem->exists($dir)) { return []; } @@ -59,7 +59,7 @@ private function appClasses() [config('blueprint.namespace') . '\\', '\\'], $file->getPath() . '/' . $file->getBasename('.php') ); - }, $this->files->allFiles($dir)); + }, $this->filesystem->allFiles($dir)); } private function loadModel(string $class) diff --git a/tests/Feature/Commands/BuildCommandTest.php b/tests/Feature/Commands/BuildCommandTest.php index c9d2d950..457bd53c 100644 --- a/tests/Feature/Commands/BuildCommandTest.php +++ b/tests/Feature/Commands/BuildCommandTest.php @@ -6,7 +6,6 @@ use Blueprint\Builder; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use Tests\TestCase; -use Tests\Traits\MocksFilesystem; /** * @covers \Blueprint\Commands\BuildCommand @@ -14,12 +13,11 @@ class BuildCommandTest extends TestCase { use MockeryPHPUnitIntegration; - use MocksFilesystem; /** @test */ public function it_uses_the_default_draft_file() { - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->with('draft.yaml') ->andReturnTrue(); @@ -36,7 +34,7 @@ public function it_uses_the_default_draft_file() /** @test */ public function it_passes_the_command_args_to_the_builder_in_right_order() { - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->with('test.yml') ->andReturnTrue(); @@ -53,7 +51,7 @@ public function it_passes_the_command_args_to_the_builder_in_right_order() /** @test */ public function it_fails_if_the_draft_file_not_exists() { - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->with('test.yml') ->andReturnFalse(); @@ -68,7 +66,7 @@ public function it_fails_if_the_draft_file_not_exists() /** @test */ public function it_shows_the_generated_files_grouped_by_actions() { - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->with('draft.yaml') ->andReturnTrue(); $builder = $this->mock(Builder::class); diff --git a/tests/Feature/Commands/EraseCommandTest.php b/tests/Feature/Commands/EraseCommandTest.php index e85f59b0..ed3c69c9 100644 --- a/tests/Feature/Commands/EraseCommandTest.php +++ b/tests/Feature/Commands/EraseCommandTest.php @@ -6,7 +6,6 @@ use Blueprint\Tracer; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use Tests\TestCase; -use Tests\Traits\MocksFilesystem; /** * @covers \Blueprint\Commands\EraseCommand @@ -14,21 +13,20 @@ class EraseCommandTest extends TestCase { use MockeryPHPUnitIntegration; - use MocksFilesystem; /** @test */ public function it_parses_and_update_the_trace_file() { - $this->files->expects('get') + $this->filesystem->expects('get') ->with('.blueprint') ->andReturn("created: created_file.php \nupdated: updated_file.php \nother: test.php"); - $this->files->expects('delete')->with("created_file.php"); + $this->filesystem->expects('delete')->with("created_file.php"); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('.blueprint', "other: test.php\n"); - $this->files->expects('exists')->with('app'); + $this->filesystem->expects('exists')->with('app'); $this->artisan('blueprint:erase') ->assertExitCode(0); @@ -37,17 +35,17 @@ public function it_parses_and_update_the_trace_file() /** @test */ public function it_deletes_the_created_files() { - $this->files->expects('get') + $this->filesystem->expects('get') ->with('.blueprint') ->andReturn("created:\n - created_file1.php\n - created_file2.php"); - $this->files->expects('delete')->with([ + $this->filesystem->expects('delete')->with([ "created_file1.php", "created_file2.php", ]); - $this->files->expects('put')->with('.blueprint', '{ }'); - $this->files->expects('exists')->with('app'); + $this->filesystem->expects('put')->with('.blueprint', '{ }'); + $this->filesystem->expects('exists')->with('app'); $this->artisan('blueprint:erase') ->assertExitCode(0) @@ -59,12 +57,12 @@ public function it_deletes_the_created_files() /** @test */ public function it_notify_about_the_updated_files() { - $this->files->expects('get') + $this->filesystem->expects('get') ->with('.blueprint') ->andReturn("updated:\n - updated_file1.php\n - updated_file2.php"); - $this->files->expects('put')->with('.blueprint', '{ }'); - $this->files->expects('exists')->with('app'); + $this->filesystem->expects('put')->with('.blueprint', '{ }'); + $this->filesystem->expects('exists')->with('app'); $this->artisan('blueprint:erase') ->assertExitCode(0) @@ -76,8 +74,8 @@ public function it_notify_about_the_updated_files() /** @test */ public function it_calls_the_trace_command() { - $this->files->expects('get')->with('.blueprint')->andReturn("other: test.php"); - $this->files->expects('put')->with('.blueprint', "other: test.php\n"); + $this->filesystem->expects('get')->with('.blueprint')->andReturn("other: test.php"); + $this->filesystem->expects('put')->with('.blueprint', "other: test.php\n"); $tracer = $this->spy(Tracer::class); @@ -85,6 +83,6 @@ public function it_calls_the_trace_command() ->assertExitCode(0); $tracer->shouldHaveReceived('execute') - ->with(resolve(Blueprint::class), $this->files); + ->with(resolve(Blueprint::class), $this->filesystem); } } diff --git a/tests/Feature/Commands/InitCommandTest.php b/tests/Feature/Commands/InitCommandTest.php index 2df17b64..d062e658 100644 --- a/tests/Feature/Commands/InitCommandTest.php +++ b/tests/Feature/Commands/InitCommandTest.php @@ -5,7 +5,6 @@ use Blueprint\Commands\NewCommand; use Illuminate\Contracts\Console\Kernel; use Tests\TestCase; -use Tests\Traits\MocksFilesystem; use Illuminate\Support\Facades\Artisan; use Mockery; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; @@ -16,24 +15,22 @@ class InitCommandTest extends TestCase { use MockeryPHPUnitIntegration; - use MocksFilesystem; - /** * @test */ public function it_creates_a_draft_file_from_stub_if_none_exists() { - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->with('draft.yaml') ->andReturnFalse(); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('draft.stub') ->andReturn('stub'); - $this->files->shouldReceive('put') + $this->filesystem->shouldReceive('put') ->with('draft.yaml', 'stub'); - $this->files->shouldReceive('exists')->with('app'); + $this->filesystem->shouldReceive('exists')->with('app'); $this->artisan('blueprint:init') ->assertExitCode(0); @@ -44,11 +41,11 @@ public function it_creates_a_draft_file_from_stub_if_none_exists() */ public function it_does_not_create_a_draft_file_if_one_exists_already() { - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->with('draft.yaml') ->andReturnTrue(); - $this->files->shouldNotReceive('put'); - $this->files->shouldReceive('exists') + $this->filesystem->shouldNotReceive('put'); + $this->filesystem->shouldReceive('exists') ->with('app'); $this->artisan('blueprint:init') diff --git a/tests/Feature/Commands/NewCommandTest.php b/tests/Feature/Commands/NewCommandTest.php index a203f2d5..205c495b 100644 --- a/tests/Feature/Commands/NewCommandTest.php +++ b/tests/Feature/Commands/NewCommandTest.php @@ -4,7 +4,6 @@ use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use Tests\TestCase; -use Tests\Traits\MocksFilesystem; /** * @covers \Blueprint\Commands\NewCommand @@ -12,23 +11,22 @@ class NewCommandTest extends TestCase { use MockeryPHPUnitIntegration; - use MocksFilesystem; /** * @test */ public function it_creates_a_draft_file_from_stub_if_none_exists() { - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->with('draft.yaml') ->andReturnFalse(); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('draft.stub') ->andReturn('stub'); - $this->files->shouldReceive('put') + $this->filesystem->shouldReceive('put') ->with('draft.yaml', 'stub'); - $this->files->shouldReceive('exists')->with('app'); + $this->filesystem->shouldReceive('exists')->with('app'); $this->artisan('blueprint:new') ->assertExitCode(0); @@ -37,11 +35,11 @@ public function it_creates_a_draft_file_from_stub_if_none_exists() /** @test */ public function it_does_not_create_a_draft_file_if_one_exists_already() { - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->with('draft.yaml') ->andReturnTrue(); - $this->files->shouldNotReceive('put'); - $this->files->shouldReceive('exists') + $this->filesystem->shouldNotReceive('put'); + $this->filesystem->shouldReceive('exists') ->with('app'); $this->artisan('blueprint:new') diff --git a/tests/Feature/Commands/TraceCommandTest.php b/tests/Feature/Commands/TraceCommandTest.php index d384c466..4a281319 100644 --- a/tests/Feature/Commands/TraceCommandTest.php +++ b/tests/Feature/Commands/TraceCommandTest.php @@ -6,9 +6,9 @@ use Blueprint\Builder; use Blueprint\Commands\TraceCommand; use Blueprint\Tracer; +use Illuminate\Support\Facades\File; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use Tests\TestCase; -use Tests\Traits\MocksFilesystem; /** * @covers \Blueprint\Commands\TraceCommand @@ -16,7 +16,6 @@ class TraceCommandTest extends TestCase { use MockeryPHPUnitIntegration; - use MocksFilesystem; /** @test */ public function it_shows_error_if_no_model_found() diff --git a/tests/Feature/Generators/ControllerGeneratorTest.php b/tests/Feature/Generators/ControllerGeneratorTest.php index 1d78136e..b49ad5c0 100644 --- a/tests/Feature/Generators/ControllerGeneratorTest.php +++ b/tests/Feature/Generators/ControllerGeneratorTest.php @@ -6,6 +6,7 @@ use Blueprint\Generators\ControllerGenerator; use Blueprint\Lexers\StatementLexer; use Blueprint\Tree; +use Illuminate\Support\Facades\File; use Tests\TestCase; /** @@ -15,8 +16,6 @@ class ControllerGeneratorTest extends TestCase { private $blueprint; - private $files; - /** @var ControllerGenerator */ private $subject; @@ -24,8 +23,7 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); - $this->subject = new ControllerGenerator($this->files); + $this->subject = new ControllerGenerator($this->filesystem); $this->blueprint = new Blueprint(); $this->blueprint->registerLexer(new \Blueprint\Lexers\ModelLexer()); @@ -38,11 +36,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.class.stub') ->andReturn($this->stub('controller.class.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['controllers' => []]))); } @@ -53,17 +51,17 @@ public function output_writes_nothing_for_empty_tree() */ public function output_writes_migration_for_controller_tree($definition, $path, $controller) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.class.stub') ->andReturn($this->stub('controller.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.method.stub') ->andReturn($this->stub('controller.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($path)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($controller)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -82,17 +80,17 @@ public function output_generates_controllers_with_models_with_custom_namespace_c $this->app['config']->set('blueprint.models_namespace', 'Models'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.class.stub') ->andReturn($this->stub('controller.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.method.stub') ->andReturn($this->stub('controller.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($path)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($controller)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -106,10 +104,10 @@ public function output_generates_controllers_with_models_with_custom_namespace_c */ public function output_works_for_pascal_case_definition() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.class.stub') ->andReturn($this->stub('controller.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.method.stub') ->andReturn($this->stub('controller.method.stub')) ->twice(); @@ -117,16 +115,16 @@ public function output_works_for_pascal_case_definition() $certificateController = 'app/Http/Controllers/CertificateController.php'; $certificateTypeController = 'app/Http/Controllers/CertificateTypeController.php'; - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($certificateController)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($certificateController, $this->fixture('controllers/certificate-controller.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($certificateTypeController)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($certificateTypeController, $this->fixture('controllers/certificate-type-controller.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/pascal-case.yaml')); @@ -143,19 +141,19 @@ public function output_respects_configuration() $this->app['config']->set('blueprint.namespace', 'Some\\App'); $this->app['config']->set('blueprint.controllers_namespace', 'Other\\Http'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.class.stub') ->andReturn($this->stub('controller.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.method.stub') ->andReturn($this->stub('controller.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Other/Http') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Other/Http', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Other/Http/UserController.php', $this->fixture('controllers/controller-configured.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/simple-controller.yaml')); @@ -173,22 +171,22 @@ public function output_using_return_types() { $this->app['config']->set('blueprint.use_return_types', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.class.stub') ->andReturn($this->stub('controller.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('controller.method.stub') ->andReturn($this->stub('controller.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Controllers') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Http/Controllers', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Controllers/TermController.php', $this->fixture('controllers/return-type-declarations.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/return-type-declarations.yaml')); diff --git a/tests/Feature/Generators/FactoryGeneratorTest.php b/tests/Feature/Generators/FactoryGeneratorTest.php index 7889d93e..645ebdbc 100644 --- a/tests/Feature/Generators/FactoryGeneratorTest.php +++ b/tests/Feature/Generators/FactoryGeneratorTest.php @@ -15,7 +15,7 @@ class FactoryGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var FactoryGenerator */ private $subject; @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->factoryStub = version_compare(App::version(), '8.0.0', '>=') ? 'factory.stub' : 'factory.closure.stub'; $this->subject = new FactoryGenerator($this->files); @@ -38,11 +37,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->factoryStub) ->andReturn($this->stub($this->factoryStub)); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['models' => []]))); } @@ -54,15 +53,15 @@ public function output_writes_nothing_for_empty_tree() */ public function output_writes_factory_for_model_tree($definition, $path, $factory) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->factoryStub) ->andReturn($this->stub($this->factoryStub)); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('database/factories') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($factory)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -78,15 +77,15 @@ public function output_writes_factory_for_model_tree($definition, $path, $factor */ public function output_writes_factory_for_model_tree_l7($definition, $path, $factory) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->factoryStub) ->andReturn($this->stub($this->factoryStub)); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('database/factories') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($factory)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -102,15 +101,15 @@ public function output_writes_factory_for_model_tree_l7($definition, $path, $fac */ public function output_writes_factory_for_model_tree_l6($definition, $path, $factory) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->factoryStub) ->andReturn($this->stub($this->factoryStub)); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('database/factories') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($factory)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -127,15 +126,15 @@ public function output_ignores_nullables_if_fake_nullables_configuration_is_set_ { $this->app['config']->set('blueprint.fake_nullables', false); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->factoryStub) ->andReturn($this->stub($this->factoryStub)); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('database/factories') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/factories/PostFactory.php', $this->fixture('factories/fake-nullables-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example.yaml')); @@ -152,15 +151,15 @@ public function output_using_return_types() { $this->app['config']->set('blueprint.use_return_types', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->factoryStub) ->andReturn($this->stub($this->factoryStub)); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('database/factories') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/factories/PostFactory.php', $this->fixture('factories/return-type-declarations-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example.yaml')); @@ -175,21 +174,21 @@ public function output_using_return_types() */ public function output_generates_references_for_nested_models() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->factoryStub) ->andReturn($this->stub($this->factoryStub)); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->times(4) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/factories/QuestionTypeFactory.php', \Mockery::type('string')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/factories/Appointment/AppointmentTypeFactory.php', \Mockery::type('string')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/factories/Screening/ReportFactory.php', \Mockery::type('string')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/factories/Screening/ScreeningQuestionFactory.php', $this->fixture('factories/nested-models-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/nested-models.yaml')); @@ -214,15 +213,15 @@ public function output_respects_configuration() $this->app['config']->set('blueprint.namespace', 'Some\\App'); $this->app['config']->set('blueprint.models_namespace', 'Models'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->factoryStub) ->andReturn($this->stub($this->factoryStub)); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('database/factories') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/factories/PostFactory.php', $this->fixture('factories/post-configured-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/post.yaml')); @@ -237,17 +236,17 @@ public function output_respects_configuration() */ public function output_creates_directory_for_nested_components() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->factoryStub) ->andReturn($this->stub($this->factoryStub)); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('database/factories/Admin') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('database/factories/Admin', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/factories/Admin/UserFactory.php', $this->fixture('factories/nested-components-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/nested-components.yaml')); diff --git a/tests/Feature/Generators/MigrationGeneratorTest.php b/tests/Feature/Generators/MigrationGeneratorTest.php index 37d4c777..50bf723d 100644 --- a/tests/Feature/Generators/MigrationGeneratorTest.php +++ b/tests/Feature/Generators/MigrationGeneratorTest.php @@ -17,7 +17,7 @@ class MigrationGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var MigrationGenerator */ private $subject; @@ -26,7 +26,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->subject = new MigrationGenerator($this->files); $this->blueprint = new Blueprint(); @@ -39,11 +38,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['models' => []]))); } @@ -58,7 +57,7 @@ public function output_writes_migration_for_model_tree($definition, $path, $migr $this->app['config']->set('blueprint.use_return_types', true); } - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -67,11 +66,11 @@ public function output_writes_migration_for_model_tree($definition, $path, $migr $timestamp_path = str_replace('timestamp', $now->format('Y_m_d_His'), $path); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with($timestamp_path) ->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($timestamp_path, $this->fixture($migration)); $tokens = $this->blueprint->parse($this->fixture($definition), $definition !== 'drafts/indexes.yaml'); @@ -90,7 +89,7 @@ public function output_updates_migration_for_model_tree($definition, $path, $mig $this->app['config']->set('blueprint.use_return_types', true); } - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -98,17 +97,17 @@ public function output_updates_migration_for_model_tree($definition, $path, $mig $yesterday_path = str_replace('timestamp', $yday->format('Y_m_d_His'), $path); - $this->files->expects('files') + $this->filesystem->expects('files') ->with('database/migrations/') ->andReturn([ new SplFileInfo($yesterday_path, '', ''), ]); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with($yesterday_path) ->andReturn(true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($yesterday_path, $this->fixture($migration)); $tokens = $this->blueprint->parse($this->fixture($definition), $definition !== 'drafts/indexes.yaml'); @@ -122,7 +121,7 @@ public function output_updates_migration_for_model_tree($definition, $path, $mig */ public function output_writes_migration_for_foreign_shorthand() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -131,9 +130,9 @@ public function output_writes_migration_for_foreign_shorthand() $timestamp_path = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_comments_table.php'); - $this->files->expects('exists')->andReturn(false); + $this->filesystem->expects('exists')->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($timestamp_path, $this->fixture('migrations/foreign-key-shorthand.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/foreign-key-shorthand.yaml')); @@ -147,7 +146,7 @@ public function output_writes_migration_for_foreign_shorthand() */ public function output_uses_past_timestamp_for_multiple_migrations() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -157,11 +156,11 @@ public function output_uses_past_timestamp_for_multiple_migrations() $post_path = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_posts_table.php'); $comment_path = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_comments_table.php'); - $this->files->expects('exists')->twice()->andReturn(false); + $this->filesystem->expects('exists')->twice()->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($post_path, $this->fixture('migrations/posts.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($comment_path, $this->fixture('migrations/comments.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/multiple-models.yaml')); @@ -175,7 +174,7 @@ public function output_uses_past_timestamp_for_multiple_migrations() */ public function output_proper_pascal_case_model_names() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -186,13 +185,13 @@ public function output_proper_pascal_case_model_names() $broker_type_path = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_broker_types_table.php'); $broker_broker_type_path = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_broker_broker_type_table.php'); - $this->files->expects('exists')->times(3)->andReturn(false); + $this->filesystem->expects('exists')->times(3)->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($broker_path, $this->fixture('migrations/pascal-case-model-names-broker.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($broker_type_path, $this->fixture('migrations/pascal-case-model-names-broker-type.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($broker_broker_type_path, $this->fixture('migrations/pascal-case-model-names-broker-broker-type.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/pascal-case-model-names.yaml')); @@ -207,7 +206,7 @@ public function output_proper_pascal_case_model_names() */ public function output_uses_proper_data_type_for_id_columns_in_laravel6() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -216,9 +215,9 @@ public function output_uses_proper_data_type_for_id_columns_in_laravel6() $timestamp_path = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_relationships_table.php'); - $this->files->expects('exists')->andReturn(false); + $this->filesystem->expects('exists')->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($timestamp_path, $this->fixture('migrations/identity-columns-big-increments.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/model-identities.yaml')); @@ -234,7 +233,7 @@ public function output_creates_constraints_for_unconventional_foreign_reference_ { $this->app->config->set('blueprint.use_constraints', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -243,9 +242,9 @@ public function output_creates_constraints_for_unconventional_foreign_reference_ $model_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_comments_table.php'); - $this->files->expects('exists')->andReturn(false); + $this->filesystem->expects('exists')->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/relationships-constraints.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/relationships.yaml')); @@ -262,7 +261,7 @@ public function output_creates_constraints_for_unconventional_foreign_reference_ { $this->app->config->set('blueprint.use_constraints', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -271,9 +270,9 @@ public function output_creates_constraints_for_unconventional_foreign_reference_ $model_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_comments_table.php'); - $this->files->expects('exists')->andReturn(false); + $this->filesystem->expects('exists')->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/relationships-constraints-laravel6.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/relationships.yaml')); @@ -287,7 +286,7 @@ public function output_creates_constraints_for_unconventional_foreign_reference_ */ public function output_also_creates_pivot_table_migration() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -297,11 +296,11 @@ public function output_also_creates_pivot_table_migration() $model_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_journeys_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_diary_journey_table.php'); - $this->files->expects('exists')->twice()->andReturn(false); + $this->filesystem->expects('exists')->twice()->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/belongs-to-many.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/belongs-to-many-pivot.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/belongs-to-many.yaml')); @@ -315,7 +314,7 @@ public function output_also_creates_pivot_table_migration() */ public function output_also_updates_pivot_table_migration() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -324,7 +323,7 @@ public function output_also_updates_pivot_table_migration() $model_migration = str_replace('timestamp', $yday->format('Y_m_d_His'), 'database/migrations/timestamp_create_journeys_table.php'); $pivot_migration = str_replace('timestamp', $yday->format('Y_m_d_His'), 'database/migrations/timestamp_create_diary_journey_table.php'); - $this->files->expects('files') + $this->filesystem->expects('files') ->with('database/migrations/') ->twice() ->andReturn([ @@ -332,12 +331,12 @@ public function output_also_updates_pivot_table_migration() new SplFileInfo($pivot_migration, '', ''), ]); - $this->files->expects('exists')->with($model_migration)->andReturn(true); - $this->files->expects('exists')->with($pivot_migration)->andReturn(true); + $this->filesystem->expects('exists')->with($model_migration)->andReturn(true); + $this->filesystem->expects('exists')->with($pivot_migration)->andReturn(true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/belongs-to-many.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/belongs-to-many-pivot.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/belongs-to-many.yaml')); @@ -352,7 +351,7 @@ public function output_also_updates_pivot_table_migration() */ public function output_also_creates_pivot_table_migration_laravel6() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -362,12 +361,12 @@ public function output_also_creates_pivot_table_migration_laravel6() $model_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_journeys_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_diary_journey_table.php'); - $this->files->expects('exists')->twice()->andReturn(false); + $this->filesystem->expects('exists')->twice()->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/belongs-to-many-laravel6.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/belongs-to-many-pivot-laravel6.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/belongs-to-many.yaml')); @@ -383,7 +382,7 @@ public function output_also_creates_constraints_for_pivot_table_migration() { $this->app->config->set('blueprint.use_constraints', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -393,12 +392,12 @@ public function output_also_creates_constraints_for_pivot_table_migration() $model_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_journeys_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_diary_journey_table.php'); - $this->files->expects('exists')->twice()->andReturn(false); + $this->filesystem->expects('exists')->twice()->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/belongs-to-many-key-constraints.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/belongs-to-many-pivot-key-constraints.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/belongs-to-many.yaml')); @@ -415,7 +414,7 @@ public function output_also_creates_constraints_for_pivot_table_migration_larave { $this->app->config->set('blueprint.use_constraints', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -425,11 +424,11 @@ public function output_also_creates_constraints_for_pivot_table_migration_larave $model_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_journeys_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_diary_journey_table.php'); - $this->files->expects('exists')->twice()->andReturn(false); + $this->filesystem->expects('exists')->twice()->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/belongs-to-many-key-constraints-laravel6.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/belongs-to-many-pivot-key-constraints-laravel6.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/belongs-to-many.yaml')); @@ -443,7 +442,7 @@ public function output_also_creates_constraints_for_pivot_table_migration_larave */ public function output_does_not_duplicate_pivot_table_migration() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -454,13 +453,13 @@ public function output_does_not_duplicate_pivot_table_migration() $people_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_people_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_company_person_table.php'); - $this->files->expects('exists')->times(3)->andReturn(false); + $this->filesystem->expects('exists')->times(3)->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($company_migration, $this->fixture('migrations/belongs-to-many-duplicated-company.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($people_migration, $this->fixture('migrations/belongs-to-many-duplicated-people.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/belongs-to-many-duplicated-pivot.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/belongs-to-many-duplicated-pivot.yaml')); @@ -475,7 +474,7 @@ public function output_does_not_duplicate_pivot_table_migration() */ public function output_does_not_duplicate_pivot_table_migration_laravel6() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -486,13 +485,13 @@ public function output_does_not_duplicate_pivot_table_migration_laravel6() $people_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_people_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_company_person_table.php'); - $this->files->expects('exists')->times(3)->andReturn(false); + $this->filesystem->expects('exists')->times(3)->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($company_migration, $this->fixture('migrations/belongs-to-many-duplicated-company-laravel6.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($people_migration, $this->fixture('migrations/belongs-to-many-duplicated-people-laravel6.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/belongs-to-many-duplicated-pivot-laravel6.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/belongs-to-many-duplicated-pivot.yaml')); @@ -506,7 +505,7 @@ public function output_does_not_duplicate_pivot_table_migration_laravel6() */ public function output_also_creates_pivot_table_migration_with_custom_name() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -516,11 +515,11 @@ public function output_also_creates_pivot_table_migration_with_custom_name() $model_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_users_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_test_table.php'); - $this->files->expects('exists')->twice()->andReturn(false); + $this->filesystem->expects('exists')->twice()->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/custom-pivot-table-name-user.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/custom-pivot-table-name-test.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/custom-pivot-table-name.yaml')); @@ -535,7 +534,7 @@ public function output_also_creates_pivot_table_migration_with_custom_name() */ public function output_also_creates_pivot_table_migration_with_custom_name_laravel6() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -545,11 +544,11 @@ public function output_also_creates_pivot_table_migration_with_custom_name_larav $model_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_users_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_test_table.php'); - $this->files->expects('exists')->twice()->andReturn(false); + $this->filesystem->expects('exists')->twice()->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/custom-pivot-table-name-user-laravel6.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/custom-pivot-table-name-test-laravel6.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/custom-pivot-table-name.yaml')); @@ -563,7 +562,7 @@ public function output_also_creates_pivot_table_migration_with_custom_name_larav */ public function output_creates_pivot_table_migration_correctly_when_model_name_contains_path_prefix() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -573,11 +572,11 @@ public function output_creates_pivot_table_migration_correctly_when_model_name_c $model_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_regions_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_city_region_table.php'); - $this->files->expects('exists')->twice()->andReturn(false); + $this->filesystem->expects('exists')->twice()->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/with-path-prefix-table-name-region.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/with-path-prefix-table-name-city-region.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/with-path-prefix.yaml')); @@ -592,7 +591,7 @@ public function output_creates_pivot_table_migration_correctly_when_model_name_c */ public function output_creates_pivot_table_migration_correctly_when_model_name_contains_path_prefix_laravel6() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -602,11 +601,11 @@ public function output_creates_pivot_table_migration_correctly_when_model_name_c $model_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_regions_table.php'); $pivot_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_city_region_table.php'); - $this->files->expects('exists')->twice()->andReturn(false); + $this->filesystem->expects('exists')->twice()->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($model_migration, $this->fixture('migrations/with-path-prefix-table-name-region-laravel6.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($pivot_migration, $this->fixture('migrations/with-path-prefix-table-name-city-region-laravel6.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/with-path-prefix.yaml')); @@ -623,7 +622,7 @@ public function output_creates_foreign_keys_with_nullable_chained_correctly() $this->app->config->set('blueprint.use_constraints', true); $this->app->config->set('blueprint.on_delete', 'null'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -632,7 +631,7 @@ public function output_creates_foreign_keys_with_nullable_chained_correctly() $model_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_carts_table.php'); - $this->files->expects('exists')->andReturn(false); + $this->filesystem->expects('exists')->andReturn(false); $this->files ->expects('put') @@ -653,7 +652,7 @@ public function output_creates_foreign_keys_with_nullable_chained_correctly_lara $this->app->config->set('blueprint.use_constraints', true); $this->app->config->set('blueprint.on_delete', 'null'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -662,7 +661,7 @@ public function output_creates_foreign_keys_with_nullable_chained_correctly_lara $model_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_carts_table.php'); - $this->files->expects('exists')->andReturn(false); + $this->filesystem->expects('exists')->andReturn(false); $this->files ->expects('put') @@ -679,7 +678,7 @@ public function output_creates_foreign_keys_with_nullable_chained_correctly_lara */ public function output_creates_foreign_keys_with_on_delete() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -688,7 +687,7 @@ public function output_creates_foreign_keys_with_on_delete() $model_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_comments_table.php'); - $this->files->expects('exists')->andReturn(false); + $this->filesystem->expects('exists')->andReturn(false); $this->files ->expects('put') @@ -706,7 +705,7 @@ public function output_creates_foreign_keys_with_on_delete() */ public function output_creates_foreign_keys_with_on_delete_laravel6() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -715,7 +714,7 @@ public function output_creates_foreign_keys_with_on_delete_laravel6() $model_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_comments_table.php'); - $this->files->expects('exists')->andReturn(false); + $this->filesystem->expects('exists')->andReturn(false); $this->files ->expects('put') @@ -732,7 +731,7 @@ public function output_creates_foreign_keys_with_on_delete_laravel6() */ public function output_works_with_polymorphic_relationships() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -743,13 +742,13 @@ public function output_works_with_polymorphic_relationships() $user_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_users_table.php'); $image_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_images_table.php'); - $this->files->expects('exists')->times(3)->andReturn(false); + $this->filesystem->expects('exists')->times(3)->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($post_migration, $this->fixture('migrations/polymorphic_relationships_posts_table.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($user_migration, $this->fixture('migrations/polymorphic_relationships_users_table.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($image_migration, $this->fixture('migrations/polymorphic_relationships_images_table.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/polymorphic-relationships.yaml')); @@ -764,7 +763,7 @@ public function output_works_with_polymorphic_relationships() */ public function output_works_with_polymorphic_relationships_laravel6() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -775,13 +774,13 @@ public function output_works_with_polymorphic_relationships_laravel6() $user_migration = str_replace('timestamp', $now->copy()->subSecond()->format('Y_m_d_His'), 'database/migrations/timestamp_create_users_table.php'); $image_migration = str_replace('timestamp', $now->format('Y_m_d_His'), 'database/migrations/timestamp_create_images_table.php'); - $this->files->expects('exists')->times(3)->andReturn(false); + $this->filesystem->expects('exists')->times(3)->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($post_migration, $this->fixture('migrations/polymorphic_relationships_posts_table_laravel6.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($user_migration, $this->fixture('migrations/polymorphic_relationships_users_table_laravel6.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($image_migration, $this->fixture('migrations/polymorphic_relationships_images_table_laravel6.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/polymorphic-relationships.yaml')); @@ -797,7 +796,7 @@ public function output_does_not_generate_relationship_for_uuid() { $this->app->config->set('blueprint.use_constraints', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -806,11 +805,11 @@ public function output_does_not_generate_relationship_for_uuid() $timestamp_path = 'database/migrations/' . $now->format('Y_m_d_His') . '_create_vats_table.php'; - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with($timestamp_path) ->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($timestamp_path, $this->fixture('migrations/uuid-without-relationship.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/uuid-without-relationship.yaml')); @@ -826,7 +825,7 @@ public function output_generates_constraint_for_uuid() { $this->app->config->set('blueprint.use_constraints', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('migration.stub') ->andReturn($this->stub('migration.stub')); @@ -835,11 +834,11 @@ public function output_generates_constraint_for_uuid() $timestamp_path = 'database/migrations/' . $now->format('Y_m_d_His') . '_create_people_table.php'; - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with($timestamp_path) ->andReturn(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($timestamp_path, $this->fixture('migrations/uuid-shorthand-constraint.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/uuid-shorthand.yaml')); diff --git a/tests/Feature/Generators/ModelGeneratorTest.php b/tests/Feature/Generators/ModelGeneratorTest.php index 33b2805e..0ea16d65 100644 --- a/tests/Feature/Generators/ModelGeneratorTest.php +++ b/tests/Feature/Generators/ModelGeneratorTest.php @@ -12,7 +12,7 @@ class ModelGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var ModelGenerator */ private $subject; @@ -21,7 +21,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->modelStub = version_compare(App::version(), '8.0.0', '>=') ? 'model.class.stub' : 'model.class.no-factory.stub'; $this->subject = new ModelGenerator($this->files); @@ -35,11 +34,11 @@ protected function setUp(): void */ public function output_generates_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['models' => []]))); } @@ -54,36 +53,36 @@ public function output_generates_models($definition, $path, $model) if ($model === 'models/return-type-declarations.php') { $this->app['config']->set('blueprint.use_return_types', true); } - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); if (in_array($definition, ['drafts/nested-components.yaml', 'drafts/resource-statements.yaml'])) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.hidden.stub') ->andReturn($this->stub('model.hidden.stub')); } - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.comment.stub') ->andReturn($this->stub('model.method.comment.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($path)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($model)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -99,42 +98,42 @@ public function output_generates_models($definition, $path, $model) */ public function output_generates_models_l7($definition, $path, $model) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); if (in_array($definition, ['drafts/nested-components.yaml', 'drafts/resource-statements.yaml'])) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.hidden.stub') ->andReturn($this->stub('model.hidden.stub')); } - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); if (in_array($definition, ['drafts/readme-example.yaml', 'drafts/all-column-types.yaml'])) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.dates.stub') ->andReturn($this->stub('model.dates.stub')); } - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.comment.stub') ->andReturn($this->stub('model.method.comment.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($path)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture(str_replace('models', 'models', $model))); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -150,42 +149,42 @@ public function output_generates_models_l7($definition, $path, $model) */ public function output_generates_models_l6($definition, $path, $model) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); if (in_array($definition, ['drafts/nested-components.yaml', 'drafts/resource-statements.yaml'])) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.hidden.stub') ->andReturn($this->stub('model.hidden.stub')); } - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); if (in_array($definition, ['drafts/readme-example.yaml', 'drafts/all-column-types.yaml'])) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.dates.stub') ->andReturn($this->stub('model.dates.stub')); } - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.comment.stub') ->andReturn($this->stub('model.method.comment.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($path)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture(str_replace('models', 'models', $model))); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -200,18 +199,18 @@ public function output_generates_models_l6($definition, $path, $model) */ public function output_works_for_pascal_case_definition() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')) ->twice(); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')) ->twice(); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')) ->twice(); @@ -219,16 +218,16 @@ public function output_works_for_pascal_case_definition() $certificateModel = 'app/Certificate.php'; $certificateTypeModel = 'app/CertificateType.php'; - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($certificateModel)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($certificateModel, $this->fixture('models/certificate-pascal-case-example-laravel8.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($certificateTypeModel)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($certificateTypeModel, $this->fixture('models/certificate-type-pascal-case-example-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/pascal-case.yaml')); @@ -243,23 +242,23 @@ public function output_works_for_pascal_case_definition() */ public function output_generates_relationships() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Subscription.php', $this->fixture('models/model-relationships-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/model-relationships.yaml')); @@ -274,38 +273,38 @@ public function output_generates_relationships() */ public function output_generates_polymorphic_relationships() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->times(3) ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->times(3) ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->times(3) ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Post.php', $this->fixture('models/post-polymorphic-relationship-laravel8.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/User.php', $this->fixture('models/user-polymorphic-relationship-laravel8.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Image.php', $this->fixture('models/image-polymorphic-relationship-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/polymorphic-relationships.yaml')); @@ -320,26 +319,26 @@ public function output_generates_polymorphic_relationships() */ public function output_generates_disabled_auto_columns() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.timestamps.stub') ->andReturn($this->stub('model.timestamps.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/State.php', $this->fixture('models/disable-auto-columns-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/disable-auto-columns.yaml')); @@ -358,28 +357,28 @@ public function output_respects_configuration() $this->app['config']->set('blueprint.namespace', 'Some\\App'); $this->app['config']->set('blueprint.models_namespace', 'Models'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Models') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Models', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Models/Comment.php', $this->fixture('models/model-configured-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/relationships.yaml')); @@ -397,37 +396,37 @@ public function output_generates_phpdoc_for_model($definition, $path, $model) { $this->app['config']->set('blueprint.generate_phpdocs', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); if ($definition === 'drafts/disable-auto-columns.yaml') { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.timestamps.stub') ->andReturn($this->stub('model.timestamps.stub')); } - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.comment.stub') ->andReturn($this->stub('model.method.comment.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($path)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($model)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -445,43 +444,43 @@ public function output_generates_phpdoc_for_model_l7($definition, $path, $model) { $this->app['config']->set('blueprint.generate_phpdocs', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); if ($definition === 'drafts/disable-auto-columns.yaml') { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.timestamps.stub') ->andReturn($this->stub('model.timestamps.stub')); } - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); if ($definition === 'drafts/readme-example.yaml') { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.dates.stub') ->andReturn($this->stub('model.dates.stub')); } - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.comment.stub') ->andReturn($this->stub('model.method.comment.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($path)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture(str_replace('models', 'models', $model))); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -499,43 +498,43 @@ public function output_generates_phpdoc_for_model_l6($definition, $path, $model) { $this->app['config']->set('blueprint.generate_phpdocs', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); if ($definition === 'drafts/disable-auto-columns.yaml') { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.timestamps.stub') ->andReturn($this->stub('model.timestamps.stub')); } - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); if ($definition === 'drafts/readme-example.yaml') { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.dates.stub') ->andReturn($this->stub('model.dates.stub')); } - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.comment.stub') ->andReturn($this->stub('model.method.comment.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($path)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture(str_replace('models', 'models', $model))); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -552,27 +551,27 @@ public function output_generates_models_with_guarded_property_when_config_option { $this->app['config']->set('blueprint.use_guarded', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.guarded.stub') ->andReturn($this->stub('model.guarded.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->shouldReceive('stub') + $this->filesystem->shouldReceive('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname('app/Comment.php')) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Comment.php', $this->fixture('models/model-guarded-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/model-guarded.yaml')); @@ -589,32 +588,32 @@ public function output_generates_models_with_namespaces_correctly() { $this->app['config']->set('blueprint.models_namespace', 'Models'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->times(4) ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->times(4) ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->times(4) ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->times(4) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Models/QuestionType.php', \Mockery::type('string')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Models/Appointment/AppointmentType.php', \Mockery::type('string')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Models/Screening/Report.php', \Mockery::type('string')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Models/Screening/ScreeningQuestion.php', $this->fixture('models/nested-models-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/nested-models.yaml')); @@ -642,23 +641,23 @@ public function output_generates_models_with_custom_namespace_correctly() $this->app['config']->set('blueprint.models_namespace', 'Models'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Models') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($model)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -673,26 +672,26 @@ public function output_generates_models_with_custom_namespace_correctly() */ public function output_generates_models_with_custom_pivot_columns() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->modelStub) ->andReturn($this->stub($this->modelStub)); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.fillable.stub') ->andReturn($this->stub('model.fillable.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.casts.stub') ->andReturn($this->stub('model.casts.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.method.stub') ->andReturn($this->stub('model.method.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('model.hidden.stub') ->andReturn($this->stub('model.hidden.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app') ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/User.php', $this->fixture('models/custom-pivot-table-name-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/custom-pivot-table-name.yaml')); diff --git a/tests/Feature/Generators/RouteGeneratorTest.php b/tests/Feature/Generators/RouteGeneratorTest.php index 5daf19ac..d8f29b95 100644 --- a/tests/Feature/Generators/RouteGeneratorTest.php +++ b/tests/Feature/Generators/RouteGeneratorTest.php @@ -15,7 +15,7 @@ class RouteGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var RouteGenerator */ private $subject; @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->subject = new RouteGenerator($this->files); $this->blueprint = new Blueprint(); @@ -49,7 +48,7 @@ public function output_generates_nothing_for_empty_tree() public function output_generates_web_routes($definition, $routes) { $path = 'routes/web.php'; - $this->files->expects('append') + $this->filesystem->expects('append') ->with($path, $this->fixture($routes)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -63,7 +62,7 @@ public function output_generates_web_routes($definition, $routes) */ public function output_generates_api_routes() { - $this->files->expects('append') + $this->filesystem->expects('append') ->with('routes/api.php', $this->fixture('routes/api-routes.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/api-routes-example.yaml')); @@ -77,9 +76,9 @@ public function output_generates_api_routes() */ public function output_generates_routes_for_mixed_resources() { - $this->files->expects('append') + $this->filesystem->expects('append') ->with('routes/api.php', $this->fixture('routes/multiple-resource-controllers-api.php')); - $this->files->expects('append') + $this->filesystem->expects('append') ->with('routes/web.php', $this->fixture('routes/multiple-resource-controllers-web.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/multiple-resource-controllers.yaml')); @@ -95,7 +94,7 @@ public function output_generates_routes_using_tuples() { config(['blueprint.generate_fqcn_route' => true]); - $this->files->expects('append') + $this->filesystem->expects('append') ->with('routes/web.php', $this->fixture('routes/routes-tuples.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/routes-tuples.yaml')); diff --git a/tests/Feature/Generators/SeederGeneratorTest.php b/tests/Feature/Generators/SeederGeneratorTest.php index 199ce362..a35b1b15 100644 --- a/tests/Feature/Generators/SeederGeneratorTest.php +++ b/tests/Feature/Generators/SeederGeneratorTest.php @@ -23,13 +23,12 @@ class SeederGeneratorTest extends TestCase private $subject; - private $files; + protected $files; protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->seederStub = version_compare(App::version(), '8.0.0', '>=') ? 'seeder.stub' : 'seeder.no-factory.stub'; $this->subject = new SeederGenerator($this->files); @@ -44,7 +43,7 @@ protected function setUp(): void */ public function output_generates_nothing_for_empty_tree() { - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['seeders' => []]))); } @@ -55,13 +54,13 @@ public function output_generates_nothing_for_empty_tree() */ public function output_generates_seeders() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->seederStub) ->andReturn($this->stub($this->seederStub)); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeders/PostSeeder.php', $this->fixture('seeders/PostSeeder-laravel8.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeders/CommentSeeder.php', $this->fixture('seeders/CommentSeeder-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); @@ -77,13 +76,13 @@ public function output_using_return_types() { $this->app['config']->set('blueprint.use_return_types', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->seederStub) ->andReturn($this->stub($this->seederStub)); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeders/PostSeeder.php', $this->fixture('seeders/PostSeeder-return-type-declarations.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeders/CommentSeeder.php', $this->fixture('seeders/CommentSeeder-return-type-declarations.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); @@ -98,13 +97,13 @@ public function output_using_return_types() */ public function output_generates_seeders_l7() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->seederStub) ->andReturn($this->stub($this->seederStub)); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); @@ -119,13 +118,13 @@ public function output_generates_seeders_l7() */ public function output_generates_seeders_l6() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->seederStub) ->andReturn($this->stub($this->seederStub)); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); @@ -140,13 +139,13 @@ public function output_generates_seeders_l6() */ public function output_generates_seeders_from_traced_models() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->seederStub) ->andReturn($this->stub($this->seederStub)); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeders/PostSeeder.php', $this->fixture('seeders/PostSeeder-laravel8.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeders/CommentSeeder.php', $this->fixture('seeders/CommentSeeder-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); @@ -164,13 +163,13 @@ public function output_generates_seeders_from_traced_models() */ public function output_generates_seeders_from_traced_models_l7() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->seederStub) ->andReturn($this->stub($this->seederStub)); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); @@ -188,13 +187,13 @@ public function output_generates_seeders_from_traced_models_l7() */ public function output_generates_seeders_from_traced_models_l6() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with($this->seederStub) ->andReturn($this->stub($this->seederStub)); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); diff --git a/tests/Feature/Generators/Statements/EventGeneratorTest.php b/tests/Feature/Generators/Statements/EventGeneratorTest.php index 30fdf895..9c0c933e 100644 --- a/tests/Feature/Generators/Statements/EventGeneratorTest.php +++ b/tests/Feature/Generators/Statements/EventGeneratorTest.php @@ -15,7 +15,7 @@ class EventGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var EventGenerator */ private $subject; @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->subject = new EventGenerator($this->files); $this->blueprint = new Blueprint(); @@ -37,11 +36,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('event.stub') ->andReturn($this->stub('event.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['controllers' => []]))); } @@ -51,11 +50,11 @@ public function output_writes_nothing_for_empty_tree() */ public function output_writes_nothing_tree_without_validate_statements() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('event.stub') ->andReturn($this->stub('event.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $tokens = $this->blueprint->parse($this->fixture('drafts/render-statements.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -68,30 +67,30 @@ public function output_writes_nothing_tree_without_validate_statements() */ public function output_writes_events() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('event.stub') ->andReturn($this->stub('event.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('constructor.stub') ->andReturn($this->stub('constructor.stub')); - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->twice() ->with('app/Events') ->andReturns(false, true); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Events/UserCreated.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Events', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Events/UserCreated.php', $this->fixture('events/user-created.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Events/UserDeleted.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Events/UserDeleted.php', $this->fixture('events/user-deleted.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/fire-statements.yaml')); @@ -105,14 +104,14 @@ public function output_writes_events() */ public function it_only_outputs_new_events() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('event.stub') ->andReturn($this->stub('event.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Events/UserCreated.php') ->andReturnTrue(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Events/UserDeleted.php') ->andReturnTrue(); @@ -130,19 +129,19 @@ public function it_respects_configuration() $this->app['config']->set('blueprint.namespace', 'Some\\App'); $this->app['config']->set('blueprint.app_path', 'src/path'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('event.stub') ->andReturn($this->stub('event.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Events') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Events', 0755, true); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Events/NewPost.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Events/NewPost.php', $this->fixture('events/event-configured.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example.yaml')); diff --git a/tests/Feature/Generators/Statements/FormRequestGeneratorTest.php b/tests/Feature/Generators/Statements/FormRequestGeneratorTest.php index 6b063d5a..1bf4ad8b 100644 --- a/tests/Feature/Generators/Statements/FormRequestGeneratorTest.php +++ b/tests/Feature/Generators/Statements/FormRequestGeneratorTest.php @@ -15,7 +15,7 @@ class FormRequestGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var FormRequestGenerator */ private $subject; @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->subject = new FormRequestGenerator($this->files); $this->blueprint = new Blueprint(); @@ -38,11 +37,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('request.stub') ->andReturn($this->stub('request.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['controllers' => []]))); } @@ -52,11 +51,11 @@ public function output_writes_nothing_for_empty_tree() */ public function output_writes_nothing_without_validate_statements() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('request.stub') ->andReturn($this->stub('request.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $tokens = $this->blueprint->parse($this->fixture('drafts/controllers-only.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -69,32 +68,32 @@ public function output_writes_nothing_without_validate_statements() */ public function output_writes_form_requests() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('request.stub') ->andReturn($this->stub('request.stub')); - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->times(3) ->with('app/Http/Requests') ->andReturns(false, true, true); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/PostIndexRequest.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Http/Requests', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Requests/PostIndexRequest.php', $this->fixture('form-requests/post-index.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/PostStoreRequest.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Requests/PostStoreRequest.php', $this->fixture('form-requests/post-store.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/OtherStoreRequest.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Requests/OtherStoreRequest.php', $this->fixture('form-requests/other-store.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/validate-statements.yaml')); @@ -108,30 +107,30 @@ public function output_writes_form_requests() */ public function output_writes_form_requests_with_support_for_model_reference_in_validate_statement() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('request.stub') ->andReturn($this->stub('request.stub')); - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->twice() ->with('app/Http/Requests') ->andReturns(false, false); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->twice() ->with('app/Http/Requests', 0755, true) ->andReturns(true, false); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/CertificateStoreRequest.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Requests/CertificateStoreRequest.php', $this->fixture('form-requests/certificate-store.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/CertificateUpdateRequest.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Requests/CertificateUpdateRequest.php', $this->fixture('form-requests/certificate-update.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/model-reference-validate.yaml')); @@ -145,17 +144,17 @@ public function output_writes_form_requests_with_support_for_model_reference_in_ */ public function it_only_outputs_new_form_requests() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('request.stub') ->andReturn($this->stub('request.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/PostIndexRequest.php') ->andReturnTrue(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/PostStoreRequest.php') ->andReturnTrue(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/OtherStoreRequest.php') ->andReturnTrue(); @@ -170,19 +169,19 @@ public function it_only_outputs_new_form_requests() */ public function output_supports_nested_form_requests() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('request.stub') ->andReturn($this->stub('request.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/Admin') ->andReturnFalse(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/Admin/UserStoreRequest.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Http/Requests/Admin', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Requests/Admin/UserStoreRequest.php', $this->fixture('form-requests/nested-components.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/nested-components.yaml')); @@ -199,19 +198,19 @@ public function it_respects_configuration() $this->app['config']->set('blueprint.namespace', 'Some\\App'); $this->app['config']->set('blueprint.app_path', 'src/path'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('request.stub') ->andReturn($this->stub('request.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Http/Requests') ->andReturns(false); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Http/Requests/PostStoreRequest.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Http/Requests', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Http/Requests/PostStoreRequest.php', $this->fixture('form-requests/form-request-configured.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example.yaml')); @@ -229,19 +228,19 @@ public function output_using_return_types() $this->app['config']->set('blueprint.app_path', 'src/path'); $this->app['config']->set('blueprint.use_return_types', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('request.stub') ->andReturn($this->stub('request.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Http/Requests') ->andReturns(false); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Http/Requests/PostStoreRequest.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Http/Requests', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Http/Requests/PostStoreRequest.php', $this->fixture('form-requests/return-type-declarations.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example.yaml')); @@ -255,19 +254,19 @@ public function output_using_return_types() */ public function output_generates_test_for_controller_tree_using_cached_model() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('request.stub') ->andReturn($this->stub('request.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests') ->andReturnFalse(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Requests/UserStoreRequest.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Http/Requests', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Requests/UserStoreRequest.php', $this->fixture('form-requests/reference-cache.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/reference-cache.yaml')); diff --git a/tests/Feature/Generators/Statements/JobGeneratorTest.php b/tests/Feature/Generators/Statements/JobGeneratorTest.php index 62abe937..2732e800 100644 --- a/tests/Feature/Generators/Statements/JobGeneratorTest.php +++ b/tests/Feature/Generators/Statements/JobGeneratorTest.php @@ -15,7 +15,7 @@ class JobGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var JobGenerator */ private $subject; @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->subject = new JobGenerator($this->files); $this->blueprint = new Blueprint(); @@ -37,11 +36,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('job.stub') ->andReturn($this->stub('job.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['controllers' => []]))); } @@ -51,11 +50,11 @@ public function output_writes_nothing_for_empty_tree() */ public function output_writes_nothing_tree_without_validate_statements() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('job.stub') ->andReturn($this->stub('job.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $tokens = $this->blueprint->parse($this->fixture('drafts/render-statements.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -68,30 +67,30 @@ public function output_writes_nothing_tree_without_validate_statements() */ public function output_writes_jobs() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('job.stub') ->andReturn($this->stub('job.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('constructor.stub') ->andReturn($this->stub('constructor.stub')); - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->twice() ->with('app/Jobs') ->andReturns(false, true); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Jobs/CreateUser.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Jobs', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Jobs/CreateUser.php', $this->fixture('jobs/create-user.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Jobs/DeleteRole.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Jobs/DeleteRole.php', $this->fixture('jobs/delete-user.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/dispatch-statements.yaml')); @@ -105,14 +104,14 @@ public function output_writes_jobs() */ public function it_only_outputs_new_jobs() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('job.stub') ->andReturn($this->stub('job.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Jobs/CreateUser.php') ->andReturnTrue(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Jobs/DeleteRole.php') ->andReturnTrue(); @@ -131,19 +130,19 @@ public function it_respects_configuration() $this->app['config']->set('blueprint.app_path', 'src/path'); $this->app['config']->set('blueprint.use_return_types', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('job.stub') ->andReturn($this->stub('job.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Jobs') ->andReturnFalse(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Jobs/SyncMedia.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Jobs', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Jobs/SyncMedia.php', $this->fixture('jobs/job-configured.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example.yaml')); diff --git a/tests/Feature/Generators/Statements/MailGeneratorTest.php b/tests/Feature/Generators/Statements/MailGeneratorTest.php index bc0fa277..4eadc394 100644 --- a/tests/Feature/Generators/Statements/MailGeneratorTest.php +++ b/tests/Feature/Generators/Statements/MailGeneratorTest.php @@ -15,7 +15,7 @@ class MailGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var MailGenerator */ private $subject; @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->subject = new MailGenerator($this->files); $this->blueprint = new Blueprint(); @@ -37,11 +36,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('mail.stub') ->andReturn($this->stub('mail.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['controllers' => []]))); } @@ -51,11 +50,11 @@ public function output_writes_nothing_for_empty_tree() */ public function output_writes_nothing_tree_without_validate_statements() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('mail.stub') ->andReturn($this->stub('mail.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $tokens = $this->blueprint->parse($this->fixture('drafts/render-statements.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -68,30 +67,30 @@ public function output_writes_nothing_tree_without_validate_statements() */ public function output_writes_mails() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('mail.stub') ->andReturn($this->stub('mail.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('constructor.stub') ->andReturn($this->stub('constructor.stub')); - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->twice() ->with('app/Mail') ->andReturns(false, true); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Mail/ReviewPost.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Mail', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Mail/ReviewPost.php', $this->fixture('mailables/review-post.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Mail/PublishedPost.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Mail/PublishedPost.php', $this->fixture('mailables/published-post.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/send-statements.yaml')); @@ -105,14 +104,14 @@ public function output_writes_mails() */ public function it_only_outputs_new_mails() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('mail.stub') ->andReturn($this->stub('mail.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Mail/ReviewPost.php') ->andReturnTrue(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Mail/PublishedPost.php') ->andReturnTrue(); @@ -130,19 +129,19 @@ public function it_respects_configuration() $this->app['config']->set('blueprint.namespace', 'Some\\App'); $this->app['config']->set('blueprint.app_path', 'src/path'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('mail.stub') ->andReturn($this->stub('mail.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Mail') ->andReturnFalse(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Mail/ReviewPost.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Mail', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Mail/ReviewPost.php', $this->fixture('mailables/mail-configured.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example.yaml')); @@ -160,19 +159,19 @@ public function output_using_return_types() $this->app['config']->set('blueprint.app_path', 'src/path'); $this->app['config']->set('blueprint.use_return_types', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('mail.stub') ->andReturn($this->stub('mail.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Mail') ->andReturnFalse(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Mail/ReviewPost.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Mail', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Mail/ReviewPost.php', $this->fixture('mailables/return-type-declarations.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example.yaml')); diff --git a/tests/Feature/Generators/Statements/NotificationGeneratorTest.php b/tests/Feature/Generators/Statements/NotificationGeneratorTest.php index 177e55ce..61a3cd78 100644 --- a/tests/Feature/Generators/Statements/NotificationGeneratorTest.php +++ b/tests/Feature/Generators/Statements/NotificationGeneratorTest.php @@ -15,7 +15,7 @@ class NotificationGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var NotificationGenerator */ private $subject; @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->subject = new NotificationGenerator($this->files); $this->blueprint = new Blueprint(); @@ -37,11 +36,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('notification.stub') ->andReturn($this->stub('notification.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['controllers' => []]))); } @@ -51,11 +50,11 @@ public function output_writes_nothing_for_empty_tree() */ public function output_writes_nothing_tree_without_validate_statements() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('notification.stub') ->andReturn($this->stub('notification.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $tokens = $this->blueprint->parse($this->fixture('drafts/render-statements.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -69,32 +68,32 @@ public function output_writes_nothing_tree_without_validate_statements() */ public function output_writes_notifications($draft) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('notification.stub') ->andReturn($this->stub('notification.stub')); if ($draft === 'drafts/send-statements-notification-facade.yaml') { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('constructor.stub') ->andReturn($this->stub('constructor.stub')); } - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->twice() ->with('app/Notification') ->andReturns(false, true); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Notification/ReviewPostNotification.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Notification', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Notification/ReviewPostNotification.php', $this->fixture('notifications/review-post.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Notification/PublishedPostNotification.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Notification/PublishedPostNotification.php', $this->fixture('notifications/published-post.php')); $tokens = $this->blueprint->parse($this->fixture($draft)); @@ -108,14 +107,14 @@ public function output_writes_notifications($draft) */ public function it_only_outputs_new_notifications() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('notification.stub') ->andReturn($this->stub('notification.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Notification/ReviewPostNotification.php') ->andReturnTrue(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Notification/PublishedPostNotification.php') ->andReturnTrue(); @@ -133,19 +132,19 @@ public function it_respects_configuration() $this->app['config']->set('blueprint.namespace', 'Some\\App'); $this->app['config']->set('blueprint.app_path', 'src/path'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('notification.stub') ->andReturn($this->stub('notification.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Notification') ->andReturnFalse(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Notification/ReviewNotification.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Notification', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Notification/ReviewNotification.php', $this->fixture('notifications/notification-configured.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example-notification-facade.yaml')); @@ -163,19 +162,19 @@ public function output_using_return_types() $this->app['config']->set('blueprint.app_path', 'src/path'); $this->app['config']->set('blueprint.use_return_types', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('notification.stub') ->andReturn($this->stub('notification.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Notification') ->andReturnFalse(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('src/path/Notification/ReviewNotification.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('src/path/Notification', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('src/path/Notification/ReviewNotification.php', $this->fixture('notifications/return-type-declarations.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/readme-example-notification-facade.yaml')); diff --git a/tests/Feature/Generators/Statements/ResourceGeneratorTest.php b/tests/Feature/Generators/Statements/ResourceGeneratorTest.php index 4651028b..6bd21663 100644 --- a/tests/Feature/Generators/Statements/ResourceGeneratorTest.php +++ b/tests/Feature/Generators/Statements/ResourceGeneratorTest.php @@ -15,7 +15,7 @@ class ResourceGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var ResourceGenerator */ private $subject; @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->subject = new ResourceGenerator($this->files); $this->blueprint = new Blueprint(); @@ -38,11 +37,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('resource.stub') ->andReturn($this->stub('resource.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['controllers' => []]))); } @@ -52,11 +51,11 @@ public function output_writes_nothing_for_empty_tree() */ public function output_writes_nothing_without_resource_statements() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('resource.stub') ->andReturn($this->stub('resource.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $tokens = $this->blueprint->parse($this->fixture('drafts/controllers-only.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -70,29 +69,29 @@ public function output_writes_nothing_without_resource_statements() public function output_writes_resources_for_render_statements() { $template = $this->stub('resource.stub'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('resource.stub') ->andReturn($template); - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->twice() ->with('app/Http/Resources') ->andReturns(false, true); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Http/Resources', 0755, true); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->twice() ->with('app/Http/Resources/UserResource.php') ->andReturns(false, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Resources/UserResource.php', $this->fixture('resources/user.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->twice() ->with('app/Http/Resources/UserCollection.php') ->andReturns(false, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Resources/UserCollection.php', $this->fixture('resources/user-collection.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/resource-statements.yaml')); @@ -106,27 +105,27 @@ public function output_writes_resources_for_render_statements() */ public function output_writes_namespaced_classes() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('resource.stub') ->andReturn(file_get_contents('stubs/resource.stub')); - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->with('app/Http/Resources/Api') ->andReturns(false, true); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('app/Http/Resources/Api', 0755, true); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->times(3) ->with('app/Http/Resources/Api/CertificateResource.php') ->andReturns(false, true, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Resources/Api/CertificateResource.php', $this->fixture('resources/certificate.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('app/Http/Resources/Api/CertificateCollection.php') ->andReturns(false); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('app/Http/Resources/Api/CertificateCollection.php', $this->fixture('resources/certificate-collection.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/api-routes-example.yaml')); diff --git a/tests/Feature/Generators/Statements/ViewGeneratorTest.php b/tests/Feature/Generators/Statements/ViewGeneratorTest.php index 941b0e4d..fdd04437 100644 --- a/tests/Feature/Generators/Statements/ViewGeneratorTest.php +++ b/tests/Feature/Generators/Statements/ViewGeneratorTest.php @@ -15,7 +15,7 @@ class ViewGeneratorTest extends TestCase { private $blueprint; - private $files; + protected $files; /** @var ViewGenerator */ private $subject; @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); $this->subject = new ViewGenerator($this->files); $this->blueprint = new Blueprint(); @@ -37,11 +36,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('view.stub') ->andReturn($this->stub('view.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['controllers' => []]))); } @@ -51,11 +50,11 @@ public function output_writes_nothing_for_empty_tree() */ public function output_writes_nothing_without_render_statements() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('view.stub') ->andReturn($this->stub('view.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $tokens = $this->blueprint->parse($this->fixture('drafts/controllers-only.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -68,35 +67,35 @@ public function output_writes_nothing_without_render_statements() */ public function output_writes_views_for_render_statements() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('view.stub') ->andReturn($this->stub('view.stub')); - $this->files->shouldReceive('exists') + $this->filesystem->shouldReceive('exists') ->times(2) ->with('resources/views/user') ->andReturnTrue(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('resources/views/user/index.blade.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('resources/views/user/index.blade.php', $this->fixture('views/user.index.blade.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('resources/views/user/create.blade.php') ->andReturnFalse(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('resources/views/user/create.blade.php', $this->fixture('views/user.create.blade.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('resources/views/post') ->andReturns(false, true); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('resources/views/post/show.blade.php') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('resources/views/post', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('resources/views/post/show.blade.php', $this->fixture('views/post.show.blade.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/render-statements.yaml')); @@ -110,17 +109,17 @@ public function output_writes_views_for_render_statements() */ public function it_only_outputs_new_views() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('view.stub') ->andReturn($this->stub('view.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('resources/views/user/index.blade.php') ->andReturnTrue(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('resources/views/user/create.blade.php') ->andReturnTrue(); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('resources/views/post/show.blade.php') ->andReturnTrue(); diff --git a/tests/Feature/Generators/TestGeneratorTest.php b/tests/Feature/Generators/TestGeneratorTest.php index f53e14d6..0d82f985 100644 --- a/tests/Feature/Generators/TestGeneratorTest.php +++ b/tests/Feature/Generators/TestGeneratorTest.php @@ -15,8 +15,6 @@ class TestGeneratorTest extends TestCase { private $blueprint; - private $files; - /** @var TestGenerator */ private $subject; @@ -24,8 +22,7 @@ protected function setUp(): void { parent::setUp(); - $this->files = \Mockery::mock(); - $this->subject = new TestGenerator($this->files); + $this->subject = new TestGenerator($this->filesystem); $this->blueprint = new Blueprint(); $this->blueprint->registerLexer(new \Blueprint\Lexers\ModelLexer()); @@ -38,11 +35,11 @@ protected function setUp(): void */ public function output_writes_nothing_for_empty_tree() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->shouldNotHaveReceived('put'); + $this->filesystem->shouldNotHaveReceived('put'); $this->assertEquals([], $this->subject->output(new Tree(['controllers' => []]))); } @@ -54,20 +51,20 @@ public function output_writes_nothing_for_empty_tree() */ public function output_generates_test_for_controller_tree($definition, $path, $test) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.case.stub') ->andReturn($this->stub('test.case.stub')); $dirname = dirname($path); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with($dirname) ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with($dirname, 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($test)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -83,20 +80,20 @@ public function output_generates_test_for_controller_tree($definition, $path, $t */ public function output_generates_test_for_controller_tree_l8($definition, $path, $test) { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.case.stub') ->andReturn($this->stub('test.case.stub')); $dirname = dirname($path); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with($dirname) ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with($dirname, 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($test)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -111,27 +108,27 @@ public function output_generates_test_for_controller_tree_l8($definition, $path, */ public function output_works_for_pascal_case_definition() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.case.stub') ->andReturn($this->stub('test.case.stub')); $certificateControllerTest = 'tests/Feature/Http/Controllers/CertificateControllerTest.php'; $certificateTypeControllerTest = 'tests/Feature/Http/Controllers/CertificateTypeControllerTest.php'; - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($certificateControllerTest)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($certificateControllerTest, $this->fixture('tests/certificate-pascal-case-example.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($certificateTypeControllerTest)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($certificateTypeControllerTest, $this->fixture('tests/certificate-type-pascal-case-example.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/pascal-case.yaml')); @@ -145,27 +142,27 @@ public function output_works_for_pascal_case_definition() */ public function output_works_for_pascal_case_definition_l8() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.case.stub') ->andReturn($this->stub('test.case.stub')); $certificateControllerTest = 'tests/Feature/Http/Controllers/CertificateControllerTest.php'; $certificateTypeControllerTest = 'tests/Feature/Http/Controllers/CertificateTypeControllerTest.php'; - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($certificateControllerTest)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($certificateControllerTest, $this->fixture('tests/certificate-pascal-case-example-laravel8.php')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with(dirname($certificateTypeControllerTest)) ->andReturnTrue(); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($certificateTypeControllerTest, $this->fixture('tests/certificate-type-pascal-case-example-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/pascal-case.yaml')); @@ -179,19 +176,19 @@ public function output_works_for_pascal_case_definition_l8() */ public function output_generates_test_for_controller_tree_using_cached_model() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.case.stub') ->andReturn($this->stub('test.case.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('tests/Feature/Http/Controllers') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('tests/Feature/Http/Controllers', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('tests/Feature/Http/Controllers/UserControllerTest.php', $this->fixture('tests/reference-cache.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/reference-cache.yaml')); @@ -212,19 +209,19 @@ public function output_generates_test_for_controller_tree_using_cached_model() */ public function output_generates_test_for_controller_tree_using_cached_model_l8() { - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.case.stub') ->andReturn($this->stub('test.case.stub')); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with('tests/Feature/Http/Controllers') ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with('tests/Feature/Http/Controllers', 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with('tests/Feature/Http/Controllers/UserControllerTest.php', $this->fixture('tests/reference-cache-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/reference-cache.yaml')); @@ -251,20 +248,20 @@ public function output_generates_tests_with_models_with_custom_namespace_correct $this->app['config']->set('blueprint.models_namespace', 'Models'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.case.stub') ->andReturn($this->stub('test.case.stub')); $dirname = dirname($path); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with($dirname) ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with($dirname, 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($test)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -285,20 +282,20 @@ public function output_generates_tests_with_models_with_custom_namespace_correct $this->app['config']->set('blueprint.models_namespace', 'Models'); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.case.stub') ->andReturn($this->stub('test.case.stub')); $dirname = dirname($path); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with($dirname) ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with($dirname, 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($test)); $tokens = $this->blueprint->parse($this->fixture($definition)); @@ -319,23 +316,23 @@ public function output_using_return_types() $this->app['config']->set('blueprint.use_return_types', true); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.class.stub') ->andReturn($this->stub('test.class.stub')); - $this->files->expects('stub') + $this->filesystem->expects('stub') ->with('test.case.stub') ->andReturn($this->stub('test.case.stub')); $dirname = dirname($path); - $this->files->expects('exists') + $this->filesystem->expects('exists') ->with($dirname) ->andReturnFalse(); - $this->files->expects('makeDirectory') + $this->filesystem->expects('makeDirectory') ->with($dirname, 0755, true); - $this->files->expects('put') + $this->filesystem->expects('put') ->with($path, $this->fixture($test)); $tokens = $this->blueprint->parse($this->fixture($definition)); diff --git a/tests/TestCase.php b/tests/TestCase.php index 8a62d811..43f72761 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,9 +3,25 @@ namespace Tests; use Blueprint\BlueprintServiceProvider; +use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\File; class TestCase extends \Orchestra\Testbench\TestCase { + /** @var Filesystem */ + protected $filesystem; + + /** @var Filesystem */ + protected $files; + + protected function setUp(): void + { + parent::setUp(); + + $this->files = $this->filesystem = File::spy(); + } + protected function getEnvironmentSetUp($app) { $app['config']->set('blueprint.namespace', 'App'); @@ -41,7 +57,7 @@ protected function useLaravel6($app) ->withNoArgs() ->andReturn('6.0.0'); - \App::swap($appMock); + App::swap($appMock); } protected function useLaravel7($app) @@ -51,7 +67,7 @@ protected function useLaravel7($app) ->withNoArgs() ->andReturn('7.0.0'); - \App::swap($appMock); + App::swap($appMock); } protected function useLaravel8($app) @@ -61,6 +77,6 @@ protected function useLaravel8($app) ->withNoArgs() ->andReturn('8.0.0'); - \App::swap($appMock); + App::swap($appMock); } } diff --git a/tests/Traits/MocksFilesystem.php b/tests/Traits/MocksFilesystem.php deleted file mode 100644 index 7193bfdf..00000000 --- a/tests/Traits/MocksFilesystem.php +++ /dev/null @@ -1,14 +0,0 @@ -files = $this->mock(\Illuminate\Filesystem\Filesystem::class); - $this->swap('files', $this->files); - } -} diff --git a/tests/Unit/BuilderTest.php b/tests/Unit/BuilderTest.php index 8f027e7e..0385a09f 100644 --- a/tests/Unit/BuilderTest.php +++ b/tests/Unit/BuilderTest.php @@ -36,17 +36,16 @@ public function execute_builds_draft_content() ->with($generated) ->andReturn('cacheable blueprint content'); - $file = \Mockery::mock(Filesystem::class); - $file->expects('get') + $this->filesystem->expects('get') ->with('draft.yaml') ->andReturn($draft); - $file->expects('exists') + $this->filesystem->expects('exists') ->with('.blueprint') ->andReturnFalse(); - $file->expects('put') + $this->filesystem->expects('put') ->with('.blueprint', 'cacheable blueprint content'); - $actual = (new Builder())->execute($blueprint, $file, 'draft.yaml'); + $actual = (new Builder())->execute($blueprint, $this->filesystem, 'draft.yaml'); $this->assertSame($generated, $actual); } @@ -91,20 +90,19 @@ public function execute_uses_cache_and_remembers_models() ]) ->andReturn('cacheable blueprint content'); - $file = \Mockery::mock(Filesystem::class); - $file->expects('get') + $this->filesystem->expects('get') ->with('draft.yaml') ->andReturn($draft); - $file->expects('exists') + $this->filesystem->expects('exists') ->with('.blueprint') ->andReturnTrue(); - $file->expects('get') + $this->filesystem->expects('get') ->with('.blueprint') ->andReturn('cached blueprint content'); - $file->expects('put') + $this->filesystem->expects('put') ->with('.blueprint', 'cacheable blueprint content'); - $actual = (new Builder())->execute($blueprint, $file, 'draft.yaml'); + $actual = (new Builder())->execute($blueprint, $this->filesystem, 'draft.yaml'); $this->assertSame($generated, $actual); } @@ -146,17 +144,16 @@ public function execute_calls_builder_without_stripping_dashes_for_draft_file_wi ]) ->andReturn('cacheable blueprint content'); - $file = \Mockery::mock(Filesystem::class); - $file->expects('get') + $this->filesystem->expects('get') ->with('draft.yaml') ->andReturn($draft); - $file->expects('exists') + $this->filesystem->expects('exists') ->with('.blueprint') ->andReturnFalse(); - $file->expects('put') + $this->filesystem->expects('put') ->with('.blueprint', 'cacheable blueprint content'); - $actual = (new Builder())->execute($blueprint, $file, 'draft.yaml'); + $actual = (new Builder())->execute($blueprint, $this->filesystem, 'draft.yaml'); $this->assertSame($generated, $actual); } diff --git a/tests/Unit/EnumTypeTest.php b/tests/Unit/EnumTypeTest.php index ae2a310e..3026cbf8 100644 --- a/tests/Unit/EnumTypeTest.php +++ b/tests/Unit/EnumTypeTest.php @@ -4,7 +4,6 @@ use Blueprint\Blueprint; use Blueprint\Builder; -use Illuminate\Filesystem\Filesystem; use Tests\TestCase; /**