From 445d3e5dc2d6fe395ea22b5470279ec89a4f3699 Mon Sep 17 00:00:00 2001 From: Guillermo Cava Date: Thu, 9 Nov 2023 16:59:32 -0500 Subject: [PATCH 1/3] add duster --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index db94fc35..b35be7c7 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,8 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.17", "mockery/mockery": "^1.4", - "phpunit/phpunit": "^9.3.3" + "phpunit/phpunit": "^9.3.3", + "tightenco/duster": "^2.5" }, "autoload": { "psr-4": { From 465899d82146ddc98236d8b2935abd23ae191ac5 Mon Sep 17 00:00:00 2001 From: Guillermo Cava Date: Thu, 9 Nov 2023 19:42:05 -0500 Subject: [PATCH 2/3] swap customer php-cs-fixer to duster --- .github/workflows/duster-lint.yml | 17 +++++++++++ .github/workflows/format.yml | 34 --------------------- .php-cs-fixer.php | 50 ------------------------------- composer.json | 11 +++++-- duster.json | 3 ++ 5 files changed, 28 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/duster-lint.yml delete mode 100644 .github/workflows/format.yml delete mode 100644 .php-cs-fixer.php create mode 100644 duster.json diff --git a/.github/workflows/duster-lint.yml b/.github/workflows/duster-lint.yml new file mode 100644 index 00000000..305e4928 --- /dev/null +++ b/.github/workflows/duster-lint.yml @@ -0,0 +1,17 @@ +name: Duster Lint + +on: + push: + branches: [ main ] + pull_request: + +jobs: + duster: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: "Duster Lint" + uses: tighten/duster-action@v2 + with: + args: lint diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 85e56884..00000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Format -on: - pull_request: - paths: ['**.php'] -jobs: - php-cs-fixer: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - ref: ${{ github.event.pull_request.head.ref }} - - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - - uses: ramsey/composer-install@v2 - - name: Run PHP-CS-Fixer - id: format - # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings - run: | - delimiter=$RANDOM - echo "summary<<${delimiter}" >> $GITHUB_OUTPUT - composer format >> $GITHUB_OUTPUT - echo $delimiter >> $GITHUB_OUTPUT - - name: Check for fixed files - run: echo "changed=$(git diff --quiet && echo false || echo true)" >> $GITHUB_ENV - - name: Commit changes - if: ${{ env.changed == 'true' }} - run: | - git config --global user.name github-actions - git config --global user.email github-actions[bot]@users.noreply.github.com - # awk trims leading and trailing whitespace from each line, sed removes the last two lines - git commit -a -m "Format" -m "$(echo '${{ steps.format.outputs.summary }})' | awk '{$1=$1};1' | sed '$d' | sed '$d')" - git push diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php deleted file mode 100644 index 00a6f028..00000000 --- a/.php-cs-fixer.php +++ /dev/null @@ -1,50 +0,0 @@ -setFinder(PhpCsFixer\Finder::create()->in(__DIR__)->exclude('tests/snapshots')) - ->setRiskyAllowed(true) - ->setRules([ - '@PSR2' => true, - '@Symfony' => true, - 'align_multiline_comment' => [ - 'comment_type' => 'all_multiline', - ], - 'binary_operator_spaces' => [ - 'operators' => [ - '|' => 'single_space', // Doesn't apply to union types - ], - ], - 'blank_line_after_namespace' => true, - 'blank_line_after_opening_tag' => true, - 'blank_line_before_statement' => [ - 'statements' => ['return', 'throw'], - ], - 'concat_space' => [ - 'spacing' => 'one', - ], - 'get_class_to_class_keyword' => true, - 'global_namespace_import' => [ - 'import_classes' => true, - ], - 'new_with_braces' => false, - 'no_empty_comment' => false, - 'no_useless_else' => true, - 'not_operator_with_successor_space' => true, - 'php_unit_method_casing' => false, - 'phpdoc_annotation_without_dot' => false, - 'phpdoc_to_comment' => [ - 'ignored_tags' => ['var'], - ], - 'phpdoc_separation' => [ - 'groups' => [ - ['test', 'group', 'dataProvider', 'doesNotPerformAssertions'], - ], - ], - 'phpdoc_var_annotation_correct_order' => true, - 'single_line_empty_body' => true, - 'trailing_comma_in_multiline' => [ - 'after_heredoc' => true, - 'elements' => ['arrays', 'arguments', 'parameters'], - ], - 'yoda_style' => false, - ]); diff --git a/composer.json b/composer.json index b35be7c7..0451f07d 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,13 @@ { "name": "tightenco/jigsaw", "description": "Simple static sites with Laravel's Blade.", - "keywords": ["blade", "laravel", "static", "site", "generator"], + "keywords": [ + "blade", + "laravel", + "static", + "site", + "generator" + ], "license": "MIT", "authors": [ { @@ -39,7 +45,6 @@ "vlucas/phpdotenv": "^5.3.1" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.17", "mockery/mockery": "^1.4", "phpunit/phpunit": "^9.3.3", "tightenco/duster": "^2.5" @@ -61,7 +66,7 @@ "jigsaw" ], "scripts": { - "format" : "php-cs-fixer fix --verbose" + "format": "./vendor/bin/duster fix" }, "config": { "sort-packages": true, diff --git a/duster.json b/duster.json new file mode 100644 index 00000000..9fe054eb --- /dev/null +++ b/duster.json @@ -0,0 +1,3 @@ +{ + "exclude": ["tests/snapshots", "src/**/helpers.php"] +} From b4c05aaeaa575a8fd39451599727d73c3e1b79ed Mon Sep 17 00:00:00 2001 From: Guillermo Cava Date: Thu, 9 Nov 2023 19:42:23 -0500 Subject: [PATCH 3/3] run linter --- src/Bootstrap/HandleExceptions.php | 10 +- src/Collection/Collection.php | 2 +- src/Collection/CollectionItem.php | 8 +- .../BladeCollectionItemHandler.php | 2 +- src/Console/BuildCommand.php | 2 +- src/Console/ConsoleOutput.php | 62 ++-- src/Container.php | 4 +- src/Events/EventBus.php | 16 +- src/Exceptions/Handler.php | 4 +- src/File/TemporaryFilesystem.php | 2 +- src/Handlers/CollectionItemHandler.php | 34 +- src/IterableObject.php | 20 +- src/Jigsaw.php | 103 +++--- src/Loaders/CollectionRemoteItemLoader.php | 18 +- src/PageVariable.php | 34 +- src/Parsers/FrontMatterParser.php | 6 +- src/Parsers/MarkdownParser.php | 10 +- src/PathResolvers/CollectionPathResolver.php | 294 +++++++++--------- src/Scaffold/CustomInstaller.php | 1 + src/Scaffold/DefaultInstaller.php | 4 + src/Scaffold/InstallerCommandException.php | 4 +- src/Scaffold/PresetPackage.php | 3 +- src/Scaffold/PresetScaffoldBuilder.php | 1 + src/Scaffold/ScaffoldBuilder.php | 1 + src/SiteData.php | 2 +- src/Support/ServiceProvider.php | 3 +- src/Support/helpers.php | 2 +- src/View/BladeCompiler.php | 3 +- tests/BladeComponentTest.php | 15 +- tests/CollectionItemTest.php | 7 +- tests/CommonMarkTest.php | 7 +- tests/CustomCommandTest.php | 3 +- tests/CustomScaffoldInstallerTest.php | 76 ++--- tests/DefaultScaffoldInstallerTest.php | 77 ++--- tests/DotInFileNameTest.php | 8 +- tests/EventsTest.php | 4 +- tests/FilePathTest.php | 112 +++++-- tests/FilesystemTest.php | 6 +- tests/InitCommandTest.php | 20 +- tests/IterableObjectTest.php | 6 +- tests/JigsawMacroTest.php | 1 + tests/PageDataBindingTest.php | 1 + tests/PhpOpenTagInMarkdownTest.php | 2 +- tests/PresetScaffoldBuilderTest.php | 6 +- tests/SnapshotsTest.php | 2 + tests/TestCase.php | 90 +++--- tests/ViewPathTest.php | 6 +- tests/rebuild.php | 3 +- 48 files changed, 603 insertions(+), 504 deletions(-) diff --git a/src/Bootstrap/HandleExceptions.php b/src/Bootstrap/HandleExceptions.php index c266710a..77c179d8 100644 --- a/src/Bootstrap/HandleExceptions.php +++ b/src/Bootstrap/HandleExceptions.php @@ -43,11 +43,11 @@ public function bootstrap(Container $app): void /** * Report PHP deprecations, or convert PHP errors to ErrorException instances. * - * @param int $level - * @param string $message - * @param string $file - * @param int $line - * @param array $context + * @param int $level + * @param string $message + * @param string $file + * @param int $line + * @param array $context * * @throws ErrorException */ diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index 1668ef8a..3f844aad 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -14,7 +14,7 @@ class Collection extends BaseCollection public static function withSettings(IterableObject $settings, $name) { - $collection = new static(); + $collection = new static; $collection->settings = $settings; $collection->name = $name; diff --git a/src/Collection/CollectionItem.php b/src/Collection/CollectionItem.php index 15924e7a..a84efdba 100644 --- a/src/Collection/CollectionItem.php +++ b/src/Collection/CollectionItem.php @@ -58,13 +58,13 @@ public function getContent() $this->_content; } - public function __toString() + protected function missingHelperError($functionName) { - return (string) $this->getContent(); + return 'No function named "' . $functionName . '" for the collection "' . $this->_meta->collectionName . '" was found in the file "config.php".'; } - protected function missingHelperError($functionName) + public function __toString() { - return 'No function named "' . $functionName . '" for the collection "' . $this->_meta->collectionName . '" was found in the file "config.php".'; + return (string) $this->getContent(); } } diff --git a/src/CollectionItemHandlers/BladeCollectionItemHandler.php b/src/CollectionItemHandlers/BladeCollectionItemHandler.php index 27a51604..7d271247 100644 --- a/src/CollectionItemHandlers/BladeCollectionItemHandler.php +++ b/src/CollectionItemHandlers/BladeCollectionItemHandler.php @@ -34,6 +34,6 @@ public function getItemVariables($file) public function getItemContent($file) { - return; + } } diff --git a/src/Console/BuildCommand.php b/src/Console/BuildCommand.php index b55bcd32..8f19018e 100644 --- a/src/Console/BuildCommand.php +++ b/src/Console/BuildCommand.php @@ -44,7 +44,7 @@ protected function fire() $cacheExists = $this->app[TemporaryFilesystem::class]->hasTempDirectory(); if ($this->input->getOption('pretty') === 'true' && $this->app->config->get('pretty') !== false) { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); } if ($this->input->getOption('quiet')) { diff --git a/src/Console/ConsoleOutput.php b/src/Console/ConsoleOutput.php index 66053b37..7a14d31b 100644 --- a/src/Console/ConsoleOutput.php +++ b/src/Console/ConsoleOutput.php @@ -16,37 +16,6 @@ public function setup($verbosity) $this->setupProgressBars(); } - protected function setupSections() - { - $this->sections = collect([ - 'footer' => $this->section(), - 'intro' => $this->section(), - 'message' => $this->section(), - 'progress' => $this->section(), - 'header' => $this->section(), - ])->map(function ($section) { - return $this->section(); - }); - - $this->sections['header']->writeln(''); - $this->sections['footer']->writeln(''); - } - - protected function setupProgressBars() - { - $this->progressBars = [ - 'collections' => $this->getProgressBar('Loading collections...'), - 'build' => $this->getProgressBar('Building files from source...'), - ]; - } - - protected function getProgressBar($message = null) - { - return $this->isVerbose() ? - new ProgressBar($this, $message, $this->sections['progress']) : - new NullProgressBar($this, $message, $this->sections['progress']); - } - public function progressBar($name) { return $this->progressBars[$name]; @@ -123,4 +92,35 @@ public function writeConclusion() return $this; } + + protected function setupSections() + { + $this->sections = collect([ + 'footer' => $this->section(), + 'intro' => $this->section(), + 'message' => $this->section(), + 'progress' => $this->section(), + 'header' => $this->section(), + ])->map(function ($section) { + return $this->section(); + }); + + $this->sections['header']->writeln(''); + $this->sections['footer']->writeln(''); + } + + protected function setupProgressBars() + { + $this->progressBars = [ + 'collections' => $this->getProgressBar('Loading collections...'), + 'build' => $this->getProgressBar('Building files from source...'), + ]; + } + + protected function getProgressBar($message = null) + { + return $this->isVerbose() ? + new ProgressBar($this, $message, $this->sections['progress']) : + new NullProgressBar($this, $message, $this->sections['progress']); + } } diff --git a/src/Container.php b/src/Container.php index 77b46d87..f157edd6 100644 --- a/src/Container.php +++ b/src/Container.php @@ -139,7 +139,7 @@ private function boot(): void $this->fireAppCallbacks($this->bootedCallbacks); } - /** @param callable[] $callbacks */ + /** @param callable[] $callbacks */ private function fireAppCallbacks(array &$callbacks): void { $index = 0; @@ -147,7 +147,7 @@ private function fireAppCallbacks(array &$callbacks): void while ($index < count($callbacks)) { $callbacks[$index]($this); - ++$index; + $index++; } } diff --git a/src/Events/EventBus.php b/src/Events/EventBus.php index dac7f627..34a633db 100644 --- a/src/Events/EventBus.php +++ b/src/Events/EventBus.php @@ -28,21 +28,21 @@ public function __construct() $this->afterBuild = collect(); } - public function __call($event, $arguments) - { - if (isset($this->{$event})) { - $this->{$event} = $this->{$event}->merge(Arr::wrap($arguments[0])); - } - } - public function fire($event, Jigsaw $jigsaw) { $this->{$event}->each(function ($task) use ($jigsaw) { if (is_callable($task)) { $task($jigsaw); } else { - (new $task())->handle($jigsaw); + (new $task)->handle($jigsaw); } }); } + + public function __call($event, $arguments) + { + if (isset($this->{$event})) { + $this->{$event} = $this->{$event}->merge(Arr::wrap($arguments[0])); + } + } } diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 94ebb5a0..957748a5 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -40,7 +40,7 @@ public function render($request, Throwable $e): void } /** - * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param \Symfony\Component\Console\Output\OutputInterface $output */ public function renderForConsole($output, Throwable $e): void { @@ -88,7 +88,7 @@ public function renderForConsole($output, Throwable $e): void $handler->handle(); } - public function map(Closure|string $from, Closure|string|null $to = null): static + public function map(Closure|string $from, Closure|string $to = null): static { if (is_string($to)) { $to = fn ($exception) => new $to('', 0, $exception); diff --git a/src/File/TemporaryFilesystem.php b/src/File/TemporaryFilesystem.php index 293129e5..9a1f33e6 100644 --- a/src/File/TemporaryFilesystem.php +++ b/src/File/TemporaryFilesystem.php @@ -13,7 +13,7 @@ class TemporaryFilesystem public function __construct($tempPath, $filesystem = null) { $this->tempPath = $tempPath; - $this->filesystem = $filesystem ?: new Filesystem(); + $this->filesystem = $filesystem ?: new Filesystem; } public function buildTempPath($filename, $extension) diff --git a/src/Handlers/CollectionItemHandler.php b/src/Handlers/CollectionItemHandler.php index 5dc38b93..78625ce8 100644 --- a/src/Handlers/CollectionItemHandler.php +++ b/src/Handlers/CollectionItemHandler.php @@ -24,23 +24,6 @@ public function shouldHandle($file) && ! Str::startsWith($file->getFilename(), ['.', '_']); } - private function isInCollectionDirectory($file) - { - $base = $file->topLevelDirectory(); - - return Str::startsWith($base, '_') && $this->hasCollectionNamed($this->getCollectionName($file)); - } - - private function hasCollectionNamed($candidate) - { - return Arr::get($this->config, 'collections.' . $candidate) !== null; - } - - private function getCollectionName($file) - { - return substr($file->topLevelDirectory(), 1); - } - public function handle($file, $pageData) { $handler = $this->handlers->first(function ($handler) use ($file) { @@ -70,4 +53,21 @@ public function handle($file, $pageData) ) : null; })->filter()->values(); } + + private function isInCollectionDirectory($file) + { + $base = $file->topLevelDirectory(); + + return Str::startsWith($base, '_') && $this->hasCollectionNamed($this->getCollectionName($file)); + } + + private function hasCollectionNamed($candidate) + { + return Arr::get($this->config, 'collections.' . $candidate) !== null; + } + + private function getCollectionName($file) + { + return substr($file->topLevelDirectory(), 1); + } } diff --git a/src/IterableObject.php b/src/IterableObject.php index 36f5d546..fb9ca28e 100644 --- a/src/IterableObject.php +++ b/src/IterableObject.php @@ -10,15 +10,6 @@ class IterableObject extends BaseCollection implements ArrayAccess { - public function __get($key) - { - if (! array_key_exists($key, $this->items) && in_array($key, static::$proxies)) { - return new HigherOrderCollectionProxy($this, $key); - } - - return $this->get($key); - } - public function except($keys) { return is_null($keys) ? $this : parent::except($keys); @@ -65,7 +56,7 @@ public function offsetGet($key): mixed if (! isset($this->items[$key])) { $prefix = $this->_source ? 'Error in ' . $this->_source . ': ' : 'Error: '; - throw new Exception($prefix . "The key '$key' does not exist."); + throw new Exception($prefix . "The key '{$key}' does not exist."); } return $this->getElement($key); @@ -91,4 +82,13 @@ protected function isArrayable($element) { return is_array($element) || $element instanceof BaseCollection; } + + public function __get($key) + { + if (! array_key_exists($key, $this->items) && in_array($key, static::$proxies)) { + return new HigherOrderCollectionProxy($this, $key); + } + + return $this->get($key); + } } diff --git a/src/Jigsaw.php b/src/Jigsaw.php index 9b38c7c8..bdfb1c89 100644 --- a/src/Jigsaw.php +++ b/src/Jigsaw.php @@ -12,16 +12,25 @@ class Jigsaw { use Macroable; + protected static $commands = []; + public $app; + protected $env; + protected $pageInfo; + protected $outputPaths; + protected $siteData; + protected $dataLoader; + protected $remoteItemLoader; + protected $siteBuilder; + protected $verbose; - protected static $commands = []; public function __construct( Container $app, @@ -35,19 +44,6 @@ public function __construct( $this->siteBuilder = $siteBuilder; } - public function build($env, $useCache = false) - { - $this->env = $env; - $this->siteData = $this->dataLoader->loadSiteData($this->app->config); - - return $this->fireEvent('beforeBuild') - ->buildCollections() - ->fireEvent('afterCollections') - ->buildSite($useCache) - ->fireEvent('afterBuild') - ->cleanup(); - } - public static function registerCommand($command) { self::$commands[] = $command; @@ -60,41 +56,17 @@ public static function addUserCommands($app, $container) } } - protected function buildCollections() - { - $this->remoteItemLoader->write($this->siteData->collections, $this->getSourcePath()); - $collectionData = $this->dataLoader->loadCollectionData($this->siteData, $this->getSourcePath()); - $this->siteData = $this->siteData->addCollectionData($collectionData); - - return $this; - } - - protected function buildSite($useCache) - { - $this->pageInfo = $this->siteBuilder - ->setUseCache($useCache) - ->build( - $this->getSourcePath(), - $this->getDestinationPath(), - $this->siteData, - ); - $this->outputPaths = $this->pageInfo->keys(); - - return $this; - } - - protected function cleanup() - { - $this->remoteItemLoader->cleanup(); - - return $this; - } - - protected function fireEvent($event) + public function build($env, $useCache = false) { - $this->app->events->fire($event, $this); + $this->env = $env; + $this->siteData = $this->dataLoader->loadSiteData($this->app->config); - return $this; + return $this->fireEvent('beforeBuild') + ->buildCollections() + ->fireEvent('afterCollections') + ->buildSite($useCache) + ->fireEvent('afterBuild') + ->cleanup(); } public function getSiteData() @@ -196,4 +168,41 @@ public function writeOutputFile($fileName, $contents) { return $this->getFilesystem()->putWithDirectories($this->getDestinationPath() . '/' . $fileName, $contents); } + + protected function buildCollections() + { + $this->remoteItemLoader->write($this->siteData->collections, $this->getSourcePath()); + $collectionData = $this->dataLoader->loadCollectionData($this->siteData, $this->getSourcePath()); + $this->siteData = $this->siteData->addCollectionData($collectionData); + + return $this; + } + + protected function buildSite($useCache) + { + $this->pageInfo = $this->siteBuilder + ->setUseCache($useCache) + ->build( + $this->getSourcePath(), + $this->getDestinationPath(), + $this->siteData, + ); + $this->outputPaths = $this->pageInfo->keys(); + + return $this; + } + + protected function cleanup() + { + $this->remoteItemLoader->cleanup(); + + return $this; + } + + protected function fireEvent($event) + { + $this->app->events->fire($event, $this); + + return $this; + } } diff --git a/src/Loaders/CollectionRemoteItemLoader.php b/src/Loaders/CollectionRemoteItemLoader.php index 77b8b0ce..0f3f73b6 100644 --- a/src/Loaders/CollectionRemoteItemLoader.php +++ b/src/Loaders/CollectionRemoteItemLoader.php @@ -29,15 +29,6 @@ public function write($collections, $source) }); } - private function createTempDirectory($source, $collectionName) - { - $tempDirectory = $source . '/_' . $collectionName . '/_tmp'; - $this->prepareDirectory($tempDirectory, true); - $this->tempDirectories[] = $tempDirectory; - - return $tempDirectory; - } - public function cleanup() { collect($this->tempDirectories)->each(function ($path) { @@ -49,6 +40,15 @@ public function cleanup() }); } + private function createTempDirectory($source, $collectionName) + { + $tempDirectory = $source . '/_' . $collectionName . '/_tmp'; + $this->prepareDirectory($tempDirectory, true); + $this->tempDirectories[] = $tempDirectory; + + return $tempDirectory; + } + private function getItems($collection) { if (! $collection->items) { diff --git a/src/PageVariable.php b/src/PageVariable.php index 4f814eb6..3149b83d 100644 --- a/src/PageVariable.php +++ b/src/PageVariable.php @@ -12,23 +12,6 @@ public function addVariables(array $variables) $this->items = collect($this->items)->merge($this->makeIterable($variables))->all(); } - public function __call($method, $args) - { - $helper = $this->get($method); - - if (! $helper && Str::startsWith($method, 'get')) { - return $this->_meta->get(Str::camel(substr($method, 3)), function () use ($method) { - throw new Exception($this->missingHelperError($method)); - }); - } - - if (is_callable($helper)) { - return $helper->__invoke($this, ...$args); - } - - throw new Exception($this->missingHelperError($method)); - } - public function getPath($key = null) { if (($key || $this->_meta->extending) && $this->_meta->path instanceof IterableObject) { @@ -61,4 +44,21 @@ protected function missingHelperError($functionName) { return 'No function named "' . $functionName . '" was found in the file "config.php".'; } + + public function __call($method, $args) + { + $helper = $this->get($method); + + if (! $helper && Str::startsWith($method, 'get')) { + return $this->_meta->get(Str::camel(substr($method, 3)), function () use ($method) { + throw new Exception($this->missingHelperError($method)); + }); + } + + if (is_callable($helper)) { + return $helper->__invoke($this, ...$args); + } + + throw new Exception($this->missingHelperError($method)); + } } diff --git a/src/Parsers/FrontMatterParser.php b/src/Parsers/FrontMatterParser.php index 137cf2e2..5c8eb291 100644 --- a/src/Parsers/FrontMatterParser.php +++ b/src/Parsers/FrontMatterParser.php @@ -7,10 +7,12 @@ class FrontMatterParser { - private $parser; public $frontMatter = []; + public $content; + private $parser; + public function __construct(Parser $parser) { $this->parser = $parser; @@ -78,6 +80,6 @@ public function extractContent($content) private function addExtendsToBladeContent($extends, $bladeContent) { - return "@extends('$extends')\n" . $bladeContent; + return "@extends('{$extends}')\n" . $bladeContent; } } diff --git a/src/Parsers/MarkdownParser.php b/src/Parsers/MarkdownParser.php index 2ed05ea7..e8257ae2 100644 --- a/src/Parsers/MarkdownParser.php +++ b/src/Parsers/MarkdownParser.php @@ -13,6 +13,11 @@ public function __construct(MarkdownParserContract $parser = null) $this->parser = $parser ?? new JigsawMarkdownParser; } + public function parse($markdown) + { + return $this->parser->parse($markdown); + } + public function __get($property) { return $this->parser->$property; @@ -22,9 +27,4 @@ public function __set($property, $value) { $this->parser->$property = $value; } - - public function parse($markdown) - { - return $this->parser->parse($markdown); - } } diff --git a/src/PathResolvers/CollectionPathResolver.php b/src/PathResolvers/CollectionPathResolver.php index 07874fd9..838c8a45 100644 --- a/src/PathResolvers/CollectionPathResolver.php +++ b/src/PathResolvers/CollectionPathResolver.php @@ -16,155 +16,11 @@ public function __construct($outputPathResolver, $viewRenderer) $this->view = $viewRenderer; } - public function link($path, $data, bool $transliterate = true) - { - return collect($data->extends)->map(function ($bladeViewPath, $templateKey) use ($path, $data, $transliterate) { - return $this->cleanOutputPath( - $this->getPath($path, $data, $this->getExtension($bladeViewPath), $templateKey), - $transliterate, - ); - }); - } - - public function getExtension($bladeViewPath) - { - $extension = $this->view->getExtension($bladeViewPath); - - return collect(['php', 'html'])->contains($extension) ? '' : '.' . $extension; - } - - private function getPath($path, $data, $extension, $templateKey = null) - { - $templateKeySuffix = $templateKey ? '/' . $templateKey : ''; - - if ($templateKey && $path instanceof IterableObject) { - $path = $path->get($templateKey); - $templateKeySuffix = ''; - - if (! $path) { - return; - } - } - - if (is_callable($path)) { - $link = $this->cleanInputPath($path->__invoke($data)); - - return $link ? $this->resolve($link . $templateKeySuffix . $extension) : ''; - } - - if (is_string($path) && $path) { - $link = $this->parseShorthand($this->cleanInputPath($path), $data); - - return $link ? $this->resolve($link . $templateKeySuffix . $extension) : ''; - } - - return $this->getDefaultPath($data, $templateKey) . $templateKeySuffix . $extension; - } - - private function getDefaultPath($data) - { - return $this->slug($data->getCollectionName()) . '/' . $this->slug($data->getFilename()); - } - - private function parseShorthand($path, $data) - { - preg_match_all('/\{(.*?)\}/', $path, $bracketedParameters); - - if (count($bracketedParameters[0]) == 0) { - return $path . '/' . $this->slug($data->getFilename()); - } - - $bracketedParametersReplaced = - collect($bracketedParameters[0])->map(function ($param) use ($data) { - return ['token' => $param, 'value' => $this->getParameterValue($param, $data)]; - })->reduce(function ($carry, $param) { - return str_replace($param['token'], $param['value'], $carry); - }, $path); - - return $bracketedParametersReplaced; - } - - private function getParameterValue($param, $data) - { - list($param, $dateFormat) = explode('|', trim($param, '{}') . '|'); - $slugSeparator = ctype_alpha($param[0]) ? null : $param[0]; - - if ($slugSeparator) { - $param = ltrim($param, $param[0]); - } - - $value = Arr::get($data, $param, $data->_meta->get($param)); - - if (! $value) { - return ''; - } - - $value = $dateFormat ? $this->formatDate($value, $dateFormat) : $value; - - return $slugSeparator ? $this->slug($value, $slugSeparator) : $value; - } - - private function formatDate($date, $format) - { - if (is_string($date)) { - return strtotime($date) ? date($format, strtotime($date)) : ''; - } - - return date($format, $date); - } - - private function cleanInputPath($path) - { - return $this->ensureSlashAtBeginningOnly($path); - } - - private function cleanOutputPath($path, bool $transliterate) - { - // Remove double slashes - $path = preg_replace('/\/\/+/', '/', $path); - - if ($transliterate) { - $path = $this->ascii($path); - } - - return $this->ensureSlashAtBeginningOnly($path); - } - - private function ensureSlashAtBeginningOnly($path) - { - return '/' . trimPath($path); - } - - private function resolve($path) - { - return $this->outputPathResolver->link(dirname($path), basename($path), 'html'); - } - - /** - * This is identical to Laravel's built-in `str_slug()` helper, - * except it preserves `.` characters. - */ - private function slug($string, $separator = '-') - { - // Convert all dashes/underscores into separator - $flip = $separator == '-' ? '_' : '-'; - $string = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $string); - - // Remove all characters that are not the separator, letters, numbers, whitespace, or dot - $string = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s\.]+!u', '', mb_strtolower($string)); - - // Replace all separator characters and whitespace by a single separator - $string = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $string); - - return trim($string, $separator); - } - /** * Transliterate a UTF-8 value to ASCII. * - * @param string $value - * @param string $language - * + * @param string $value + * @param string $language * @return string */ private static function ascii($value, $language = 'en') @@ -323,8 +179,7 @@ private static function charsArray() * * @see https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt * - * @param string $language - * + * @param string $language * @return array|null */ private static function languageSpecificCharsArray($language) @@ -346,4 +201,147 @@ private static function languageSpecificCharsArray($language) return $languageSpecific[$language] ?? null; } + + public function link($path, $data, bool $transliterate = true) + { + return collect($data->extends)->map(function ($bladeViewPath, $templateKey) use ($path, $data, $transliterate) { + return $this->cleanOutputPath( + $this->getPath($path, $data, $this->getExtension($bladeViewPath), $templateKey), + $transliterate, + ); + }); + } + + public function getExtension($bladeViewPath) + { + $extension = $this->view->getExtension($bladeViewPath); + + return collect(['php', 'html'])->contains($extension) ? '' : '.' . $extension; + } + + private function getPath($path, $data, $extension, $templateKey = null) + { + $templateKeySuffix = $templateKey ? '/' . $templateKey : ''; + + if ($templateKey && $path instanceof IterableObject) { + $path = $path->get($templateKey); + $templateKeySuffix = ''; + + if (! $path) { + return; + } + } + + if (is_callable($path)) { + $link = $this->cleanInputPath($path->__invoke($data)); + + return $link ? $this->resolve($link . $templateKeySuffix . $extension) : ''; + } + + if (is_string($path) && $path) { + $link = $this->parseShorthand($this->cleanInputPath($path), $data); + + return $link ? $this->resolve($link . $templateKeySuffix . $extension) : ''; + } + + return $this->getDefaultPath($data, $templateKey) . $templateKeySuffix . $extension; + } + + private function getDefaultPath($data) + { + return $this->slug($data->getCollectionName()) . '/' . $this->slug($data->getFilename()); + } + + private function parseShorthand($path, $data) + { + preg_match_all('/\{(.*?)\}/', $path, $bracketedParameters); + + if (count($bracketedParameters[0]) == 0) { + return $path . '/' . $this->slug($data->getFilename()); + } + + $bracketedParametersReplaced = + collect($bracketedParameters[0])->map(function ($param) use ($data) { + return ['token' => $param, 'value' => $this->getParameterValue($param, $data)]; + })->reduce(function ($carry, $param) { + return str_replace($param['token'], $param['value'], $carry); + }, $path); + + return $bracketedParametersReplaced; + } + + private function getParameterValue($param, $data) + { + [$param, $dateFormat] = explode('|', trim($param, '{}') . '|'); + $slugSeparator = ctype_alpha($param[0]) ? null : $param[0]; + + if ($slugSeparator) { + $param = ltrim($param, $param[0]); + } + + $value = Arr::get($data, $param, $data->_meta->get($param)); + + if (! $value) { + return ''; + } + + $value = $dateFormat ? $this->formatDate($value, $dateFormat) : $value; + + return $slugSeparator ? $this->slug($value, $slugSeparator) : $value; + } + + private function formatDate($date, $format) + { + if (is_string($date)) { + return strtotime($date) ? date($format, strtotime($date)) : ''; + } + + return date($format, $date); + } + + private function cleanInputPath($path) + { + return $this->ensureSlashAtBeginningOnly($path); + } + + private function cleanOutputPath($path, bool $transliterate) + { + // Remove double slashes + $path = preg_replace('/\/\/+/', '/', $path); + + if ($transliterate) { + $path = $this->ascii($path); + } + + return $this->ensureSlashAtBeginningOnly($path); + } + + private function ensureSlashAtBeginningOnly($path) + { + return '/' . trimPath($path); + } + + private function resolve($path) + { + return $this->outputPathResolver->link(dirname($path), basename($path), 'html'); + } + + /** + * This is identical to Laravel's built-in `str_slug()` helper, + * except it preserves `.` characters. + */ + private function slug($string, $separator = '-') + { + // Convert all dashes/underscores into separator + $flip = $separator == '-' ? '_' : '-'; + $string = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $string); + + // Remove all characters that are not the separator, letters, numbers, whitespace, or dot + $string = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s\.]+!u', '', mb_strtolower($string)); + + // Replace all separator characters and whitespace by a single separator + $string = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $string); + + return trim($string, $separator); + } } diff --git a/src/Scaffold/CustomInstaller.php b/src/Scaffold/CustomInstaller.php index 7b5f9438..1f1c30be 100644 --- a/src/Scaffold/CustomInstaller.php +++ b/src/Scaffold/CustomInstaller.php @@ -5,6 +5,7 @@ class CustomInstaller { public $ignore = ['init.php']; + protected $from; protected $builder; protected $console; diff --git a/src/Scaffold/DefaultInstaller.php b/src/Scaffold/DefaultInstaller.php index 82054fd5..15ac653e 100644 --- a/src/Scaffold/DefaultInstaller.php +++ b/src/Scaffold/DefaultInstaller.php @@ -17,9 +17,13 @@ class DefaultInstaller 'npm install', 'npm run dev', ]; + protected $commands; + protected $delete; + protected $ignore; + protected $builder; public function install(ScaffoldBuilder $builder, $settings = []) diff --git a/src/Scaffold/InstallerCommandException.php b/src/Scaffold/InstallerCommandException.php index 939fb109..11e342e9 100644 --- a/src/Scaffold/InstallerCommandException.php +++ b/src/Scaffold/InstallerCommandException.php @@ -4,4 +4,6 @@ use Exception; -class InstallerCommandException extends Exception {} +class InstallerCommandException extends Exception +{ +} diff --git a/src/Scaffold/PresetPackage.php b/src/Scaffold/PresetPackage.php index 6381df2a..355e7ca8 100644 --- a/src/Scaffold/PresetPackage.php +++ b/src/Scaffold/PresetPackage.php @@ -22,6 +22,7 @@ class PresetPackage public $preset; public $suffix; public $vendor; + protected $builder; protected $customInstaller; protected $defaultInstaller; @@ -33,7 +34,7 @@ public function __construct(DefaultInstaller $default, CustomInstaller $custom, $this->defaultInstaller = $default; $this->customInstaller = $custom; $this->process = $process; - $this->files = new Filesystem(); + $this->files = new Filesystem; } public function init($preset, PresetScaffoldBuilder $builder) diff --git a/src/Scaffold/PresetScaffoldBuilder.php b/src/Scaffold/PresetScaffoldBuilder.php index c4acca31..3254dc5d 100644 --- a/src/Scaffold/PresetScaffoldBuilder.php +++ b/src/Scaffold/PresetScaffoldBuilder.php @@ -8,6 +8,7 @@ class PresetScaffoldBuilder extends ScaffoldBuilder { public $package; + protected $files; protected $process; protected $question; diff --git a/src/Scaffold/ScaffoldBuilder.php b/src/Scaffold/ScaffoldBuilder.php index e8e8312a..8fe9ef3b 100644 --- a/src/Scaffold/ScaffoldBuilder.php +++ b/src/Scaffold/ScaffoldBuilder.php @@ -13,6 +13,7 @@ abstract class ScaffoldBuilder ]; public $base; + protected $console; protected $files; protected $process; diff --git a/src/SiteData.php b/src/SiteData.php index b099948c..b8b8eb8c 100644 --- a/src/SiteData.php +++ b/src/SiteData.php @@ -8,7 +8,7 @@ class SiteData extends IterableObject { public static function build(Collection $config) { - $siteData = new static(); + $siteData = new static; $siteData->putIterable('collections', $config->get('collections')); $siteData->putIterable('page', $config); diff --git a/src/Support/ServiceProvider.php b/src/Support/ServiceProvider.php index 16052f78..8e809b77 100644 --- a/src/Support/ServiceProvider.php +++ b/src/Support/ServiceProvider.php @@ -8,7 +8,8 @@ abstract class ServiceProvider { public function __construct( protected Container $app, - ) {} + ) { + } public function register(): void { diff --git a/src/Support/helpers.php b/src/Support/helpers.php index c655bb66..06ac9164 100644 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -133,7 +133,7 @@ function url(string $path): string function dd(...$args) { foreach ($args as $x) { - (new VarDumper())->dump($x); + (new VarDumper)->dump($x); } exit(1); diff --git a/src/View/BladeCompiler.php b/src/View/BladeCompiler.php index 54a970a1..8bc77470 100644 --- a/src/View/BladeCompiler.php +++ b/src/View/BladeCompiler.php @@ -9,8 +9,7 @@ class BladeCompiler extends BaseBladeCompiler /** * Compile the component tags. * - * @param string $value - * + * @param string $value * @return string */ protected function compileComponentTags($value) diff --git a/tests/BladeComponentTest.php b/tests/BladeComponentTest.php index 619f10c3..fa337c0e 100644 --- a/tests/BladeComponentTest.php +++ b/tests/BladeComponentTest.php @@ -21,18 +21,20 @@ public function can_include_blade_component_with_at_syntax() ]), '_components' => [ 'alert.blade.php' => implode("\n", [ - '
', - '

This is the component

', - '

Named title slot: {{ $title }}

', - '{{ $slot }}', - '
', + '
', + '

This is the component

', + '

Named title slot: {{ $title }}

', + '{{ $slot }}', + '
', ]), ], ]); $this->buildSite($files, []); - $this->assertOutputFile('build/page.html', <<assertOutputFile( + 'build/page.html', + <<<'HTML'

This is the component

Named title slot: Title test

@@ -155,6 +157,7 @@ class_alias('Tests\\AlertComponent', 'Components\\ClassComponent'); } } +// phpcs:disable PSR1.Classes.ClassDeclaration,Squiz.Classes.ClassFileName class AlertComponent extends Component { public $type; diff --git a/tests/CollectionItemTest.php b/tests/CollectionItemTest.php index 696f149f..46e6c1da 100644 --- a/tests/CollectionItemTest.php +++ b/tests/CollectionItemTest.php @@ -38,7 +38,8 @@ public function collection_item_contents_are_returned_when_item_is_referenced_as */ public function collection_item_can_be_filtered() { - $config = collect(['collections' => [ + $config = collect([ + 'collections' => [ 'collection' => [ 'path' => 'collection/{filename}', 'filter' => function ($item) { @@ -85,7 +86,8 @@ public function collection_item_can_be_filtered() */ public function collection_item_can_be_mapped() { - $config = collect(['collections' => [ + $config = collect([ + 'collections' => [ 'collection' => [ 'path' => 'collection/{filename}', 'map' => function ($item) { @@ -266,6 +268,7 @@ public function collection_item_page_metadata_contains_modified_time() } } +// phpcs:disable PSR1.Classes.ClassDeclaration,Squiz.Classes.ClassFileName class MappedItem extends CollectionItem { public function doubleNumber() diff --git a/tests/CommonMarkTest.php b/tests/CommonMarkTest.php index 1b9ce2de..c59f4a70 100644 --- a/tests/CommonMarkTest.php +++ b/tests/CommonMarkTest.php @@ -46,7 +46,7 @@ public function configure_commonmark_parser() /** @test */ public function replace_commonmark_extensions() { - $files = $this->withContent(<<withContent(<<<'MD' # Fruits {.class} Apple @@ -74,10 +74,11 @@ public function override_parser_with_custom_class() $files = $this->withContent('### Heading {.class}'); $this->app->bind(MarkdownParserContract::class, function () { - return new class implements MarkdownParserContract { + return new class implements MarkdownParserContract + { public function parse(string $text) { - return <<createSource([]); $command = $this->app->make(CustomCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $console = new CommandTester($command); $console->execute([]); @@ -24,6 +24,7 @@ public function custom_command_with_no_arguments() } } +// phpcs:disable PSR1.Classes.ClassDeclaration,Squiz.Classes.ClassFileName class CustomCommand extends Command { protected function fire() diff --git a/tests/CustomScaffoldInstallerTest.php b/tests/CustomScaffoldInstallerTest.php index f6a94828..d62bd9a8 100644 --- a/tests/CustomScaffoldInstallerTest.php +++ b/tests/CustomScaffoldInstallerTest.php @@ -18,12 +18,12 @@ class CustomScaffoldInstallerTest extends TestCase public function custom_installer_installs_basic_scaffold_files() { $this->createSource([]); - $builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner); $builder->setBase($this->tmp); $this->assertCount(0, app('files')->filesAndDirectories($this->tmp)); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup(); $this->assertFileExists($this->tmpPath('source')); @@ -38,10 +38,10 @@ public function custom_installer_installs_basic_scaffold_files() public function installer_deletes_single_base_file_specified_in_delete_array() { $this->createSource([]); - $builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->delete('config.php'); @@ -55,10 +55,10 @@ public function installer_deletes_single_base_file_specified_in_delete_array() public function installer_deletes_multiple_base_files_specified_in_delete_array() { $this->createSource([]); - $builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->delete([ 'config.php', @@ -76,10 +76,10 @@ public function installer_deletes_multiple_base_files_specified_in_delete_array( public function installer_deletes_base_directories_specified_in_delete_array() { $this->createSource([]); - $builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->delete([ 'source', @@ -104,10 +104,10 @@ public function installer_copies_all_preset_files_if_copy_has_no_parameter() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->copy(); @@ -132,10 +132,10 @@ public function installer_copies_individual_preset_file_if_copy_parameter_is_str ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->copy('preset-file.php'); @@ -160,10 +160,10 @@ public function installer_copies_multiple_preset_files_if_copy_parameter_is_arra ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->copy([ 'preset-file.php', @@ -189,10 +189,10 @@ public function installer_can_copy_files_using_a_wildcard() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->copy([ 'preset-file-*.php', @@ -219,10 +219,10 @@ public function installer_can_call_copy_multiple_times() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->copy('.dotfile') ->copy('source'); @@ -252,10 +252,10 @@ public function installer_copies_from_specified_directory_to_root_if_from_is_spe ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->from('themes/directory-2') ->copy(); @@ -280,10 +280,10 @@ public function installer_can_ignore_preset_files_when_copying() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->ignore('.dotfile') ->copy(); @@ -309,10 +309,10 @@ public function installer_can_call_ignore_multiple_times() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->ignore('.dotfile') ->ignore('preset-file.php') @@ -342,10 +342,10 @@ public function original_composer_json_is_not_deleted() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->delete('composer.json'); @@ -379,10 +379,10 @@ public function original_composer_json_is_merged_with_new_composer_json_after_co ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->copy(); @@ -428,10 +428,10 @@ public function composer_json_files_are_merged_when_copying_multiple_times() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->copy() ->from('theme') @@ -462,10 +462,10 @@ public function empty_composer_json_is_created_if_it_was_not_present_before_pres ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new CustomInstaller())->install($builder) + (new CustomInstaller)->install($builder) ->setup() ->copy(); @@ -479,6 +479,7 @@ public function empty_composer_json_is_created_if_it_was_not_present_before_pres /** * @test + * * @doesNotPerformAssertions */ public function installer_can_ask_for_user_input() @@ -486,7 +487,7 @@ public function installer_can_ask_for_user_input() $console = Mockery::spy(ConsoleSession::class); $builder = Mockery::spy(PresetScaffoldBuilder::class); - (new CustomInstaller())->setConsole($console) + (new CustomInstaller)->setConsole($console) ->install($builder) ->setup() ->ask('What is your name?'); @@ -497,6 +498,7 @@ public function installer_can_ask_for_user_input() /** * @test + * * @doesNotPerformAssertions */ public function installer_can_ask_for_user_input_with_choices() @@ -504,7 +506,7 @@ public function installer_can_ask_for_user_input_with_choices() $console = Mockery::spy(ConsoleSession::class); $builder = Mockery::spy(PresetScaffoldBuilder::class); - (new CustomInstaller())->setConsole($console) + (new CustomInstaller)->setConsole($console) ->install($builder) ->setup() ->ask( @@ -524,6 +526,7 @@ public function installer_can_ask_for_user_input_with_choices() /** * @test + * * @doesNotPerformAssertions */ public function installer_can_ask_for_user_confirmation() @@ -531,7 +534,7 @@ public function installer_can_ask_for_user_confirmation() $console = Mockery::spy(ConsoleSession::class); $builder = Mockery::spy(PresetScaffoldBuilder::class); - (new CustomInstaller())->setConsole($console) + (new CustomInstaller)->setConsole($console) ->install($builder) ->setup() ->confirm('Continue?'); @@ -542,6 +545,7 @@ public function installer_can_ask_for_user_confirmation() /** * @test + * * @doesNotPerformAssertions */ public function installer_runs_specified_commands_from_init() @@ -549,7 +553,7 @@ public function installer_runs_specified_commands_from_init() $package = Mockery::mock(PresetPackage::class); $builder = Mockery::spy(PresetScaffoldBuilder::class); - (new CustomInstaller())->setConsole(null) + (new CustomInstaller)->setConsole(null) ->install($builder) ->setup() ->run('yarn'); diff --git a/tests/DefaultScaffoldInstallerTest.php b/tests/DefaultScaffoldInstallerTest.php index 17ed5ace..e7628b47 100644 --- a/tests/DefaultScaffoldInstallerTest.php +++ b/tests/DefaultScaffoldInstallerTest.php @@ -18,12 +18,12 @@ class DefaultScaffoldInstallerTest extends TestCase public function installer_installs_basic_scaffold_files() { $this->createSource([]); - $builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner); $builder->setBase($this->tmp); $this->assertCount(0, app('files')->filesAndDirectories($this->tmp)); - (new DefaultInstaller())->install($builder, ['commands' => []]); + (new DefaultInstaller)->install($builder, ['commands' => []]); $this->assertFileExists($this->tmpPath('source')); $this->assertFileExists($this->tmpPath('package.json')); @@ -37,10 +37,10 @@ public function installer_installs_basic_scaffold_files() public function installer_deletes_single_base_file_specified_in_delete_array() { $this->createSource([]); - $builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, [ + (new DefaultInstaller)->install($builder, [ 'delete' => 'config.php', 'commands' => [], ]); @@ -55,10 +55,10 @@ public function installer_deletes_single_base_file_specified_in_delete_array() public function installer_deletes_multiple_base_files_specified_in_delete_array() { $this->createSource([]); - $builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, [ + (new DefaultInstaller)->install($builder, [ 'delete' => ['config.php', 'package.json'], 'commands' => [], ]); @@ -74,10 +74,10 @@ public function installer_deletes_multiple_base_files_specified_in_delete_array( public function installer_deletes_base_directories_specified_in_delete_array() { $this->createSource([]); - $builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, [ + (new DefaultInstaller)->install($builder, [ 'delete' => ['source'], 'commands' => [], ]); @@ -108,10 +108,10 @@ public function installer_copies_all_preset_files() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => []]); + (new DefaultInstaller)->install($builder, ['commands' => []]); $this->assertFileExists($this->tmpPath('.dotfile')); $this->assertFileExists($this->tmpPath('preset-file.php')); @@ -132,10 +132,10 @@ public function installer_preserves_base_files_when_copying_preset_files() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => []]); + (new DefaultInstaller)->install($builder, ['commands' => []]); $this->assertFileExists($this->tmpPath('config.php')); } @@ -152,10 +152,10 @@ public function installer_overwrites_base_files_of_same_name_when_copying_preset ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => []]); + (new DefaultInstaller)->install($builder, ['commands' => []]); $this->assertOutputFile('config.php', 'new config file from preset'); } @@ -179,10 +179,10 @@ public function installer_can_ignore_files_and_directories_from_preset_when_copy ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, [ + (new DefaultInstaller)->install($builder, [ 'ignore' => [ 'ignore-this.php', 'ignore-directory', @@ -215,10 +215,10 @@ public function installer_can_ignore_files_and_directories_from_preset_using_wil ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, [ + (new DefaultInstaller)->install($builder, [ 'ignore' => [ 'ignore*', ], @@ -243,10 +243,10 @@ public function installer_ignores_node_modules_directory_from_preset_when_copyin ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => []]); + (new DefaultInstaller)->install($builder, ['commands' => []]); $this->assertFileMissing($this->tmpPath('node_modules')); } @@ -263,10 +263,10 @@ public function installer_ignores_vendor_directory_from_preset_when_copying() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => []]); + (new DefaultInstaller)->install($builder, ['commands' => []]); $this->assertFileMissing($this->tmpPath('vendor')); } @@ -283,10 +283,10 @@ public function installer_ignores_init_file_from_preset_when_copying() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => []]); + (new DefaultInstaller)->install($builder, ['commands' => []]); $this->assertFileMissing($this->tmpPath('init.php')); } @@ -304,10 +304,10 @@ public function installer_ignores_build_directories_from_preset_when_copying() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => []]); + (new DefaultInstaller)->install($builder, ['commands' => []]); $this->assertFileMissing($this->tmpPath('build_local')); $this->assertFileMissing($this->tmpPath('build_production')); @@ -315,6 +315,7 @@ public function installer_ignores_build_directories_from_preset_when_copying() /** * @test + * * @doesNotPerformAssertions */ public function installer_runs_default_commands_if_none_are_specified_in_init() @@ -326,7 +327,7 @@ public function installer_runs_default_commands_if_none_are_specified_in_init() $builder->shouldReceive('copyPresetFiles')->andReturn($builder); $builder->shouldReceive('mergeComposerDotJson')->andReturn($builder); - $installer = new DefaultInstaller(); + $installer = new DefaultInstaller; $installer->install($builder); $builder->shouldHaveReceived('runCommands')->with($installer::DEFAULT_COMMANDS); @@ -334,6 +335,7 @@ public function installer_runs_default_commands_if_none_are_specified_in_init() /** * @test + * * @doesNotPerformAssertions */ public function installer_runs_no_commands_if_empty_array_is_specified_in_init() @@ -345,7 +347,7 @@ public function installer_runs_no_commands_if_empty_array_is_specified_in_init() $builder->shouldReceive('copyPresetFiles')->andReturn($builder); $builder->shouldReceive('mergeComposerDotJson')->andReturn($builder); - $installer = new DefaultInstaller(); + $installer = new DefaultInstaller; $installer->install($builder, ['commands' => []]); $builder->shouldHaveReceived('runCommands')->with([]); @@ -353,6 +355,7 @@ public function installer_runs_no_commands_if_empty_array_is_specified_in_init() /** * @test + * * @doesNotPerformAssertions */ public function installer_runs_specified_commands_from_init() @@ -364,7 +367,7 @@ public function installer_runs_specified_commands_from_init() $builder->shouldReceive('copyPresetFiles')->andReturn($builder); $builder->shouldReceive('mergeComposerDotJson')->andReturn($builder); - $installer = new DefaultInstaller(); + $installer = new DefaultInstaller; $installer->install($builder, ['commands' => ['yarn']]); $builder->shouldHaveReceived('runCommands')->with(['yarn']); @@ -389,10 +392,10 @@ public function composer_json_is_restored_if_deleted_after_preset_is_installed() ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => [], 'delete' => 'composer.json']); + (new DefaultInstaller)->install($builder, ['commands' => [], 'delete' => 'composer.json']); $this->assertFileExists($this->tmpPath('composer.json')); $this->assertEquals($old_composer, json_decode(file_get_contents($this->tmpPath('composer.json')), true)); @@ -423,10 +426,10 @@ public function original_composer_json_is_merged_with_composer_json_installed_by ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => [], 'delete' => 'composer.json']); + (new DefaultInstaller)->install($builder, ['commands' => [], 'delete' => 'composer.json']); $new_composer = json_decode(file_get_contents($this->tmpPath('composer.json')), true); @@ -460,10 +463,10 @@ public function version_constraints_from_original_composer_json_take_precedence_ ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => [], 'delete' => 'composer.json']); + (new DefaultInstaller)->install($builder, ['commands' => [], 'delete' => 'composer.json']); $new_composer = json_decode(file_get_contents($this->tmpPath('composer.json')), true); @@ -484,10 +487,10 @@ public function empty_composer_json_is_created_if_it_was_not_present_before_pres ]); $package = Mockery::mock(PresetPackage::class); $package->path = $this->tmp . '/package'; - $builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner()); + $builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner); $builder->setBase($this->tmp); - (new DefaultInstaller())->install($builder, ['commands' => [], 'delete' => 'composer.json']); + (new DefaultInstaller)->install($builder, ['commands' => [], 'delete' => 'composer.json']); $this->assertEquals( [ diff --git a/tests/DotInFileNameTest.php b/tests/DotInFileNameTest.php index 038c4f12..3c80c173 100644 --- a/tests/DotInFileNameTest.php +++ b/tests/DotInFileNameTest.php @@ -62,7 +62,7 @@ public function blade_files_with_dot_in_filename_are_processed() */ public function dot_in_filename_is_preserved_for_collection_item_with_default_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('collection-item-with.dot'); $outputPath = $pathResolver->link(null, $pageVariable); @@ -75,7 +75,7 @@ public function dot_in_filename_is_preserved_for_collection_item_with_default_pa */ public function dot_in_filename_is_preserved_for_collection_item_with_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('collection-item-with.dot'); $outputPath = $pathResolver->link('{filename}', $pageVariable); @@ -88,7 +88,7 @@ public function dot_in_filename_is_preserved_for_collection_item_with_shorthand_ */ public function dot_in_filename_is_preserved_for_collection_item_with_slugified_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('collection-item-with.dot'); $outputPath = $pathResolver->link('{_filename}', $pageVariable); @@ -98,7 +98,7 @@ public function dot_in_filename_is_preserved_for_collection_item_with_slugified_ protected function getPageDataDummy() { - return PageData::withPageMetaData(new IterableObject(), []); + return PageData::withPageMetaData(new IterableObject, []); } protected function getPageVariableDummy($filename) diff --git a/tests/EventsTest.php b/tests/EventsTest.php index cbdaf94a..056a451e 100644 --- a/tests/EventsTest.php +++ b/tests/EventsTest.php @@ -55,7 +55,8 @@ public function multiple_event_listeners_are_fired_in_the_order_they_were_define /** @test */ public function it_can_handle_invokable_listeners() { - $this->app['events']->beforeBuild(new class { + $this->app['events']->beforeBuild(new class + { private $object; public function __construct() @@ -554,6 +555,7 @@ public function user_can_write_a_new_output_file_in_a_new_directory_in_after_bui } } +// phpcs:disable PSR1.Classes.ClassDeclaration,Squiz.Classes.ClassFileName class TestListener { public function handle($jigsaw) diff --git a/tests/FilePathTest.php b/tests/FilePathTest.php index 1b867d73..a8e2485b 100644 --- a/tests/FilePathTest.php +++ b/tests/FilePathTest.php @@ -9,9 +9,12 @@ class FilePathTest extends TestCase { - public function test_accented_character_in_filename_is_replaced_with_unaccented_character_when_using_default_path_config() + /** + * @test + */ + public function accented_character_in_filename_is_replaced_with_unaccented_character_when_using_default_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('Fútbol solidario'); $outputPath = $pathResolver->link(null, $pageVariable); @@ -19,9 +22,12 @@ public function test_accented_character_in_filename_is_replaced_with_unaccented_ $this->assertEquals('/futbol-solidario', $outputPath[0]); } - public function test_accented_character_in_filename_is_replaced_with_unaccented_character_when_using_shorthand_path_config() + /** + * @test + */ + public function accented_character_in_filename_is_replaced_with_unaccented_character_when_using_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('Fútbol solidario'); $outputPath = $pathResolver->link('{filename}', $pageVariable); @@ -29,9 +35,12 @@ public function test_accented_character_in_filename_is_replaced_with_unaccented_ $this->assertEquals('/Futbol solidario', $outputPath[0]); } - public function test_accented_character_in_filename_is_replaced_with_unaccented_character_when_using_slugified_shorthand_path_config() + /** + * @test + */ + public function accented_character_in_filename_is_replaced_with_unaccented_character_when_using_slugified_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('Fútbol solidario'); $outputPath = $pathResolver->link('{_filename}', $pageVariable); @@ -39,9 +48,12 @@ public function test_accented_character_in_filename_is_replaced_with_unaccented_ $this->assertEquals('/futbol_solidario', $outputPath[0]); } - public function test_invalid_characters_in_filename_are_removed_when_using_default_path_config() + /** + * @test + */ + public function invalid_characters_in_filename_are_removed_when_using_default_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('Has® Invalid™ Characters'); $outputPath = $pathResolver->link(null, $pageVariable); @@ -49,9 +61,12 @@ public function test_invalid_characters_in_filename_are_removed_when_using_defau $this->assertEquals('/has-invalid-characters', $outputPath[0]); } - public function test_leading_periods_are_not_removed() + /** + * @test + */ + public function leading_periods_are_not_removed() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('.well-known'); $outputPath = $pathResolver->link(null, $pageVariable); @@ -59,9 +74,12 @@ public function test_leading_periods_are_not_removed() $this->assertEquals('/.well-known', $outputPath[0]); } - public function test_invalid_characters_in_filename_are_removed_when_using_shorthand_path_config() + /** + * @test + */ + public function invalid_characters_in_filename_are_removed_when_using_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('Has® Invalid™ Characters'); $outputPath = $pathResolver->link('{filename}', $pageVariable); @@ -69,9 +87,12 @@ public function test_invalid_characters_in_filename_are_removed_when_using_short $this->assertEquals('/Has Invalid Characters', $outputPath[0]); } - public function test_invalid_characters_in_filename_are_removed_when_using_slugified_shorthand_path_config() + /** + * @test + */ + public function invalid_characters_in_filename_are_removed_when_using_slugified_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('Has® Invalid™ Characters'); $outputPath = $pathResolver->link('{_filename}', $pageVariable); @@ -80,9 +101,12 @@ public function test_invalid_characters_in_filename_are_removed_when_using_slugi } // @todo make this consisten in v2 - public function test_some_international_characters_in_filename_are_allowed_when_using_default_path_config() + /** + * @test + */ + public function some_international_characters_in_filename_are_allowed_when_using_default_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('테스트-파일-이름'); $outputPath = $pathResolver->link(null, $pageVariable); @@ -91,9 +115,12 @@ public function test_some_international_characters_in_filename_are_allowed_when_ } // @todo make this consisten in v2 - public function test_some_international_characters_in_filename_are_allowed_when_using_shorthand_path_config() + /** + * @test + */ + public function some_international_characters_in_filename_are_allowed_when_using_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('테스트-파일-이름'); $outputPath = $pathResolver->link('{filename}', $pageVariable); @@ -102,9 +129,12 @@ public function test_some_international_characters_in_filename_are_allowed_when_ } // @todo make this consisten in v2 - public function test_some_international_characters_in_filename_are_allowed_when_using_slugified_shorthand_path_config() + /** + * @test + */ + public function some_international_characters_in_filename_are_allowed_when_using_slugified_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('테스트-파일-이름'); $outputPath = $pathResolver->link('{_filename}', $pageVariable); @@ -113,9 +143,12 @@ public function test_some_international_characters_in_filename_are_allowed_when_ } // @todo make this consisten in v2 - public function test_some_international_characters_in_filename_are_not_allowed_when_using_default_path_config() + /** + * @test + */ + public function some_international_characters_in_filename_are_not_allowed_when_using_default_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('اختبار-مسار-الملف'); $outputPath = $pathResolver->link(null, $pageVariable); @@ -124,9 +157,12 @@ public function test_some_international_characters_in_filename_are_not_allowed_w } // @todo make this consisten in v2 - public function test_some_international_characters_in_filename_are_not_allowed_when_using_shorthand_path_config() + /** + * @test + */ + public function some_international_characters_in_filename_are_not_allowed_when_using_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('اختبار-مسار-الملف'); $outputPath = $pathResolver->link('{filename}', $pageVariable); @@ -135,9 +171,12 @@ public function test_some_international_characters_in_filename_are_not_allowed_w } // @todo make this consisten in v2 - public function test_some_international_characters_in_filename_are_not_allowed_when_using_slugified_shorthand_path_config() + /** + * @test + */ + public function some_international_characters_in_filename_are_not_allowed_when_using_slugified_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('اختبار-مسار-الملف'); $outputPath = $pathResolver->link('{_filename}', $pageVariable); @@ -145,9 +184,12 @@ public function test_some_international_characters_in_filename_are_not_allowed_w $this->assertEquals('/akhtbar_msar_almlf', $outputPath[0]); } - public function test_disable_transliteration_when_using_default_path_config() + /** + * @test + */ + public function disable_transliteration_when_using_default_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('اختبار-مسار-الملف'); $outputPath = $pathResolver->link(null, $pageVariable, false); @@ -155,9 +197,12 @@ public function test_disable_transliteration_when_using_default_path_config() $this->assertEquals('/اختبار-مسار-الملف', $outputPath[0]); } - public function test_disable_transliteration_when_using_shorthand_path_config() + /** + * @test + */ + public function disable_transliteration_when_using_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('اختبار-مسار-الملف'); $outputPath = $pathResolver->link('{filename}', $pageVariable, false); @@ -165,9 +210,12 @@ public function test_disable_transliteration_when_using_shorthand_path_config() $this->assertEquals('/اختبار-مسار-الملف', $outputPath[0]); } - public function test_disable_transliteration_when_using_slugified_shorthand_path_config() + /** + * @test + */ + public function disable_transliteration_when_using_slugified_shorthand_path_config() { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); $pathResolver = $this->app->make(CollectionPathResolver::class); $pageVariable = $this->getPageVariableDummy('اختبار-مسار-الملف'); $outputPath = $pathResolver->link('{_filename}', $pageVariable, false); diff --git a/tests/FilesystemTest.php b/tests/FilesystemTest.php index 8d96d8f4..d8935a2d 100644 --- a/tests/FilesystemTest.php +++ b/tests/FilesystemTest.php @@ -48,7 +48,7 @@ public function DS_Store_is_always_ignored_when_retrieving_all_files_and_directo $files = collect( $this->app->make(Filesystem::class) - ->filesAndDirectories($this->tmp), + ->filesAndDirectories($this->tmp), )->map(function ($file) { return $file->getRelativePathName(); }); @@ -259,7 +259,7 @@ protected function getFilesMatching($match) return collect( $this->app->make(Filesystem::class) - ->filesAndDirectories($this->tmp, $match), + ->filesAndDirectories($this->tmp, $match), )->map(function ($file) { return $file->getRelativePathName(); }); @@ -271,7 +271,7 @@ protected function getFilesExcept($ignore) return collect( $this->app->make(Filesystem::class) - ->filesAndDirectories($this->tmp, null, $ignore), + ->filesAndDirectories($this->tmp, null, $ignore), )->map(function ($file) { return $file->getRelativePathName(); }); diff --git a/tests/InitCommandTest.php b/tests/InitCommandTest.php index 88cb16c9..cb6e09d1 100644 --- a/tests/InitCommandTest.php +++ b/tests/InitCommandTest.php @@ -25,7 +25,7 @@ public function init_command_with_no_arguments_uses_basic_scaffold_for_site() $this->createSource([]); $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $command->setBase($this->tmp); $console = new CommandTester($command); @@ -49,7 +49,7 @@ public function init_command_with_argument_uses_preset_scaffold_for_site() $this->createSource([]); $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $command->setBase($this->tmp); $console = new CommandTester($command); @@ -66,7 +66,7 @@ public function init_command_with_argument_uses_preset_scaffold_for_site() public function init_command_displays_error_if_preset_name_is_invalid() { $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $console = new CommandTester($command); $console->execute(['preset' => 'invalid']); @@ -80,7 +80,7 @@ public function init_command_displays_warning_if_source_directory_exists() { $this->createSource(['source' => []]); $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $command->setBase($this->tmp); $console = new CommandTester($command); @@ -97,7 +97,7 @@ public function init_command_displays_warning_if_config_dot_php_exists() { $this->createSource(['config.php' => '']); $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $command->setBase($this->tmp); $console = new CommandTester($command); @@ -121,7 +121,7 @@ public function will_not_build_scaffold_if_site_already_initialized_and_user_cho $this->createSource(['config.php' => '']); $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $command->setBase($this->tmp); $console = new CommandTester($command); @@ -147,7 +147,7 @@ public function will_archive_existing_site_if_user_chooses_archive_option() $this->createSource(['config.php' => '']); $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $command->setBase($this->tmp); $console = new CommandTester($command); @@ -172,7 +172,7 @@ public function will_build_scaffold_if_site_already_initialized_and_user_chooses $this->createSource(['config.php' => '']); $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $command->setBase($this->tmp); $console = new CommandTester($command); @@ -197,7 +197,7 @@ public function will_delete_existing_site_if_user_chooses_delete_option() $this->createSource(['config.php' => '']); $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $command->setBase($this->tmp); $console = new CommandTester($command); @@ -222,7 +222,7 @@ public function will_build_scaffold_if_site_already_initialized_and_user_chooses $this->createSource(['config.php' => '']); $command = $this->app->make(InitCommand::class); - $command->setApplication(new Application()); + $command->setApplication(new Application); $command->setBase($this->tmp); $console = new CommandTester($command); diff --git a/tests/IterableObjectTest.php b/tests/IterableObjectTest.php index 093020aa..48cd1b7d 100644 --- a/tests/IterableObjectTest.php +++ b/tests/IterableObjectTest.php @@ -176,4 +176,8 @@ public function intermediate_items_that_extend_IterableObject_are_not_changed_wh } } -class ExtendsIterableObject extends IterableObject {} +// phpcs:disable PSR1.Classes.ClassDeclaration,Squiz.Classes.ClassFileName +class ExtendsIterableObject extends IterableObject +{ +} +// phpcs:enable diff --git a/tests/JigsawMacroTest.php b/tests/JigsawMacroTest.php index 2443a8c8..23433bd4 100644 --- a/tests/JigsawMacroTest.php +++ b/tests/JigsawMacroTest.php @@ -29,6 +29,7 @@ public function jigsaw_mixin_function_calls_successfully() } } +// phpcs:disable PSR1.Classes.ClassDeclaration,Squiz.Classes.ClassFileName class JigsawMixinTestClass { public function getNameMixin() diff --git a/tests/PageDataBindingTest.php b/tests/PageDataBindingTest.php index 3e37fafe..aacd11b5 100644 --- a/tests/PageDataBindingTest.php +++ b/tests/PageDataBindingTest.php @@ -35,6 +35,7 @@ class_alias('Tests\TestPageHeaderComponent', 'Components\PageHeader'); } } +// phpcs:disable PSR1.Classes.ClassDeclaration,Squiz.Classes.ClassFileName class TestPageHeaderComponent extends Component { public $page; diff --git a/tests/PhpOpenTagInMarkdownTest.php b/tests/PhpOpenTagInMarkdownTest.php index af14f702..6feeec5f 100644 --- a/tests/PhpOpenTagInMarkdownTest.php +++ b/tests/PhpOpenTagInMarkdownTest.php @@ -41,6 +41,6 @@ public function blade_md_hybrid_files_containing_php_open_tag_are_processed() protected function getPageDataDummy() { - return PageData::withPageMetaData(new IterableObject(), []); + return PageData::withPageMetaData(new IterableObject, []); } } diff --git a/tests/PresetScaffoldBuilderTest.php b/tests/PresetScaffoldBuilderTest.php index 55b3e3c9..9048a289 100644 --- a/tests/PresetScaffoldBuilderTest.php +++ b/tests/PresetScaffoldBuilderTest.php @@ -61,12 +61,13 @@ public function named_preset_resolves_to_vendor_package_path_if_not_predefined() /** * @test + * * @doesNotPerformAssertions */ public function package_is_loaded_via_composer_if_not_found_locally() { $process = Mockery::spy(ProcessRunner::class); - $this->app->instance(PresetPackage::class, new PresetPackage(new DefaultInstaller(), new CustomInstaller(), $process)); + $this->app->instance(PresetPackage::class, new PresetPackage(new DefaultInstaller, new CustomInstaller, $process)); $preset = $this->app->make(PresetScaffoldBuilder::class); $this->createSource(['vendor' => ['test' => ['package' => []]]]); $preset->base = $this->tmp; @@ -126,6 +127,7 @@ public function exception_is_thrown_if_package_init_file_contains_errors() /** * @test + * * @doesNotPerformAssertions */ public function init_file_of_array_type_is_loaded() @@ -157,6 +159,7 @@ public function init_file_of_array_type_is_loaded() /** * @test + * * @doesNotPerformAssertions */ public function init_file_of_php_type_is_loaded() @@ -191,6 +194,7 @@ public function init_file_of_php_type_is_loaded() /** * @test + * * @doesNotPerformAssertions */ public function init_file_is_optional() diff --git a/tests/SnapshotsTest.php b/tests/SnapshotsTest.php index 77452c0b..a055320c 100644 --- a/tests/SnapshotsTest.php +++ b/tests/SnapshotsTest.php @@ -40,7 +40,9 @@ public function snapshots(): array /** * @test + * * @group snapshots + * * @dataProvider snapshots */ public function build(string $name) diff --git a/tests/TestCase.php b/tests/TestCase.php index 53a4fdd1..c00ffd82 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -57,14 +57,6 @@ protected function setUp(): void ]; } - protected function createTmp(): void - { - mkdir($this->tmp = __DIR__ . '/fixtures/tmp/' . static::haiku()); - - // TODO this creates Jigsaw's cache directory in the root of this repo - $this->filesystem->ensureDirectoryExists(app()->cachePath()); - } - protected function tearDown(): void { if ($this->app) { @@ -98,6 +90,45 @@ public function getInputFile($filename) return new InputFile($sourceFile, $this->sourcePath); } + public function buildSite($vfs = null, $config = [], $pretty = false, $viewPath = '/source') + { + $this->app->consoleOutput->setup($verbosity = -1); + $this->app->config = collect($this->app->config)->merge($config); + + if ($collections = value($this->app->config->get('collections'))) { + $this->app->config->put('collections', collect($collections)->flatMap(function ($value, $key) { + return is_array($value) ? [$key => $value] : [$value => []]; + })); + } + + $this->app->buildPath = [ + 'source' => "{$this->tmp}/source", + 'views' => "{$this->tmp}/{$viewPath}", + 'destination' => "{$this->tmp}/build", + ]; + + if ($pretty) { + $this->app->instance('outputPathResolver', new PrettyOutputPathResolver); + } + + return $this->app + ->make(Jigsaw::class) + ->build('test'); + } + + public function clean($output) + { + return str_replace("\n", '', $output); + } + + protected function createTmp(): void + { + mkdir($this->tmp = __DIR__ . '/fixtures/tmp/' . static::haiku()); + + // TODO this creates Jigsaw's cache directory in the root of this repo + $this->filesystem->ensureDirectoryExists(app()->cachePath()); + } + protected function tmpPath(string $path): string { return "{$this->tmp}/{$path}"; @@ -110,10 +141,12 @@ protected function setupSource($source = []) { $this->createSource(['source' => $source]); - return new class($this->tmpPath('')) { + return new class($this->tmpPath('')) + { public function __construct( protected string $tmp, - ) {} + ) { + } public function hasChild($path) { @@ -122,11 +155,13 @@ public function hasChild($path) public function getChild($path) { - return new class($this->tmp, $path) { + return new class($this->tmp, $path) + { public function __construct( protected string $tmp, protected string $path, - ) {} + ) { + } public function getContent() { @@ -173,37 +208,6 @@ protected function buildSiteData($vfs = null, $config = []) return $siteData->addCollectionData($collectionData); } - public function buildSite($vfs = null, $config = [], $pretty = false, $viewPath = '/source') - { - $this->app->consoleOutput->setup($verbosity = -1); - $this->app->config = collect($this->app->config)->merge($config); - - if ($collections = value($this->app->config->get('collections'))) { - $this->app->config->put('collections', collect($collections)->flatMap(function ($value, $key) { - return is_array($value) ? [$key => $value] : [$value => []]; - })); - } - - $this->app->buildPath = [ - 'source' => "{$this->tmp}/source", - 'views' => "{$this->tmp}/{$viewPath}", - 'destination' => "{$this->tmp}/build", - ]; - - if ($pretty) { - $this->app->instance('outputPathResolver', new PrettyOutputPathResolver()); - } - - return $this->app - ->make(Jigsaw::class) - ->build('test'); - } - - public function clean($output) - { - return str_replace("\n", '', $output); - } - protected function fixDirectorySlashes(string $path): string { return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); diff --git a/tests/ViewPathTest.php b/tests/ViewPathTest.php index 113936d8..9741604f 100644 --- a/tests/ViewPathTest.php +++ b/tests/ViewPathTest.php @@ -9,7 +9,7 @@ public function can_load_views_from_custom_path() { $this->createSource([ 'source' => [ - 'page.md' => << <<<'MD' --- extends: main --- @@ -17,7 +17,7 @@ public function can_load_views_from_custom_path() MD, ], 'views' => [ - 'main.blade.php' => << <<<'BLADE' @yield('content') @@ -27,7 +27,7 @@ public function can_load_views_from_custom_path() $this->buildSite(null, [], false, '/views'); - $this->assertOutputFile('build/page.html', <<assertOutputFile('build/page.html', <<<'HTML'

Hello world!

diff --git a/tests/rebuild.php b/tests/rebuild.php index 0402d374..6b977204 100644 --- a/tests/rebuild.php +++ b/tests/rebuild.php @@ -22,5 +22,4 @@ function removeDirectory($path) rmdir($path); - return; -} + }