diff --git a/config/docs.php b/config/docs.php index 4ac1dd70..9650b1f0 100644 --- a/config/docs.php +++ b/config/docs.php @@ -90,7 +90,7 @@ | | Example: https://github.com/hydephp/docs/blob/master | Do not specify the filename or extension, Hyde will do that for you. - | Setting the setting to null will disable the feature. + | Setting this to null will disable the feature. | */ diff --git a/config/hyde.php b/config/hyde.php index 408ababf..ba8757a0 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -138,7 +138,7 @@ | Site Output Directory |-------------------------------------------------------------------------- | - | This setting specifies the output path for your site, useful to for + | This setting specifies the output path for your site, useful to, for | example, store the site in the docs/ directory for GitHub Pages. | The path is relative to the root of your project. | @@ -308,7 +308,7 @@ | | Here you can customize the footer Markdown text for your site. | - | If you don't want to write Markdown here, you use a Markdown include. + | If you don't want to write Markdown here, you can use a Markdown include. | You can also customize the Blade view if you want a more complex footer. | You can disable it completely by changing the setting to `false`. | @@ -428,7 +428,7 @@ | | Here you can configure settings for the built-in realtime compiler server. | The server also includes a magic dashboard feature that supercharges - | your local development! This feature can alo be customised here. + | your local development! This feature can also be customised here. | */ diff --git a/config/markdown.php b/config/markdown.php index cd9afdea..b872c1a7 100644 --- a/config/markdown.php +++ b/config/markdown.php @@ -71,7 +71,7 @@ | | This feature allows you to use basic Laravel Blade in Markdown files. | - | It's disabled by default since can be a security risk as it allows + | It's disabled by default since it can be a security risk as it allows | arbitrary PHP to run. But if your Markdown is trusted, try it out! | | To see the syntax and usage, see the documentation: diff --git a/src/Console/Commands/BuildSiteCommand.php b/src/Console/Commands/BuildSiteCommand.php index db199299..e809eff6 100644 --- a/src/Console/Commands/BuildSiteCommand.php +++ b/src/Console/Commands/BuildSiteCommand.php @@ -26,12 +26,11 @@ class BuildSiteCommand extends Command { /** @var string */ protected $signature = 'build - {--run-vite : Build frontend assets using Vite} - {--run-prettier : Format the output using NPM Prettier} + {--vite : Build frontend assets using Vite} {--pretty-urls : Should links in output use pretty URLs?} {--no-api : Disable API calls, for example, Torchlight} - {--run-dev : [Removed] Use --run-vite instead} - {--run-prod : [Removed] Use --run-vite instead}'; + {--run-dev : [Removed] Use --vite instead} + {--run-prod : [Removed] Use --vite instead}'; /** @var string */ protected $description = 'Build the static site'; @@ -88,7 +87,7 @@ protected function runPreBuildActions(): void Config::set(['hyde.pretty_urls' => true]); } - if ($this->option('run-vite')) { + if ($this->option('vite')) { $this->runNodeCommand('npm run build', 'Building frontend assets for production!'); } @@ -98,14 +97,6 @@ protected function runPreBuildActions(): void public function runPostBuildActions(): void { $this->taskService->runPostBuildTasks(); - - if ($this->option('run-prettier')) { - $this->runNodeCommand( - 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line', - 'Prettifying code!', - 'prettify code' - ); - } } protected function printFinishMessage(float $timeStart): void @@ -161,7 +152,7 @@ protected function getExitCode(): int /** * This method is called when the removed --run-dev or --run-prod options are used. * - * @deprecated Use --run-vite instead + * @deprecated Use --vite instead * @since v2.0 - This will be removed after 2-3 minor releases depending on the timeframe between them. (~v2.3) * * @codeCoverageIgnore @@ -170,7 +161,7 @@ protected function checkForDeprecatedRunMixCommandUsage(): void { if ($this->option('run-dev') || $this->option('run-prod')) { $this->error('The --run-dev and --run-prod options have been removed in HydePHP v2.0.'); - $this->info('Please use --run-vite instead to build assets for production with Vite.'); + $this->info('Please use --vite instead to build assets for production with Vite.'); $this->line('See https://github.com/hydephp/develop/pull/2013 for more information.'); exit(Command::INVALID); diff --git a/src/Console/Commands/ServeCommand.php b/src/Console/Commands/ServeCommand.php deleted file mode 100644 index c7132e4f..00000000 --- a/src/Console/Commands/ServeCommand.php +++ /dev/null @@ -1,232 +0,0 @@ -[default: "localhost"]}} - {--port= : [default: 8080]} - {--save-preview= : Should the served page be saved to disk? (Overrides config setting)} - {--dashboard= : Enable the realtime compiler dashboard. (Overrides config setting)} - {--pretty-urls= : Enable pretty URLs. (Overrides config setting)} - {--play-cdn= : Enable the Tailwind Play CDN. (Overrides config setting)} - {--open=false : Open the site preview in the browser.} - {--vite : Enable Vite for Hot Module Replacement (HMR)} - '; - - /** @var string */ - protected $description = 'Start the realtime compiler server'; - - protected ConsoleOutput $console; - - protected InvokedProcess $server; - protected ?InvokedProcess $vite = null; - - public function safeHandle(): int - { - $this->configureOutput(); - $this->printStartMessage(); - - if ($this->option('open') !== 'false') { - $this->openInBrowser((string) $this->option('open')); - } - - if ($this->option('vite')) { - $this->runViteProcess(); - } - - $this->runServerProcess(sprintf('php -S %s:%d %s', - $this->getHostSelection(), - $this->getPortSelection(), - escapeshellarg($this->getExecutablePath()), - )); - - $this->handleRunningProcesses(); - - return Command::SUCCESS; - } - - protected function getHostSelection(): string - { - return (string) $this->option('host') ?: Config::getString('hyde.server.host', 'localhost'); - } - - protected function getPortSelection(): int - { - return (int) ($this->option('port') ?: Config::getInt('hyde.server.port', 8080)); - } - - protected function getExecutablePath(): string - { - return Hyde::path('vendor/hyde/realtime-compiler/bin/server.php'); - } - - protected function runServerProcess(string $command): void - { - $this->server = Process::forever()->env($this->getEnvironmentVariables())->start($command, $this->getOutputHandler()); - } - - protected function getEnvironmentVariables(): array - { - return Arr::whereNotNull([ - 'HYDE_SERVER_REQUEST_OUTPUT' => ! $this->option('no-ansi'), - 'HYDE_SERVER_SAVE_PREVIEW' => $this->parseEnvironmentOption('save-preview'), - 'HYDE_SERVER_DASHBOARD' => $this->parseEnvironmentOption('dashboard'), - 'HYDE_PRETTY_URLS' => $this->parseEnvironmentOption('pretty-urls'), - 'HYDE_PLAY_CDN' => $this->parseEnvironmentOption('play-cdn'), - ]); - } - - protected function configureOutput(): void - { - if (! $this->useBasicOutput()) { - $this->console = new ConsoleOutput($this->output->isVerbose()); - } - } - - protected function printStartMessage(): void - { - $this->useBasicOutput() - ? $this->output->writeln('Starting the HydeRC server... Use Ctrl+C to stop') - : $this->console->printStartMessage($this->getHostSelection(), $this->getPortSelection(), $this->getEnvironmentVariables(), $this->option('vite')); - } - - protected function getOutputHandler(): Closure - { - return $this->useBasicOutput() ? function (string $type, string $line): void { - $this->output->write($line); - } : $this->console->getFormatter(); - } - - protected function useBasicOutput(): bool - { - return $this->option('no-ansi') || ! class_exists(ConsoleOutput::class); - } - - protected function parseEnvironmentOption(string $name): ?string - { - $value = $this->option($name) ?? $this->checkArgvForOption($name); - - if ($value !== null) { - return match ($value) { - 'true', '' => 'enabled', - 'false' => 'disabled', - default => throw new InvalidArgumentException(sprintf('Invalid boolean value for --%s option.', $name)) - }; - } - - return null; - } - - /** Fallback check so that an environment option without a value is acknowledged as true. */ - protected function checkArgvForOption(string $name): ?string - { - if (isset($_SERVER['argv'])) { - if (in_array("--$name", $_SERVER['argv'], true)) { - return 'true'; - } - } - - return null; - } - - protected function openInBrowser(string $path = '/'): void - { - $binary = $this->getOpenCommand(PHP_OS_FAMILY); - - $command = sprintf('%s http://%s:%d', $binary, $this->getHostSelection(), $this->getPortSelection()); - $command = rtrim("$command/$path", '/'); - - $process = $binary ? Process::command($command)->run() : null; - - if (! $process || $process->failed()) { - $this->warn('Unable to open the site preview in the browser on your system:'); - $this->line(sprintf(' %s', str_replace("\n", "\n ", $process ? $process->errorOutput() : "Missing suitable 'open' binary."))); - $this->newLine(); - } - } - - protected function getOpenCommand(string $osFamily): ?string - { - return match ($osFamily) { - 'Windows' => 'start', - 'Darwin' => 'open', - 'Linux' => 'xdg-open', - default => null - }; - } - - protected function runViteProcess(): void - { - if (! $this->isPortAvailable(5173)) { - throw new InvalidArgumentException( - 'Unable to start Vite server: Port 5173 is already in use. '. - 'Please stop any other Vite processes and try again.' - ); - } - - Filesystem::touch('app/storage/framework/runtime/vite.hot'); - - $this->vite = Process::forever()->start('npm run dev'); - } - - protected function handleRunningProcesses(): void - { - while ($this->server->running()) { - $this->handleViteOutput(); - - Sleep::for(100)->milliseconds(); - } - } - - protected function handleViteOutput(): void - { - if ($this->vite?->running()) { - $output = $this->vite->latestOutput(); - - if ($output) { - $this->output->write($output); - } - } - } - - /** @experimental This feature may be removed before the final release. */ - protected function isPortAvailable(int $port): bool - { - $socket = @fsockopen('localhost', $port, $errno, $errstr, 1); - if ($socket !== false) { - fclose($socket); - - return false; - } - - return true; - } -} diff --git a/src/Console/ConsoleServiceProvider.php b/src/Console/ConsoleServiceProvider.php index 5e8cb9b0..a62819aa 100644 --- a/src/Console/ConsoleServiceProvider.php +++ b/src/Console/ConsoleServiceProvider.php @@ -34,7 +34,6 @@ public function register(): void Commands\RouteListCommand::class, Commands\ValidateCommand::class, - Commands\ServeCommand::class, Commands\DebugCommand::class, Commands\ChangeSourceDirectoryCommand::class, diff --git a/src/Console/Helpers/InteractivePublishCommandHelper.php b/src/Console/Helpers/InteractivePublishCommandHelper.php index faf33bb2..97f08712 100644 --- a/src/Console/Helpers/InteractivePublishCommandHelper.php +++ b/src/Console/Helpers/InteractivePublishCommandHelper.php @@ -60,7 +60,7 @@ public function getBaseDirectory(): string public function publishFiles(): void { foreach ($this->publishableFilesMap as $source => $target) { - Filesystem::ensureDirectoryExists(dirname($target)); + Filesystem::ensureParentDirectoryExists($target); Filesystem::copy($source, $target); } } diff --git a/src/Facades/Config.php b/src/Facades/Config.php index f9630af4..77aaeeb0 100644 --- a/src/Facades/Config.php +++ b/src/Facades/Config.php @@ -44,7 +44,7 @@ public static function getFloat(string $key, ?float $default = null): float return (float) self::validated(static::get($key, $default), 'float', $key); } - /** @experimental Could possibly be merged by allowing null returns if default is null? Preferably with generics so the type is matched by IDE support. */ + /** @experimental */ public static function getNullableString(string $key, ?string $default = null): ?string { /** @var array|string|int|bool|float|null $value */ diff --git a/src/Facades/Filesystem.php b/src/Facades/Filesystem.php index 5523f658..7fcca1fd 100644 --- a/src/Facades/Filesystem.php +++ b/src/Facades/Filesystem.php @@ -117,6 +117,19 @@ public static function unlinkIfExists(string $path): bool return self::kernel()->filesystem()->unlinkIfExists($path); } + /** + * Ensure that the parent directory of the given file path exists. + * + * @param string $path + * @param int $mode + * @param bool $recursive + * @return void + */ + public static function ensureParentDirectoryExists(string $path, int $mode = 0755, bool $recursive = true): void + { + self::ensureDirectoryExists(self::dirname($path), $mode, $recursive); + } + /** * Get the contents of a file. * diff --git a/src/Foundation/Concerns/ImplementsStringHelpers.php b/src/Foundation/Concerns/ImplementsStringHelpers.php index 91096048..3fb12988 100644 --- a/src/Foundation/Concerns/ImplementsStringHelpers.php +++ b/src/Foundation/Concerns/ImplementsStringHelpers.php @@ -46,7 +46,11 @@ public static function makeSlug(string $value): string // Transliterate international characters to ASCII $value = Str::transliterate($value); - // Todo: In v2.0 we will use the following dictionary: ['@' => 'at', '&' => 'and'] + // Normalize a couple of common symbols before slugging (since v2) + $value = strtr($value, [ + '@' => ' at ', + '&' => ' and ', + ]); return Str::slug($value); } diff --git a/src/Foundation/HydeKernel.php b/src/Foundation/HydeKernel.php index 22e34c0e..992ad488 100644 --- a/src/Foundation/HydeKernel.php +++ b/src/Foundation/HydeKernel.php @@ -50,7 +50,7 @@ class HydeKernel implements SerializableContract use Serializable; use Macroable; - final public const VERSION = '2.0.0-RC.3'; + final public const VERSION = '2.0.0-RC.4'; protected static self $instance; diff --git a/src/Framework/Concerns/RegistersFileLocations.php b/src/Framework/Concerns/RegistersFileLocations.php index b44c7808..24c56ab8 100644 --- a/src/Framework/Concerns/RegistersFileLocations.php +++ b/src/Framework/Concerns/RegistersFileLocations.php @@ -104,7 +104,7 @@ protected function getOutputDirectoryConfiguration(string $class, string $defaul private function getPageConfiguration(string $option, string $class, string $default): string { - return Config::getNullableString("hyde.$option.".Str::kebab(class_basename($class))) /** @experimental Support for using kebab-case class names */ + return Config::getNullableString("hyde.$option.".Str::kebab(class_basename($class))) ?? Config::getNullableString("hyde.$option.$class") ?? $default; } diff --git a/src/Framework/Exceptions/InvalidConfigurationException.php b/src/Framework/Exceptions/InvalidConfigurationException.php index 306b6fd4..f54ebfc0 100644 --- a/src/Framework/Exceptions/InvalidConfigurationException.php +++ b/src/Framework/Exceptions/InvalidConfigurationException.php @@ -48,8 +48,6 @@ protected function findConfigLine(string $namespace, string $key): array /** * @internal - * - * @experimental */ public static function try(callable $callback, ?string $message = null): mixed { diff --git a/src/Framework/Exceptions/ParseException.php b/src/Framework/Exceptions/ParseException.php index 1611bdbd..f3af4e6c 100644 --- a/src/Framework/Exceptions/ParseException.php +++ b/src/Framework/Exceptions/ParseException.php @@ -12,7 +12,6 @@ use function sprintf; use function explode; -/** @experimental This class may change significantly before its release. */ class ParseException extends RuntimeException { /** @var int */ diff --git a/src/Framework/Factories/BlogPostDataFactory.php b/src/Framework/Factories/BlogPostDataFactory.php index 57be18ec..95b5fa9c 100644 --- a/src/Framework/Factories/BlogPostDataFactory.php +++ b/src/Framework/Factories/BlogPostDataFactory.php @@ -74,7 +74,7 @@ public function toArray(): array protected function makeDescription(): string { - return $this->getMatter('description') ?? $this->makeDescriptionFromMarkdownBody(); + return $this->getMatter('description') ?? $this->getMatter('excerpt') ?? $this->makeDescriptionFromMarkdownBody(); } protected function makeCategory(): ?string diff --git a/src/Framework/Features/Navigation/NavigationGroup.php b/src/Framework/Features/Navigation/NavigationGroup.php index 229960da..59108e56 100644 --- a/src/Framework/Features/Navigation/NavigationGroup.php +++ b/src/Framework/Features/Navigation/NavigationGroup.php @@ -57,7 +57,6 @@ protected function containsOnlyDocumentationPages(): bool }); } - /** @experimental This method is subject to change before its release. */ public static function normalizeGroupKey(string $group): string { return Str::slug($group); diff --git a/src/Framework/Features/Navigation/NavigationMenuGenerator.php b/src/Framework/Features/Navigation/NavigationMenuGenerator.php index 02467e4c..c73d6663 100644 --- a/src/Framework/Features/Navigation/NavigationMenuGenerator.php +++ b/src/Framework/Features/Navigation/NavigationMenuGenerator.php @@ -19,9 +19,6 @@ use function in_array; use function strtolower; -/** - * @experimental This class may change significantly before its release. - */ class NavigationMenuGenerator { /** @var \Illuminate\Support\Collection */ @@ -194,8 +191,7 @@ protected function normalizeGroupLabel(string $label): string protected function searchForGroupLabelInConfig(string $groupKey): ?string { - // TODO: Normalize this: sidebar_group_labels -> docs.sidebar.labels - return $this->getConfigArray($this->generatesSidebar ? 'docs.sidebar_group_labels' : 'hyde.navigation.labels')[$groupKey] ?? null; + return $this->getConfigArray($this->generatesSidebar ? 'docs.sidebar.labels' : 'hyde.navigation.labels')[$groupKey] ?? null; } protected function searchForGroupPriorityInConfig(string $groupKey): ?int diff --git a/src/Markdown/Contracts/FrontMatter/BlogPostSchema.php b/src/Markdown/Contracts/FrontMatter/BlogPostSchema.php index cee053f8..4ef0e90f 100644 --- a/src/Markdown/Contracts/FrontMatter/BlogPostSchema.php +++ b/src/Markdown/Contracts/FrontMatter/BlogPostSchema.php @@ -14,7 +14,7 @@ interface BlogPostSchema extends PageSchema { public const BLOG_POST_SCHEMA = [ 'title' => 'string', - 'description' => 'string', + 'description' => 'string', // Excerpt is also supported 'category' => 'string', 'date' => 'string', 'author' => ['string', AuthorSchema::AUTHOR_SCHEMA], diff --git a/src/Pages/Concerns/BaseMarkdownPage.php b/src/Pages/Concerns/BaseMarkdownPage.php index 20438097..ba738c6a 100644 --- a/src/Pages/Concerns/BaseMarkdownPage.php +++ b/src/Pages/Concerns/BaseMarkdownPage.php @@ -10,7 +10,6 @@ use Hyde\Markdown\Models\Markdown; use Illuminate\Support\Facades\View; -use function dirname; use function ltrim; use function trim; @@ -65,7 +64,7 @@ public function compile(): string */ public function save(): static { - Filesystem::ensureDirectoryExists(dirname($this->getSourcePath())); + Filesystem::ensureParentDirectoryExists($this->getSourcePath()); Filesystem::putContents($this->getSourcePath(), ltrim(trim("$this->matter\n$this->markdown")."\n")); diff --git a/src/Support/Internal/RouteListItem.php b/src/Support/Internal/RouteListItem.php index 43e11c1b..18a1ed06 100644 --- a/src/Support/Internal/RouteListItem.php +++ b/src/Support/Internal/RouteListItem.php @@ -45,7 +45,6 @@ protected function stylePageType(string $class): string $page = $this->route->getPage(); - /** @experimental The typeLabel macro is experimental */ if ($page instanceof InMemoryPage && $page->hasMacro('typeLabel')) { $type .= sprintf(' (%s)', (string) $page->__call('typeLabel', [])); } diff --git a/src/Support/Models/RouteKey.php b/src/Support/Models/RouteKey.php index ab2dcf59..a97916c8 100644 --- a/src/Support/Models/RouteKey.php +++ b/src/Support/Models/RouteKey.php @@ -57,8 +57,6 @@ public static function fromPage(string $pageClass, string $identifier): self } /** - * @experimental - * * @param class-string<\Hyde\Pages\Concerns\HydePage> $pageClass * */ protected static function stripPrefixIfNeeded(string $pageClass, string $identifier): string diff --git a/src/helpers.php b/src/helpers.php index ddc0bf27..c7089ef6 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -119,6 +119,13 @@ function make_title(string $value): string } } + if (! function_exists('\Hyde\title')) { + function title(string $value): string + { + return hyde()->makeTitle($value); + } + } + if (! function_exists('\Hyde\normalize_newlines')) { function normalize_newlines(string $string): string { diff --git a/tests/Feature/Actions/AnonymousViewCompilerTest.php b/tests/Feature/Actions/AnonymousViewCompilerTest.php index 2d52fec7..717ebf91 100644 --- a/tests/Feature/Actions/AnonymousViewCompilerTest.php +++ b/tests/Feature/Actions/AnonymousViewCompilerTest.php @@ -8,9 +8,7 @@ use Hyde\Framework\Exceptions\FileNotFoundException; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Framework\Actions\AnonymousViewCompiler - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\AnonymousViewCompiler::class)] class AnonymousViewCompilerTest extends TestCase { public function testCanCompileBladeFile() diff --git a/tests/Feature/Actions/ConvertsMarkdownToPlainTextTest.php b/tests/Feature/Actions/ConvertsMarkdownToPlainTextTest.php index 60c0228f..fd725fc3 100644 --- a/tests/Feature/Actions/ConvertsMarkdownToPlainTextTest.php +++ b/tests/Feature/Actions/ConvertsMarkdownToPlainTextTest.php @@ -7,9 +7,7 @@ use Hyde\Framework\Actions\ConvertsMarkdownToPlainText; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Framework\Actions\ConvertsMarkdownToPlainText - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\ConvertsMarkdownToPlainText::class)] class ConvertsMarkdownToPlainTextTest extends TestCase { public function testItRemovesHeadings() diff --git a/tests/Feature/Actions/CreatesNewPageSourceFileTest.php b/tests/Feature/Actions/CreatesNewPageSourceFileTest.php index 0748dbfa..9f5d26bd 100644 --- a/tests/Feature/Actions/CreatesNewPageSourceFileTest.php +++ b/tests/Feature/Actions/CreatesNewPageSourceFileTest.php @@ -13,9 +13,7 @@ use Hyde\Pages\DocumentationPage; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Framework\Actions\CreatesNewPageSourceFile - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\CreatesNewPageSourceFile::class)] class CreatesNewPageSourceFileTest extends TestCase { public function testClassCanBeInstantiated() diff --git a/tests/Feature/AssetAPIFeatureTest.php b/tests/Feature/AssetAPIFeatureTest.php index 73c26047..e8e3a14a 100644 --- a/tests/Feature/AssetAPIFeatureTest.php +++ b/tests/Feature/AssetAPIFeatureTest.php @@ -12,11 +12,10 @@ /** * High level test for the Asset API. - * - * @covers \Hyde\Facades\Asset - * @covers \Hyde\Support\Filesystem\MediaFile - * @covers \Hyde\Foundation\Kernel\Hyperlinks */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Asset::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Filesystem\MediaFile::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\Hyperlinks::class)] class AssetAPIFeatureTest extends TestCase { public function testAssetAPIExamples() diff --git a/tests/Feature/AutomaticNavigationConfigurationsTest.php b/tests/Feature/AutomaticNavigationConfigurationsTest.php index 235e5aae..e0054f23 100644 --- a/tests/Feature/AutomaticNavigationConfigurationsTest.php +++ b/tests/Feature/AutomaticNavigationConfigurationsTest.php @@ -28,15 +28,14 @@ * High-level broad-spectrum tests for the automatic navigation configurations, testing various setups. * * @see \Hyde\Framework\Testing\Unit\Views\NavigationHtmlLayoutsTest - * - * @covers \Hyde\Facades\Navigation - * @covers \Hyde\Framework\Factories\NavigationDataFactory - * @covers \Hyde\Framework\Features\Navigation\NavigationMenuGenerator - * @covers \Hyde\Framework\Features\Navigation\DocumentationSidebar - * @covers \Hyde\Framework\Features\Navigation\MainNavigationMenu - * @covers \Hyde\Framework\Features\Navigation\NavigationMenu - * @covers \Hyde\Framework\Features\Navigation\NavigationItem */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Navigation::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\NavigationDataFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationMenuGenerator::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\DocumentationSidebar::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\MainNavigationMenu::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationMenu::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationItem::class)] class AutomaticNavigationConfigurationsTest extends TestCase { protected function setUp(): void @@ -867,7 +866,7 @@ public function testSidebarWithConfigLabels() public function testSidebarGroupLabelsCanBeSetInConfig() { - config(['docs.sidebar_group_labels' => ['foo' => 'Bar']]); + config(['docs.sidebar.labels' => ['foo' => 'Bar']]); $this->assertSidebarEquals([ ['label' => 'Bar', 'children' => ['Bar']], @@ -1022,7 +1021,7 @@ public function testSidebarItemGroupingIsNormalized() public function testSidebarLabelsCanBeSetInConfig() { - config(['docs.sidebar_group_labels' => ['foo' => 'Hello world!']]); + config(['docs.sidebar.labels' => ['foo' => 'Hello world!']]); $this->assertSidebarEquals(['Hello world!'], [ new DocumentationPage('foo', ['navigation.group' => 'foo']), diff --git a/tests/Feature/BladeMatterParserTest.php b/tests/Feature/BladeMatterParserTest.php index eac6d4a7..3e0eec76 100644 --- a/tests/Feature/BladeMatterParserTest.php +++ b/tests/Feature/BladeMatterParserTest.php @@ -8,9 +8,7 @@ use Hyde\Testing\TestCase; use RuntimeException; -/** - * @covers \Hyde\Framework\Actions\BladeMatterParser - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\BladeMatterParser::class)] class BladeMatterParserTest extends TestCase { public function testCanParseFrontMatter() diff --git a/tests/Feature/BlogPostDatePrefixHelperTest.php b/tests/Feature/BlogPostDatePrefixHelperTest.php index 9a3cd077..b9b47812 100644 --- a/tests/Feature/BlogPostDatePrefixHelperTest.php +++ b/tests/Feature/BlogPostDatePrefixHelperTest.php @@ -12,12 +12,12 @@ /** * High level test for the feature that allows dates to be set using prefixes in blog post filenames. * - * @covers \Hyde\Framework\Features\Blogging\BlogPostDatePrefixHelper - * @covers \Hyde\Framework\Factories\BlogPostDataFactory - * @covers \Hyde\Support\Models\RouteKey * * @see \Hyde\Framework\Testing\Unit\BlogPostDatePrefixHelperUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Blogging\BlogPostDatePrefixHelper::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\BlogPostDataFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Models\RouteKey::class)] class BlogPostDatePrefixHelperTest extends TestCase { public function testCanDetectDatePrefix() diff --git a/tests/Feature/CommandTest.php b/tests/Feature/CommandTest.php index 5af52879..779530ca 100644 --- a/tests/Feature/CommandTest.php +++ b/tests/Feature/CommandTest.php @@ -12,9 +12,7 @@ use RuntimeException; use Symfony\Component\Console\Style\OutputStyle; -/** - * @covers \Hyde\Console\Concerns\Command - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Concerns\Command::class)] class CommandTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Feature/Commands/BuildRssFeedCommandTest.php b/tests/Feature/Commands/BuildRssFeedCommandTest.php index f7374f7b..56b891b4 100644 --- a/tests/Feature/Commands/BuildRssFeedCommandTest.php +++ b/tests/Feature/Commands/BuildRssFeedCommandTest.php @@ -8,10 +8,8 @@ use Hyde\Hyde; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Console\Commands\BuildRssFeedCommand - * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\BuildRssFeedCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed::class)] class BuildRssFeedCommandTest extends TestCase { public function testRssFeedIsGeneratedWhenConditionsAreMet() diff --git a/tests/Feature/Commands/BuildSearchCommandTest.php b/tests/Feature/Commands/BuildSearchCommandTest.php index d345354f..12ff89f9 100644 --- a/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/tests/Feature/Commands/BuildSearchCommandTest.php @@ -11,11 +11,9 @@ use Hyde\Testing\TestCase; use Hyde\Framework\Features\Documentation\DocumentationSearchIndex; -/** - * @covers \Hyde\Console\Commands\BuildSearchCommand - * @covers \Hyde\Framework\Features\Documentation\DocumentationSearchPage - * @covers \Hyde\Framework\Features\Documentation\DocumentationSearchIndex - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\BuildSearchCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Documentation\DocumentationSearchPage::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Documentation\DocumentationSearchIndex::class)] class BuildSearchCommandTest extends TestCase { public function testItCreatesTheSearchJsonFile() diff --git a/tests/Feature/Commands/BuildSitemapCommandTest.php b/tests/Feature/Commands/BuildSitemapCommandTest.php index ab66436b..193517fc 100644 --- a/tests/Feature/Commands/BuildSitemapCommandTest.php +++ b/tests/Feature/Commands/BuildSitemapCommandTest.php @@ -7,10 +7,8 @@ use Hyde\Hyde; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Console\Commands\BuildSitemapCommand - * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\BuildSitemapCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap::class)] class BuildSitemapCommandTest extends TestCase { public function testSitemapIsGeneratedWhenConditionsAreMet() diff --git a/tests/Feature/Commands/CacheClearCommandTest.php b/tests/Feature/Commands/CacheClearCommandTest.php index 318beef1..acfe289f 100644 --- a/tests/Feature/Commands/CacheClearCommandTest.php +++ b/tests/Feature/Commands/CacheClearCommandTest.php @@ -7,9 +7,7 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Facades\Cache; -/** - * @coversNothing - */ +#[\PHPUnit\Framework\Attributes\CoversNothing] class CacheClearCommandTest extends TestCase { public function testCacheClearCommand() diff --git a/tests/Feature/Commands/ChangeSourceDirectoryCommandTest.php b/tests/Feature/Commands/ChangeSourceDirectoryCommandTest.php index 5a0fc3ce..16c98a35 100644 --- a/tests/Feature/Commands/ChangeSourceDirectoryCommandTest.php +++ b/tests/Feature/Commands/ChangeSourceDirectoryCommandTest.php @@ -8,9 +8,7 @@ use Hyde\Hyde; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Console\Commands\ChangeSourceDirectoryCommand - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\ChangeSourceDirectoryCommand::class)] class ChangeSourceDirectoryCommandTest extends TestCase { public function testCommandMovesSourceDirectoriesToNewSuppliedDirectoryAndUpdatesTheConfigurationFile() diff --git a/tests/Feature/Commands/DebugCommandTest.php b/tests/Feature/Commands/DebugCommandTest.php index 2023de84..c69fe4fc 100644 --- a/tests/Feature/Commands/DebugCommandTest.php +++ b/tests/Feature/Commands/DebugCommandTest.php @@ -10,9 +10,7 @@ use Illuminate\Console\OutputStyle; use Hyde\Console\Commands\DebugCommand; -/** - * @covers \Hyde\Console\Commands\DebugCommand - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\DebugCommand::class)] class DebugCommandTest extends TestCase { public function testDebugCommandCanRun() diff --git a/tests/Feature/Commands/MakePageCommandTest.php b/tests/Feature/Commands/MakePageCommandTest.php index 84fe56be..a08096c3 100644 --- a/tests/Feature/Commands/MakePageCommandTest.php +++ b/tests/Feature/Commands/MakePageCommandTest.php @@ -10,10 +10,8 @@ use Hyde\Hyde; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Console\Commands\MakePageCommand - * @covers \Hyde\Framework\Actions\CreatesNewPageSourceFile - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\MakePageCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\CreatesNewPageSourceFile::class)] class MakePageCommandTest extends TestCase { protected string $markdownPath; @@ -116,7 +114,7 @@ public function testCommandOverwritesExistingFilesWhenForceOptionIsUsed() $this->artisan('make:page "foo test page" --force')->assertExitCode(0); - $this->assertNotEquals('This should be overwritten', file_get_contents($this->markdownPath)); + $this->assertNotSame('This should be overwritten', file_get_contents($this->markdownPath)); } public function testCommandPromptsForTitleIfItWasNotSpecified() diff --git a/tests/Feature/Commands/MakePostCommandTest.php b/tests/Feature/Commands/MakePostCommandTest.php index 2967ab31..9e761a48 100644 --- a/tests/Feature/Commands/MakePostCommandTest.php +++ b/tests/Feature/Commands/MakePostCommandTest.php @@ -8,10 +8,8 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Carbon; -/** - * @covers \Hyde\Console\Commands\MakePostCommand - * @covers \Hyde\Framework\Actions\CreatesNewMarkdownPostFile - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\MakePostCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\CreatesNewMarkdownPostFile::class)] class MakePostCommandTest extends TestCase { public function testCommandHasExpectedOutputAndCreatesValidFile() diff --git a/tests/Feature/Commands/PackageDiscoverCommandTest.php b/tests/Feature/Commands/PackageDiscoverCommandTest.php index 28fdcd11..55dcfad8 100644 --- a/tests/Feature/Commands/PackageDiscoverCommandTest.php +++ b/tests/Feature/Commands/PackageDiscoverCommandTest.php @@ -8,9 +8,7 @@ use Hyde\Testing\TestCase; use Illuminate\Foundation\PackageManifest; -/** - * @covers \Hyde\Console\Commands\PackageDiscoverCommand - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\PackageDiscoverCommand::class)] class PackageDiscoverCommandTest extends TestCase { public function testPackageDiscoverCommandRegistersManifestPath() diff --git a/tests/Feature/Commands/PublishConfigsCommandTest.php b/tests/Feature/Commands/PublishConfigsCommandTest.php index e2b32d65..3a9efbca 100644 --- a/tests/Feature/Commands/PublishConfigsCommandTest.php +++ b/tests/Feature/Commands/PublishConfigsCommandTest.php @@ -9,9 +9,7 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; -/** - * @covers \Hyde\Console\Commands\PublishConfigsCommand - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\PublishConfigsCommand::class)] class PublishConfigsCommandTest extends TestCase { public function setUp(): void @@ -60,7 +58,7 @@ public function testCommandOverwritesExistingFiles() ->expectsChoice('Which configuration files do you want to publish?', 'All configs', $this->expectedOptions()) ->assertExitCode(0); - $this->assertNotEquals('foo', File::get(Hyde::path('config/hyde.php'))); + $this->assertNotSame('foo', File::get(Hyde::path('config/hyde.php'))); } protected function expectedOptions(): array diff --git a/tests/Feature/Commands/PublishHomepageCommandTest.php b/tests/Feature/Commands/PublishHomepageCommandTest.php index f04a0632..e5fad845 100644 --- a/tests/Feature/Commands/PublishHomepageCommandTest.php +++ b/tests/Feature/Commands/PublishHomepageCommandTest.php @@ -8,10 +8,8 @@ use Hyde\Hyde; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Console\Commands\PublishHomepageCommand - * @covers \Hyde\Console\Concerns\AsksToRebuildSite - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\PublishHomepageCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Concerns\AsksToRebuildSite::class)] class PublishHomepageCommandTest extends TestCase { protected function setUp(): void @@ -109,7 +107,7 @@ public function testCommandOverwritesModifiedFilesIfForceFlagIsSet() $this->artisan('publish:homepage welcome --force --no-interaction') ->assertExitCode(0); - $this->assertNotEquals('foo', file_get_contents(Hyde::path('_pages/index.blade.php'))); + $this->assertNotSame('foo', file_get_contents(Hyde::path('_pages/index.blade.php'))); $this->assertFileExists(Hyde::path('_pages/index.blade.php')); } diff --git a/tests/Feature/Commands/PublishViewsCommandTest.php b/tests/Feature/Commands/PublishViewsCommandTest.php index ed6ed3b6..7ba3109f 100644 --- a/tests/Feature/Commands/PublishViewsCommandTest.php +++ b/tests/Feature/Commands/PublishViewsCommandTest.php @@ -17,11 +17,10 @@ use Symfony\Component\Console\Output\BufferedOutput; /** - * @covers \Hyde\Console\Commands\PublishViewsCommand - * @covers \Hyde\Console\Helpers\InteractivePublishCommandHelper - * * @see \Hyde\Framework\Testing\Unit\InteractivePublishCommandHelperTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\PublishViewsCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Helpers\InteractivePublishCommandHelper::class)] class PublishViewsCommandTest extends TestCase { public function testCommandPublishesViews() diff --git a/tests/Feature/Commands/RebuildPageCommandTest.php b/tests/Feature/Commands/RebuildPageCommandTest.php index 998b14e8..fbe8a839 100644 --- a/tests/Feature/Commands/RebuildPageCommandTest.php +++ b/tests/Feature/Commands/RebuildPageCommandTest.php @@ -7,9 +7,7 @@ use Hyde\Hyde; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Console\Commands\RebuildPageCommand - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\RebuildPageCommand::class)] class RebuildPageCommandTest extends TestCase { public function testHandleIsSuccessfulWithValidPath() diff --git a/tests/Feature/Commands/RouteListCommandTest.php b/tests/Feature/Commands/RouteListCommandTest.php index b715501c..24407478 100644 --- a/tests/Feature/Commands/RouteListCommandTest.php +++ b/tests/Feature/Commands/RouteListCommandTest.php @@ -10,11 +10,10 @@ use Hyde\Support\Models\Route; /** - * @covers \Hyde\Console\Commands\RouteListCommand - * @covers \Hyde\Support\Internal\RouteListItem - * * @see \Hyde\Framework\Testing\Feature\RouteListTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\RouteListCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Internal\RouteListItem::class)] class RouteListCommandTest extends TestCase { public function testRouteListCommand() diff --git a/tests/Feature/Commands/ServeCommandTest.php b/tests/Feature/Commands/ServeCommandTest.php index 858d35f4..c2c38794 100644 --- a/tests/Feature/Commands/ServeCommandTest.php +++ b/tests/Feature/Commands/ServeCommandTest.php @@ -12,10 +12,9 @@ use TypeError; /** - * @covers \Hyde\Console\Commands\ServeCommand - * * @see \Hyde\Framework\Testing\Unit\ServeCommandOptionsUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\RealtimeCompiler\Console\Commands\ServeCommand::class)] class ServeCommandTest extends TestCase { protected function setUp(): void @@ -184,6 +183,8 @@ public function testHydeServeCommandWithViteOption() { $this->cleanUpWhenDone('app/storage/framework/runtime/vite.hot'); + $this->ensureNodeEnvironmentForTest(); + $mockViteProcess = mock(InvokedProcess::class); $mockViteProcess->shouldReceive('running') ->once() @@ -227,13 +228,15 @@ public function testHydeServeCommandWithViteOption() ->expectsOutput('vite latest output') ->assertExitCode(0); - $this->assertFileExists('app/storage/framework/runtime/vite.hot'); + $this->assertFileDoesNotExist('app/storage/framework/runtime/vite.hot'); } public function testHydeServeCommandWithViteOptionButViteNotRunning() { $this->cleanUpWhenDone('app/storage/framework/runtime/vite.hot'); + $this->ensureNodeEnvironmentForTest(); + $mockViteProcess = mock(InvokedProcess::class); $mockViteProcess->shouldReceive('running') ->once() @@ -270,18 +273,227 @@ public function testHydeServeCommandWithViteOptionButViteNotRunning() ->expectsOutput('Starting the HydeRC server... Use Ctrl+C to stop') ->assertExitCode(0); - $this->assertFileExists('app/storage/framework/runtime/vite.hot'); + $this->assertFileDoesNotExist('app/storage/framework/runtime/vite.hot'); } public function testHydeServeCommandWithViteOptionThrowsWhenPortIsInUse() { - $socket = stream_socket_server('tcp://127.0.0.1:5173'); + $socket = stream_socket_server('tcp://127.0.0.1:5173', $errno, $errstr); + + if ($socket === false) { + $this->markTestSkipped("Unable to create test socket server: $errstr (errno: $errno)"); + } + + try { + $this->artisan('serve --vite') + ->expectsOutputToContain('Unable to start Vite server: Port 5173 is already in use') + ->assertExitCode(1); + } finally { + stream_socket_shutdown($socket, STREAM_SHUT_RDWR); + } + } + + public function testHydeServeCommandWithViteOptionButNodeModulesNotInstalled() + { + $nodeModulesExists = file_exists(Hyde::path('node_modules')); + if ($nodeModulesExists) { + rename(Hyde::path('node_modules'), Hyde::path('node_modules.backup')); + } + + $packageJsonExists = file_exists(Hyde::path('package.json')); + if (! $packageJsonExists) { + file_put_contents(Hyde::path('package.json'), '{}'); + $this->cleanUpWhenDone('package.json'); + } + + try { + $this->artisan('serve --vite --no-interaction') + ->expectsOutputToContain('Node modules are not installed') + ->assertExitCode(1); + } finally { + if ($nodeModulesExists) { + rename(Hyde::path('node_modules.backup'), Hyde::path('node_modules')); + } + } + } + + public function testHydeServeCommandWithViteOptionButPackageJsonMissing() + { + $packageJsonExists = file_exists(Hyde::path('package.json')); + if ($packageJsonExists) { + rename(Hyde::path('package.json'), Hyde::path('package.json.backup')); + } + + try { + $this->artisan('serve --vite --no-interaction') + ->expectsOutputToContain('Node modules are not installed') + ->assertExitCode(1); + } finally { + if ($packageJsonExists) { + rename(Hyde::path('package.json.backup'), Hyde::path('package.json')); + } + } + } + + public function testHydeServeCommandWithViteOptionWithInteractiveConfirmationAccepted() + { + $nodeModulesExists = file_exists(Hyde::path('node_modules')); + if ($nodeModulesExists) { + rename(Hyde::path('node_modules'), Hyde::path('node_modules.backup')); + } + + $packageJsonExists = file_exists(Hyde::path('package.json')); + if (! $packageJsonExists) { + file_put_contents(Hyde::path('package.json'), '{}'); + $this->cleanUpWhenDone('package.json'); + } + + Process::fake([ + 'npm install' => function () { + if (! file_exists(Hyde::path('node_modules'))) { + mkdir(Hyde::path('node_modules')); + } + + return Process::result('', '', 0); + }, + ]); + + try { + $this->artisan('serve --vite --no-interaction') + ->expectsOutputToContain('Node modules are not installed') + ->assertExitCode(1); + } finally { + // Restore node_modules if it existed + if ($nodeModulesExists) { + if (file_exists(Hyde::path('node_modules'))) { + $this->recursiveRemoveDirectory(Hyde::path('node_modules')); + } + rename(Hyde::path('node_modules.backup'), Hyde::path('node_modules')); + } else { + if (file_exists(Hyde::path('node_modules'))) { + $this->recursiveRemoveDirectory(Hyde::path('node_modules')); + } + } + } + } + + public function testHydeServeCommandWithViteOptionWithInteractiveConfirmationDeclined() + { + $nodeModulesExists = file_exists(Hyde::path('node_modules')); + if ($nodeModulesExists) { + rename(Hyde::path('node_modules'), Hyde::path('node_modules.backup')); + } + + $packageJsonExists = file_exists(Hyde::path('package.json')); + if (! $packageJsonExists) { + file_put_contents(Hyde::path('package.json'), '{}'); + $this->cleanUpWhenDone('package.json'); + } + + try { + $this->artisan('serve --vite') + ->expectsQuestion('Would you like to install them now?', false) + ->expectsOutputToContain('The --vite flag cannot be used if Vite is not installed') + ->assertExitCode(1); + } finally { + if ($nodeModulesExists) { + rename(Hyde::path('node_modules.backup'), Hyde::path('node_modules')); + } + } + } + + public function testHydeServeCommandWithViteOptionWhenNpmInstallFails() + { + $nodeModulesExists = file_exists(Hyde::path('node_modules')); + if ($nodeModulesExists) { + rename(Hyde::path('node_modules'), Hyde::path('node_modules.backup')); + } + + $packageJsonExists = file_exists(Hyde::path('package.json')); + if (! $packageJsonExists) { + file_put_contents(Hyde::path('package.json'), '{}'); + $this->cleanUpWhenDone('package.json'); + } + + Process::fake([ + 'npm install' => Process::result('', 'npm install failed', 1), + ]); + + try { + $this->artisan('serve --vite') + ->expectsQuestion('Would you like to install them now?', true) + ->expectsOutput('Installing Node modules...') + ->assertExitCode(1); + + Process::assertRan('npm install'); + } finally { + if ($nodeModulesExists) { + rename(Hyde::path('node_modules.backup'), Hyde::path('node_modules')); + } + } + } + + public function testHydeServeCommandWithViteOptionWhenNpmInstallSucceedsButNodeModulesStillNotAvailable() + { + $nodeModulesExists = file_exists(Hyde::path('node_modules')); + if ($nodeModulesExists) { + rename(Hyde::path('node_modules'), Hyde::path('node_modules.backup')); + } + + $packageJsonExists = file_exists(Hyde::path('package.json')); + if (! $packageJsonExists) { + file_put_contents(Hyde::path('package.json'), '{}'); + $this->cleanUpWhenDone('package.json'); + } + + Process::fake([ + 'npm install' => Process::result('', '', 0), + ]); + + try { + $this->artisan('serve --vite') + ->expectsQuestion('Would you like to install them now?', true) + ->expectsOutput('Installing Node modules...') + ->expectsOutput('Node modules installed successfully.') + ->expectsOutputToContain('Node modules installation completed but dependencies are still not available') + ->assertExitCode(1); + + Process::assertRan('npm install'); + } finally { + if ($nodeModulesExists) { + rename(Hyde::path('node_modules.backup'), Hyde::path('node_modules')); + } + } + } - $this->artisan('serve --vite') - ->expectsOutputToContain('Unable to start Vite server: Port 5173 is already in use') - ->assertExitCode(1); + protected function ensureNodeEnvironmentForTest(): void + { + if (! file_exists(Hyde::path('package.json'))) { + file_put_contents(Hyde::path('package.json'), '{}'); + $this->cleanUpWhenDone('package.json'); + } + + if (! file_exists(Hyde::path('node_modules'))) { + mkdir(Hyde::path('node_modules')); + $this->cleanUpWhenDone('node_modules'); + } + } - stream_socket_shutdown($socket, STREAM_SHUT_RDWR); + protected function recursiveRemoveDirectory(string $dir): void + { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object !== '.' && $object !== '..') { + if (is_dir($dir.'/'.$object)) { + $this->recursiveRemoveDirectory($dir.'/'.$object); + } else { + unlink($dir.'/'.$object); + } + } + } + rmdir($dir); + } } protected function binaryPath(): string diff --git a/tests/Feature/Commands/ValidateCommandTest.php b/tests/Feature/Commands/ValidateCommandTest.php index 523f83a3..da95e6e6 100644 --- a/tests/Feature/Commands/ValidateCommandTest.php +++ b/tests/Feature/Commands/ValidateCommandTest.php @@ -7,12 +7,11 @@ use Hyde\Testing\TestCase; /** - * @covers \Hyde\Console\Commands\ValidateCommand - * @covers \Hyde\Framework\Services\ValidationService - * @covers \Hyde\Support\Models\ValidationResult - * * @see \Hyde\Framework\Testing\Feature\Services\ValidationServiceTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\ValidateCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Services\ValidationService::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Models\ValidationResult::class)] class ValidateCommandTest extends TestCase { public function testValidateCommandCanRun() diff --git a/tests/Feature/Commands/VendorPublishCommandTest.php b/tests/Feature/Commands/VendorPublishCommandTest.php index dfeab8cc..ff9f3e1d 100644 --- a/tests/Feature/Commands/VendorPublishCommandTest.php +++ b/tests/Feature/Commands/VendorPublishCommandTest.php @@ -12,9 +12,7 @@ use Illuminate\Support\ServiceProvider; use NunoMaduro\LaravelConsoleSummary\LaravelConsoleSummaryServiceProvider; -/** - * @covers \Hyde\Console\Commands\VendorPublishCommand - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\VendorPublishCommand::class)] class VendorPublishCommandTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/ConfigurableFeaturesTest.php b/tests/Feature/ConfigurableFeaturesTest.php index 2d45caa9..fb04fe0a 100644 --- a/tests/Feature/ConfigurableFeaturesTest.php +++ b/tests/Feature/ConfigurableFeaturesTest.php @@ -12,9 +12,7 @@ use function config; -/** - * @covers \Hyde\Facades\Features - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Features::class)] class ConfigurableFeaturesTest extends TestCase { public function testHasDocumentationSearchReturnsFalseWhenFeatureIsNotEnabled() diff --git a/tests/Feature/ConfigurableSourceRootsFeatureTest.php b/tests/Feature/ConfigurableSourceRootsFeatureTest.php index 0e86d7b8..1531e2b6 100644 --- a/tests/Feature/ConfigurableSourceRootsFeatureTest.php +++ b/tests/Feature/ConfigurableSourceRootsFeatureTest.php @@ -20,6 +20,33 @@ */ class ConfigurableSourceRootsFeatureTest extends TestCase { + protected function setUp(): void + { + parent::setUp(); + + // Clean up any existing test directories + $this->cleanupTestDirectories(); + } + + protected function tearDown(): void + { + // Clean up test directories after each test + $this->cleanupTestDirectories(); + + parent::tearDown(); + } + + protected function cleanupTestDirectories(): void + { + if (is_dir(Hyde::path('custom'))) { + File::deleteDirectory(Hyde::path('custom')); + } + + if (is_dir(Hyde::path('_site'))) { + File::deleteDirectory(Hyde::path('_site')); + } + } + public function testDefaultConfigValueIsEmptyString() { $this->assertSame('', config('hyde.source_root')); @@ -31,8 +58,6 @@ public function testFilesInCustomSourceRootCanBeDiscovered() $this->assertCount(1, MarkdownPage::files()); $this->assertCount(1, MarkdownPage::all()); - - File::deleteDirectory(Hyde::path('custom')); } public function testFilesInCustomSourceRootCanBeCompiled() @@ -42,9 +67,6 @@ public function testFilesInCustomSourceRootCanBeCompiled() $this->artisan('build'); $this->assertFileExists(Hyde::path('_site/markdown.html')); - - File::deleteDirectory(Hyde::path('custom')); - File::deleteDirectory(Hyde::path('_site')); } public function testHydePagePathMethodSupportsCustomSourceRoots() @@ -59,8 +81,13 @@ public function testHydePagePathMethodSupportsCustomSourceRoots() protected function setupCustomSourceRoot(): void { - mkdir(Hyde::path('custom')); - mkdir(Hyde::path('custom/_pages')); + // Ensure directories exist without throwing error if they already exist + if (! is_dir(Hyde::path('custom'))) { + mkdir(Hyde::path('custom')); + } + if (! is_dir(Hyde::path('custom/_pages'))) { + mkdir(Hyde::path('custom/_pages')); + } config(['hyde.source_root' => 'custom']); (new HydeServiceProvider(app()))->register(); diff --git a/tests/Feature/ConsoleKernelTest.php b/tests/Feature/ConsoleKernelTest.php index 38d1688d..d00b345f 100644 --- a/tests/Feature/ConsoleKernelTest.php +++ b/tests/Feature/ConsoleKernelTest.php @@ -14,12 +14,11 @@ /** * This test covers our custom console kernel, which is responsible for registering our custom bootstrappers. * - * @covers \Hyde\Foundation\ConsoleKernel - * * Our custom bootstrapping system depends on code from Laravel Zero which is marked as internal. * Sadly, there is no way around working with this private API. Since they may change the API * at any time, we have tests here to detect if their code changes, so we can catch it early. */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\ConsoleKernel::class)] class ConsoleKernelTest extends TestCase { public function testIsInstantiable() diff --git a/tests/Feature/ConvertsArrayToFrontMatterTest.php b/tests/Feature/ConvertsArrayToFrontMatterTest.php index 3eda88a7..dc8d48ca 100644 --- a/tests/Feature/ConvertsArrayToFrontMatterTest.php +++ b/tests/Feature/ConvertsArrayToFrontMatterTest.php @@ -7,9 +7,7 @@ use Hyde\Framework\Actions\ConvertsArrayToFrontMatter; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Framework\Actions\ConvertsArrayToFrontMatter - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\ConvertsArrayToFrontMatter::class)] class ConvertsArrayToFrontMatterTest extends TestCase { public function testActionConvertsAnArrayToFrontMatter() diff --git a/tests/Feature/DarkmodeFeatureTest.php b/tests/Feature/DarkmodeFeatureTest.php index 8bb9efd8..14883c6b 100644 --- a/tests/Feature/DarkmodeFeatureTest.php +++ b/tests/Feature/DarkmodeFeatureTest.php @@ -11,9 +11,7 @@ use Illuminate\Support\Facades\Config; use Hyde\Framework\Features\Navigation\MainNavigationMenu; -/** - * @covers \Hyde\Facades\Features::hasDarkmode - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Features::class)] class DarkmodeFeatureTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/DataCollectionTest.php b/tests/Feature/DataCollectionTest.php index 7577da7d..badce421 100644 --- a/tests/Feature/DataCollectionTest.php +++ b/tests/Feature/DataCollectionTest.php @@ -10,10 +10,9 @@ use Hyde\Testing\TestCase; /** - * @covers \Hyde\Support\DataCollection - * * @see \Hyde\Framework\Testing\Unit\DataCollectionUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\DataCollection::class)] class DataCollectionTest extends TestCase { public function testMarkdownCollections() diff --git a/tests/Feature/DiscoveryServiceTest.php b/tests/Feature/DiscoveryServiceTest.php index 1cb508ac..814bc0a4 100644 --- a/tests/Feature/DiscoveryServiceTest.php +++ b/tests/Feature/DiscoveryServiceTest.php @@ -32,7 +32,7 @@ protected function tearDown(): void if (is_dir($file)) { Filesystem::deleteDirectory($file); } else { - @unlink($file); + Filesystem::unlinkIfExists($file); } } $this->filesToDelete = []; @@ -47,7 +47,9 @@ protected function file(string $path): void protected function directory(string $path, bool $recursive = false): void { $this->filesToDelete[] = Hyde::path($path); - @mkdir(Hyde::path($path), recursive: $recursive); + if (! is_dir(Hyde::path($path))) { + mkdir(Hyde::path($path), recursive: $recursive); + } } public function testGetSourceFileListForModelMethodFindsDefaultModelProperties() diff --git a/tests/Feature/DocumentationPageTest.php b/tests/Feature/DocumentationPageTest.php index 17119c2f..b0390217 100644 --- a/tests/Feature/DocumentationPageTest.php +++ b/tests/Feature/DocumentationPageTest.php @@ -15,11 +15,9 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\File; -/** - * @covers \Hyde\Pages\DocumentationPage - * @covers \Hyde\Framework\Factories\Concerns\HasFactory - * @covers \Hyde\Framework\Factories\NavigationDataFactory - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\DocumentationPage::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\Concerns\HasFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\NavigationDataFactory::class)] class DocumentationPageTest extends TestCase { public function testCanGetCurrentPagePath() diff --git a/tests/Feature/DocumentationSearchIndexTest.php b/tests/Feature/DocumentationSearchIndexTest.php index 7cc9b893..ece094cb 100644 --- a/tests/Feature/DocumentationSearchIndexTest.php +++ b/tests/Feature/DocumentationSearchIndexTest.php @@ -9,10 +9,9 @@ use Hyde\Framework\Features\Documentation\DocumentationSearchIndex; /** - * @covers \Hyde\Framework\Features\Documentation\DocumentationSearchIndex - * * @see \Hyde\Framework\Testing\Feature\Commands\BuildSearchCommandTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Documentation\DocumentationSearchIndex::class)] class DocumentationSearchIndexTest extends TestCase { public function testCanCreateDocumentationSearchIndexInstance() diff --git a/tests/Feature/DocumentationSearchPageTest.php b/tests/Feature/DocumentationSearchPageTest.php index 97badc9d..5ea4c83e 100644 --- a/tests/Feature/DocumentationSearchPageTest.php +++ b/tests/Feature/DocumentationSearchPageTest.php @@ -11,10 +11,9 @@ use Hyde\Testing\TestCase; /** - * @covers \Hyde\Framework\Features\Documentation\DocumentationSearchPage - * * @see \Hyde\Framework\Testing\Feature\Commands\BuildSearchCommandTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Documentation\DocumentationSearchPage::class)] class DocumentationSearchPageTest extends TestCase { public function testCanCreateDocumentationSearchPageInstance() diff --git a/tests/Feature/DynamicMarkdownLinksFeatureTest.php b/tests/Feature/DynamicMarkdownLinksFeatureTest.php index 458160b2..316be091 100644 --- a/tests/Feature/DynamicMarkdownLinksFeatureTest.php +++ b/tests/Feature/DynamicMarkdownLinksFeatureTest.php @@ -17,11 +17,10 @@ use Hyde\Markdown\Processing\DynamicMarkdownLinkProcessor; /** - * @covers \Hyde\Markdown\Processing\DynamicMarkdownLinkProcessor - * @covers \Hyde\Framework\Concerns\Internal\SetsUpMarkdownConverter - * * @see \Hyde\Framework\Testing\Feature\Services\Markdown\DynamicMarkdownLinkProcessorTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Processing\DynamicMarkdownLinkProcessor::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Concerns\Internal\SetsUpMarkdownConverter::class)] class DynamicMarkdownLinksFeatureTest extends TestCase { public static function setUpBeforeClass(): void diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index deca7e4f..ba7212c4 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -6,9 +6,7 @@ use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Hyde - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Hyde::class)] class ExampleTest extends TestCase { public function testExample() diff --git a/tests/Feature/FeaturedImageFactoryTest.php b/tests/Feature/FeaturedImageFactoryTest.php index fd3f7f1c..d0924ecc 100644 --- a/tests/Feature/FeaturedImageFactoryTest.php +++ b/tests/Feature/FeaturedImageFactoryTest.php @@ -11,9 +11,7 @@ use Hyde\Testing\TestCase; use RuntimeException; -/** - * @covers \Hyde\Framework\Factories\FeaturedImageFactory - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\FeaturedImageFactory::class)] class FeaturedImageFactoryTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/FeaturedImageTest.php b/tests/Feature/FeaturedImageTest.php index 929fe34e..3e61bd68 100644 --- a/tests/Feature/FeaturedImageTest.php +++ b/tests/Feature/FeaturedImageTest.php @@ -11,10 +11,9 @@ use Illuminate\Support\Facades\Http; /** - * @covers \Hyde\Framework\Features\Blogging\Models\FeaturedImage - * * @see \Hyde\Framework\Testing\Unit\FeaturedImageUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Blogging\Models\FeaturedImage::class)] class FeaturedImageTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/FileCollectionTest.php b/tests/Feature/FileCollectionTest.php index cb0d5ba8..9a31862e 100644 --- a/tests/Feature/FileCollectionTest.php +++ b/tests/Feature/FileCollectionTest.php @@ -16,11 +16,9 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Collection; -/** - * @covers \Hyde\Foundation\Kernel\FileCollection - * @covers \Hyde\Foundation\Concerns\BaseFoundationCollection - * @covers \Hyde\Foundation\Facades\Files - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\FileCollection::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Concerns\BaseFoundationCollection::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Facades\Files::class)] class FileCollectionTest extends TestCase { public function testBootMethodCreatesNewPageCollectionAndDiscoversPagesAutomatically() diff --git a/tests/Feature/FilesystemFacadeTest.php b/tests/Feature/FilesystemFacadeTest.php index 4b67f34b..bae6224a 100644 --- a/tests/Feature/FilesystemFacadeTest.php +++ b/tests/Feature/FilesystemFacadeTest.php @@ -9,13 +9,12 @@ use Hyde\Testing\TestCase; /** - * @covers \Hyde\Facades\Filesystem - * @covers \Hyde\Foundation\Kernel\Filesystem - * @covers \Hyde\Framework\Concerns\Internal\ForwardsIlluminateFilesystem - * * @see \FilesystemFacadeMimeTypeHelperUnitTest * @see \Hyde\Framework\Testing\Unit\FilesystemFacadeUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Filesystem::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\Filesystem::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Concerns\Internal\ForwardsIlluminateFilesystem::class)] class FilesystemFacadeTest extends TestCase { public function testBasePath() diff --git a/tests/Feature/Foundation/FilesystemTest.php b/tests/Feature/Foundation/FilesystemTest.php index 0e5e18d6..555156d4 100644 --- a/tests/Feature/Foundation/FilesystemTest.php +++ b/tests/Feature/Foundation/FilesystemTest.php @@ -21,12 +21,10 @@ use function Hyde\normalize_slashes; -/** - * @covers \Hyde\Foundation\HydeKernel - * @covers \Hyde\Foundation\Kernel\Filesystem - * @covers \Hyde\Foundation\Concerns\HasMediaFiles - * @covers \Hyde\Facades\Filesystem - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\HydeKernel::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\Filesystem::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Concerns\HasMediaFiles::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Filesystem::class)] class FilesystemTest extends UnitTestCase { use CreatesTemporaryFiles; diff --git a/tests/Feature/Foundation/HyperlinksTest.php b/tests/Feature/Foundation/HyperlinksTest.php index 2b72bf20..905393c1 100644 --- a/tests/Feature/Foundation/HyperlinksTest.php +++ b/tests/Feature/Foundation/HyperlinksTest.php @@ -12,9 +12,7 @@ use Hyde\Hyde; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Foundation\Kernel\Hyperlinks - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\Hyperlinks::class)] class HyperlinksTest extends TestCase { protected Hyperlinks $class; diff --git a/tests/Feature/GlobalMetadataBagTest.php b/tests/Feature/GlobalMetadataBagTest.php index c44378e2..40ec669c 100644 --- a/tests/Feature/GlobalMetadataBagTest.php +++ b/tests/Feature/GlobalMetadataBagTest.php @@ -10,9 +10,7 @@ use Hyde\Support\Facades\Render; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Framework\Features\Metadata\GlobalMetadataBag - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\GlobalMetadataBag::class)] class GlobalMetadataBagTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/HelpersTest.php b/tests/Feature/HelpersTest.php index 9efbfb65..a402391b 100644 --- a/tests/Feature/HelpersTest.php +++ b/tests/Feature/HelpersTest.php @@ -21,6 +21,24 @@ * * @see \Hyde\Framework\Testing\Unit\UnixsumTest for additional tests of the unixsum function */ +#[\PHPUnit\Framework\Attributes\CoversFunction('hyde')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\unslash')] +#[\PHPUnit\Framework\Attributes\CoversFunction('asset')] +#[\PHPUnit\Framework\Attributes\CoversFunction('route')] +#[\PHPUnit\Framework\Attributes\CoversFunction('url')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\hyde')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\unixsum')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\unixsum_file')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\make_title')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\title')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\normalize_newlines')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\strip_newlines')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\trim_slashes')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\evaluate_arrayable')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\yaml_encode')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\yaml_decode')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\path_join')] +#[\PHPUnit\Framework\Attributes\CoversFunction('\Hyde\normalize_slashes')] class HelpersTest extends TestCase { protected function setUp(): void @@ -30,31 +48,26 @@ protected function setUp(): void config(['hyde.cache_busting' => false]); } - /** @covers ::hyde */ public function testHydeFunctionExists() { $this->assertTrue(function_exists('hyde')); } - /** @covers ::hyde */ public function testHydeFunctionReturnsHydeKernelClass() { $this->assertInstanceOf(HydeKernel::class, hyde()); } - /** @covers ::hyde */ public function testCanCallMethodsOnReturnedHydeClass() { $this->assertSame(Hyde::path(), hyde()->path()); } - /** @covers ::\Hyde\unslash */ public function testUnslashFunctionExists() { $this->assertTrue(function_exists('Hyde\unslash')); } - /** @covers ::\Hyde\unslash */ public function testUnslashFunctionTrimsTrailingSlashes() { $tests = ['foo', '/foo', 'foo/', '/foo/', '\foo\\', '\\/foo/\\']; @@ -76,7 +89,6 @@ public function testUnslashFunctionTrimsTrailingSlashes() } } - /** @covers ::asset */ public function testAssetFunction() { $this->assertInstanceOf(MediaFile::class, asset('app.css')); @@ -86,7 +98,6 @@ public function testAssetFunction() $this->assertSame('media/app.css', (string) asset('app.css')); } - /** @covers ::asset */ public function testAssetFunctionWithCacheBusting() { config(['hyde.cache_busting' => true]); @@ -101,7 +112,6 @@ public function testAssetFunctionWithCacheBusting() ); } - /** @covers ::asset */ public function testAssetFunctionWithExternalUrl() { $this->expectException(FileNotFoundException::class); @@ -109,7 +119,6 @@ public function testAssetFunctionWithExternalUrl() $this->assertSame('https://example.com/foo', asset('https://example.com/foo')); } - /** @covers ::asset */ public function testAssetFunctionWithSetBaseUrl() { $this->assertInstanceOf(MediaFile::class, asset('app.css')); @@ -119,7 +128,6 @@ public function testAssetFunctionWithSetBaseUrl() $this->assertSame('https://example.com/media/app.css', (string) asset('app.css')); } - /** @covers ::asset */ public function testAssetFunctionWithNoBaseUrl() { $this->assertInstanceOf(MediaFile::class, asset('app.css')); @@ -129,7 +137,6 @@ public function testAssetFunctionWithNoBaseUrl() $this->assertSame('media/app.css', (string) asset('app.css')); } - /** @covers ::asset */ public function testAssetFunctionWithLocalhostBaseUrl() { $this->assertInstanceOf(MediaFile::class, asset('app.css')); @@ -139,7 +146,6 @@ public function testAssetFunctionWithLocalhostBaseUrl() $this->assertSame('media/app.css', (string) asset('app.css')); } - /** @covers ::asset */ public function testAssetFunctionFromNestedPage() { $this->assertInstanceOf(MediaFile::class, asset('app.css')); @@ -150,7 +156,6 @@ public function testAssetFunctionFromNestedPage() $this->assertSame('../media/app.css', (string) asset('app.css')); } - /** @covers ::asset */ public function testAssetFunctionFromDeeplyNestedPage() { $this->assertInstanceOf(MediaFile::class, asset('app.css')); @@ -161,7 +166,6 @@ public function testAssetFunctionFromDeeplyNestedPage() $this->assertSame('../../media/app.css', (string) asset('app.css')); } - /** @covers ::asset */ public function testAssetFunctionWithCustomMediaDirectory() { $this->file('custom/app.css'); @@ -173,14 +177,12 @@ public function testAssetFunctionWithCustomMediaDirectory() $this->assertSame('custom/app.css', (string) asset('app.css')); } - /** @covers ::route */ public function testRouteFunction() { $this->assertNotNull(Hyde::route('index')); $this->assertSame(Routes::get('index'), route('index')); } - /** @covers ::route */ public function testRouteFunctionWithInvalidRoute() { $this->expectException(\Hyde\Framework\Exceptions\RouteNotFoundException::class); @@ -188,34 +190,29 @@ public function testRouteFunctionWithInvalidRoute() route('invalid'); } - /** @covers ::url */ public function testUrlFunction() { $this->assertSame(Hyde::url('foo'), url('foo')); } - /** @covers ::url */ public function testUrlFunctionWithBaseUrl() { $this->app['config']->set(['hyde.url' => 'https://example.com']); $this->assertSame('https://example.com/foo', url('foo')); } - /** @covers ::url */ public function testUrlFunctionWithLocalhostBaseUrl() { $this->app['config']->set(['hyde.url' => 'http://localhost']); $this->assertSame('foo', url('foo')); } - /** @covers ::url */ public function testUrlFunctionWithoutBaseUrl() { $this->app['config']->set(['hyde.url' => null]); $this->assertSame('foo', url('foo')); } - /** @covers ::url */ public function testUrlFunctionWithoutBaseUrlOrPath() { $this->app['config']->set(['hyde.url' => null]); @@ -223,7 +220,6 @@ public function testUrlFunctionWithoutBaseUrlOrPath() $this->assertNull(url()); } - /** @covers ::url */ public function testUrlFunctionWithLocalhostBaseUrlButNoPath() { $this->app['config']->set(['hyde.url' => 'http://localhost']); @@ -231,14 +227,12 @@ public function testUrlFunctionWithLocalhostBaseUrlButNoPath() $this->assertNull(url()); } - /** @covers ::url */ public function testUrlFunctionWithAlreadyQualifiedUrl() { $this->assertSame('https://example.com/foo', url('https://example.com/foo')); $this->assertSame('http://localhost/foo', url('http://localhost/foo')); } - /** @covers ::url */ public function testUrlFunctionWithAlreadyQualifiedUrlWhenSiteUrlIsSet() { $this->app['config']->set(['hyde.url' => 'https://example.com']); @@ -247,7 +241,6 @@ public function testUrlFunctionWithAlreadyQualifiedUrlWhenSiteUrlIsSet() $this->assertSame('http://localhost/foo', url('http://localhost/foo')); } - /** @covers ::url */ public function testUrlFunctionWithAlreadyQualifiedUrlWhenSiteUrlIsSetToSomethingElse() { $this->app['config']->set(['hyde.url' => 'my-site.com']); @@ -256,38 +249,32 @@ public function testUrlFunctionWithAlreadyQualifiedUrlWhenSiteUrlIsSetToSomethin $this->assertSame('http://localhost/foo', url('http://localhost/foo')); } - /** @covers ::\Hyde\hyde */ public function testHydeFunctionExistsInHydeNamespace() { $this->assertTrue(function_exists('Hyde\hyde')); } - /** @covers ::\Hyde\hyde */ public function testNamespacedHydeFunction() { $this->assertSame(hyde(), \Hyde\hyde()); } - /** @covers ::\Hyde\unslash */ public function testUnslashFunctionExistsInHydeNamespace() { $this->assertTrue(function_exists('Hyde\unslash')); } - /** @covers ::\Hyde\unslash */ public function testNamespacedUnslashFunction() { $this->assertSame(\Hyde\unslash('foo'), \Hyde\unslash('foo')); } - /** @covers ::\Hyde\unixsum */ public function testUnixsumFunction() { $this->assertSame(md5("foo\n"), \Hyde\unixsum("foo\n")); $this->assertSame(md5("foo\n"), \Hyde\unixsum("foo\r\n")); } - /** @covers ::\Hyde\unixsum_file */ public function testUnixsumFileFunction() { $this->file('unix.txt', "foo\n"); @@ -297,50 +284,47 @@ public function testUnixsumFileFunction() $this->assertSame(md5("foo\n"), \Hyde\unixsum_file('windows.txt')); } - /** @covers ::\Hyde\make_title */ public function testHydeMakeTitleFunction() { $this->assertSame(Hyde::makeTitle('foo'), \Hyde\make_title('foo')); } - /** @covers ::\Hyde\normalize_newlines */ + public function testHydeTitleFunction() + { + $this->assertSame(Hyde::makeTitle('foo'), \Hyde\title('foo')); + } + public function testHydeNormalizeNewlinesFunction() { $this->assertSame(Hyde::normalizeNewlines('foo'), \Hyde\normalize_newlines('foo')); } - /** @covers ::\Hyde\strip_newlines */ public function testHydeStripNewlinesFunction() { $this->assertSame(Hyde::stripNewlines('foo'), \Hyde\strip_newlines('foo')); } - /** @covers ::\Hyde\trim_slashes */ public function testHydeTrimSlashesFunction() { $this->assertSame(Hyde::trimSlashes('foo'), \Hyde\trim_slashes('foo')); } - /** @covers ::\Hyde\evaluate_arrayable */ public function testHydeEvaluateArrayableFunction() { $this->assertSame(['foo'], \Hyde\evaluate_arrayable(['foo'])); $this->assertSame(['foo'], \Hyde\evaluate_arrayable(collect(['foo']))); } - /** @covers ::\Hyde\yaml_encode */ public function testHydeYamlEncodeFunction() { $this->assertSame("foo: bar\n", \Hyde\yaml_encode(['foo' => 'bar'])); } - /** @covers ::\Hyde\yaml_encode */ public function testHydeYamlEncodeFunctionEncodesArrayables() { $this->assertSame("foo: bar\n", \Hyde\yaml_encode(collect(['foo' => 'bar']))); } - /** @covers ::\Hyde\yaml_encode */ public function testHydeYamlEncodeFunctionAcceptsParameters() { $this->assertSame( @@ -349,13 +333,11 @@ public function testHydeYamlEncodeFunctionAcceptsParameters() ); } - /** @covers ::\Hyde\yaml_decode */ public function testHydeYamlDecodeFunction() { $this->assertSame(['foo' => 'bar'], \Hyde\yaml_decode("foo: bar\n")); } - /** @covers ::\Hyde\yaml_decode */ public function testHydeYamlDecodeFunctionAcceptsParameters() { $this->assertSame( @@ -364,19 +346,16 @@ public function testHydeYamlDecodeFunctionAcceptsParameters() ); } - /** @covers ::\Hyde\path_join */ public function testHydePathJoinFunction() { $this->assertSame('foo/bar', \Hyde\path_join('foo', 'bar')); } - /** @covers ::\Hyde\path_join */ public function testHydePathJoinFunctionWithMultiplePaths() { $this->assertSame('foo/bar/baz', \Hyde\path_join('foo', 'bar', 'baz')); } - /** @covers ::\Hyde\normalize_slashes */ public function testHydeNormalizeSlashesFunction() { $this->assertSame('foo/bar', \Hyde\normalize_slashes('foo\\bar')); diff --git a/tests/Feature/HighLevelYamlConfigurationFeatureTest.php b/tests/Feature/HighLevelYamlConfigurationFeatureTest.php index a31b7a29..71fd3684 100644 --- a/tests/Feature/HighLevelYamlConfigurationFeatureTest.php +++ b/tests/Feature/HighLevelYamlConfigurationFeatureTest.php @@ -10,11 +10,10 @@ * High level test for the Yaml configuration feature. * * @see \Hyde\Framework\Testing\Feature\YamlConfigurationFeatureTest - * - * @covers \Hyde\Foundation\Internal\LoadYamlConfiguration - * @covers \Hyde\Foundation\Internal\LoadYamlEnvironmentVariables - * @covers \Hyde\Foundation\Internal\YamlConfigurationRepository */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Internal\LoadYamlConfiguration::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Internal\LoadYamlEnvironmentVariables::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Internal\YamlConfigurationRepository::class)] class HighLevelYamlConfigurationFeatureTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/HomepageViewTest.php b/tests/Feature/HomepageViewTest.php index a7e48f25..a473e8f5 100644 --- a/tests/Feature/HomepageViewTest.php +++ b/tests/Feature/HomepageViewTest.php @@ -11,8 +11,9 @@ use Hyde\Testing\TestsBladeViews; /** - * @coversNothing Test to ensure all homepages can be rendered + * Test to ensure all homepages can be rendered. */ +#[\PHPUnit\Framework\Attributes\CoversNothing] class HomepageViewTest extends TestCase { use TestsBladeViews; diff --git a/tests/Feature/HydeCoreExtensionTest.php b/tests/Feature/HydeCoreExtensionTest.php index 4debb39d..ff818f5e 100644 --- a/tests/Feature/HydeCoreExtensionTest.php +++ b/tests/Feature/HydeCoreExtensionTest.php @@ -14,9 +14,7 @@ use Hyde\Pages\DocumentationPage; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Foundation\HydeCoreExtension - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\HydeCoreExtension::class)] class HydeCoreExtensionTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Feature/HydeExtensionFeatureTest.php b/tests/Feature/HydeExtensionFeatureTest.php index dc46d02c..d48aa5d2 100644 --- a/tests/Feature/HydeExtensionFeatureTest.php +++ b/tests/Feature/HydeExtensionFeatureTest.php @@ -23,15 +23,15 @@ /** * Tests the Extensions API Feature on a higher level to ensure the components work together. * - * @covers \Hyde\Foundation\Concerns\HydeExtension - * @covers \Hyde\Foundation\Concerns\ManagesExtensions - * @covers \Hyde\Foundation\HydeKernel - * @covers \Hyde\Foundation\Kernel\FileCollection - * @covers \Hyde\Foundation\Kernel\PageCollection - * @covers \Hyde\Foundation\Kernel\RouteCollection * * @see \Hyde\Framework\Testing\Unit\ExtensionsUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Concerns\HydeExtension::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Concerns\ManagesExtensions::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\HydeKernel::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\FileCollection::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\PageCollection::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\RouteCollection::class)] class HydeExtensionFeatureTest extends TestCase { protected HydeKernel $kernel; diff --git a/tests/Feature/HydeKernelTest.php b/tests/Feature/HydeKernelTest.php index c3344220..04b6f7e0 100644 --- a/tests/Feature/HydeKernelTest.php +++ b/tests/Feature/HydeKernelTest.php @@ -33,13 +33,13 @@ * This test class runs high-level tests on the HydeKernel class, * as most of the logic actually resides in linked service classes. * - * @covers \Hyde\Foundation\HydeKernel - * @covers \Hyde\Hyde * * @see \Hyde\Framework\Testing\Unit\HydeHelperFacadeMakeTitleTest * @see \Hyde\Framework\Testing\Unit\HydeHelperFacadeMakeSlugTest * @see \Hyde\Framework\Testing\Feature\HydeExtensionFeatureTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\HydeKernel::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Hyde::class)] class HydeKernelTest extends TestCase { public function testKernelSingletonCanBeAccessedByServiceContainer() diff --git a/tests/Feature/HydePageTest.php b/tests/Feature/HydePageTest.php index d9ca0150..9ca64d14 100644 --- a/tests/Feature/HydePageTest.php +++ b/tests/Feature/HydePageTest.php @@ -23,16 +23,15 @@ /** * Test the base HydePage class. - * - * @covers \Hyde\Pages\Concerns\HydePage - * @covers \Hyde\Pages\Concerns\BaseMarkdownPage - * @covers \Hyde\Framework\Factories\Concerns\HasFactory - * @covers \Hyde\Framework\Factories\NavigationDataFactory - * @covers \Hyde\Framework\Factories\FeaturedImageFactory - * @covers \Hyde\Framework\Factories\HydePageDataFactory - * @covers \Hyde\Framework\Factories\BlogPostDataFactory - * @covers \Hyde\Framework\Concerns\InteractsWithFrontMatter */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\Concerns\HydePage::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\Concerns\BaseMarkdownPage::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\Concerns\HasFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\NavigationDataFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\FeaturedImageFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\HydePageDataFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\BlogPostDataFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Concerns\InteractsWithFrontMatter::class)] class HydePageTest extends TestCase { // Section: Baseline tests (Abstract class) diff --git a/tests/Feature/HydeServiceProviderTest.php b/tests/Feature/HydeServiceProviderTest.php index e84448db..faad0cb0 100644 --- a/tests/Feature/HydeServiceProviderTest.php +++ b/tests/Feature/HydeServiceProviderTest.php @@ -21,13 +21,11 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Facades\Artisan; -/** - * @covers \Hyde\Framework\HydeServiceProvider - * @covers \Hyde\Framework\Concerns\RegistersFileLocations - * @covers \Hyde\Foundation\Providers\ConfigurationServiceProvider - * @covers \Hyde\Foundation\Providers\NavigationServiceProvider - * @covers \Hyde\Foundation\Providers\ViewServiceProvider - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\HydeServiceProvider::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Concerns\RegistersFileLocations::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Providers\ConfigurationServiceProvider::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Providers\NavigationServiceProvider::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Providers\ViewServiceProvider::class)] class HydeServiceProviderTest extends TestCase { protected HydeServiceProvider $provider; @@ -236,7 +234,7 @@ public function testProviderRegistersAllPageModelSourcePaths() $this->provider->register(); foreach ($pages as $page) { - $this->assertNotEquals('foo', $page::sourceDirectory(), "Source directory for $page was not set"); + $this->assertNotSame('foo', $page::sourceDirectory(), "Source directory for $page was not set"); } } @@ -252,7 +250,7 @@ public function testProviderRegistersAllPageModelOutputPaths() $this->provider->register(); foreach ($pages as $page) { - $this->assertNotEquals('foo', $page::outputDirectory(), "Output directory for $page was not set"); + $this->assertNotSame('foo', $page::outputDirectory(), "Output directory for $page was not set"); } } diff --git a/tests/Feature/IncludesFacadeTest.php b/tests/Feature/IncludesFacadeTest.php index 1b6229e5..e26752d3 100644 --- a/tests/Feature/IncludesFacadeTest.php +++ b/tests/Feature/IncludesFacadeTest.php @@ -12,10 +12,9 @@ use Illuminate\Support\Facades\Blade; /** - * @covers \Hyde\Support\Includes - * * @see \Hyde\Framework\Testing\Unit\IncludesFacadeUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Includes::class)] class IncludesFacadeTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/InternationalizationTest.php b/tests/Feature/InternationalizationTest.php index 450e342c..bca7d422 100644 --- a/tests/Feature/InternationalizationTest.php +++ b/tests/Feature/InternationalizationTest.php @@ -12,13 +12,12 @@ use Hyde\Testing\TestCase; /** - * @coversNothing High level test to ensure the internationalization features are working. + * High level test to ensure the internationalization features are working. */ +#[\PHPUnit\Framework\Attributes\CoversNothing] class InternationalizationTest extends TestCase { - /** - * @dataProvider internationalCharacterSetsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('internationalCharacterSetsProvider')] public function testCanCreateBlogPostFilesWithInternationalCharacterSets( string $title, string $description, @@ -60,9 +59,7 @@ public function testCanCreateBlogPostFilesWithInternationalCharacterSets( Filesystem::unlink($path); } - /** - * @dataProvider internationalCharacterSetsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('internationalCharacterSetsProvider')] public function testCanCompileBlogPostFilesWithInternationalCharacterSets( string $title, string $description, @@ -91,27 +88,25 @@ public function testCanCompileBlogPostFilesWithInternationalCharacterSets( Filesystem::unlink($path); } - public static function internationalCharacterSetsProvider(): array + public static function internationalCharacterSetsProvider(): \Iterator { - return [ - 'Chinese (Simplified)' => [ - '你好世界', - '简短描述', - 'ni-hao-shi-jie', - '你好世界', - ], - 'Japanese' => [ - 'こんにちは世界', - '短い説明', - 'konnichihashi-jie', - 'こんにちは世界', - ], - 'Korean' => [ - '안녕하세요 세계', - '짧은 설명', - 'annyeonghaseyo-segye', - '안녕하세요 세계', - ], + yield 'Chinese (Simplified)' => [ + '你好世界', + '简短描述', + 'ni-hao-shi-jie', + '你好世界', + ]; + yield 'Japanese' => [ + 'こんにちは世界', + '短い説明', + 'konnichihashi-jie', + 'こんにちは世界', + ]; + yield 'Korean' => [ + '안녕하세요 세계', + '짧은 설명', + 'annyeonghaseyo-segye', + '안녕하세요 세계', ]; } } diff --git a/tests/Feature/MarkdownHeadingRendererTest.php b/tests/Feature/MarkdownHeadingRendererTest.php index be3bb352..b086269d 100644 --- a/tests/Feature/MarkdownHeadingRendererTest.php +++ b/tests/Feature/MarkdownHeadingRendererTest.php @@ -10,10 +10,9 @@ use Hyde\Pages\MarkdownPage; /** - * @covers \Hyde\Markdown\Processing\HeadingRenderer - * * @see \Hyde\Framework\Testing\Unit\HeadingRendererUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Processing\HeadingRenderer::class)] class MarkdownHeadingRendererTest extends TestCase { public function testBasicHeadingRendering() diff --git a/tests/Feature/MarkdownPostTest.php b/tests/Feature/MarkdownPostTest.php index cc4109d8..4a509097 100644 --- a/tests/Feature/MarkdownPostTest.php +++ b/tests/Feature/MarkdownPostTest.php @@ -16,10 +16,8 @@ use Hyde\Support\Models\DateString; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Pages\MarkdownPost - * @covers \Hyde\Framework\Factories\Concerns\HasFactory - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\MarkdownPost::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\Concerns\HasFactory::class)] class MarkdownPostTest extends TestCase { public function testConstructorCanCreateANewAuthorInstanceFromUsernameString() @@ -192,6 +190,25 @@ public function testBlogPostFeedCanBeRenderedWhenPostHasNoFrontMatter() Filesystem::unlink('_site/feed-test.html'); } + public function testConstructorCanUseExcerptAsAliasForDescription() + { + $post = new MarkdownPost(matter: FrontMatter::fromArray([ + 'excerpt' => 'This is the excerpt content', + ])); + + $this->assertSame('This is the excerpt content', $post->description); + } + + public function testConstructorPrioritizesDescriptionOverExcerptWhenBothAreSet() + { + $post = new MarkdownPost(matter: FrontMatter::fromArray([ + 'description' => 'This is the description', + 'excerpt' => 'This is the excerpt', + ])); + + $this->assertSame('This is the description', $post->description); + } + protected function setupMediaFileAndCacheBusting(bool $enableCacheBusting = false): void { $this->file('_media/foo.png', 'test content'); diff --git a/tests/Feature/MarkdownServiceTest.php b/tests/Feature/MarkdownServiceTest.php index de4faab2..a20bd32b 100644 --- a/tests/Feature/MarkdownServiceTest.php +++ b/tests/Feature/MarkdownServiceTest.php @@ -10,10 +10,8 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Facades\Config; -/** - * @covers \Hyde\Framework\Services\MarkdownService - * @covers \Hyde\Framework\Concerns\Internal\SetsUpMarkdownConverter - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Services\MarkdownService::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Concerns\Internal\SetsUpMarkdownConverter::class)] class MarkdownServiceTest extends TestCase { public function testServiceCanParseMarkdownToHtml() diff --git a/tests/Feature/MetadataTest.php b/tests/Feature/MetadataTest.php index e1220f8f..3cd140d4 100644 --- a/tests/Feature/MetadataTest.php +++ b/tests/Feature/MetadataTest.php @@ -17,14 +17,12 @@ use Hyde\Pages\MarkdownPost; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Framework\Features\Metadata\MetadataBag - * @covers \Hyde\Framework\Features\Metadata\PageMetadataBag - * @covers \Hyde\Framework\Features\Metadata\GlobalMetadataBag - * @covers \Hyde\Framework\Features\Metadata\Elements\LinkElement - * @covers \Hyde\Framework\Features\Metadata\Elements\MetadataElement - * @covers \Hyde\Framework\Features\Metadata\Elements\OpenGraphElement - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\MetadataBag::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\PageMetadataBag::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\GlobalMetadataBag::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\Elements\LinkElement::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\Elements\MetadataElement::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\Elements\OpenGraphElement::class)] class MetadataTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/NavigationAPITest.php b/tests/Feature/NavigationAPITest.php index 22b5257c..0487c04a 100644 --- a/tests/Feature/NavigationAPITest.php +++ b/tests/Feature/NavigationAPITest.php @@ -22,14 +22,13 @@ * High level tests for the Navigation API to go along with the code-driven documentation. * * @see \Hyde\Framework\Features\Navigation\ - * - * @covers \Hyde\Framework\Features\Navigation\NavigationMenu - * @covers \Hyde\Framework\Features\Navigation\NavigationItem - * @covers \Hyde\Framework\Features\Navigation\NavigationGroup - * @covers \Hyde\Framework\Features\Navigation\MainNavigationMenu - * @covers \Hyde\Framework\Features\Navigation\DocumentationSidebar */ #[AllowDynamicProperties] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationMenu::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationItem::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationGroup::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\MainNavigationMenu::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\DocumentationSidebar::class)] class NavigationAPITest extends TestCase { use MocksKernelFeatures; diff --git a/tests/Feature/NavigationDataTest.php b/tests/Feature/NavigationDataTest.php index de433810..a9d00329 100644 --- a/tests/Feature/NavigationDataTest.php +++ b/tests/Feature/NavigationDataTest.php @@ -9,9 +9,7 @@ use Hyde\Testing\UnitTestCase; use ReflectionClass; -/** - * @covers \Hyde\Framework\Features\Navigation\NavigationData - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationData::class)] class NavigationDataTest extends UnitTestCase { protected array $array = [ diff --git a/tests/Feature/NavigationMenuTest.php b/tests/Feature/NavigationMenuTest.php index 0b48b00c..ae3fecc1 100644 --- a/tests/Feature/NavigationMenuTest.php +++ b/tests/Feature/NavigationMenuTest.php @@ -18,12 +18,11 @@ use Hyde\Framework\Features\Navigation\NavigationMenuGenerator; /** - * @covers \Hyde\Framework\Features\Navigation\NavigationMenu - * @covers \Hyde\Framework\Features\Navigation\MainNavigationMenu - * @covers \Hyde\Framework\Features\Navigation\NavigationMenuGenerator - * * @see \Hyde\Framework\Testing\Unit\NavigationMenuUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationMenu::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\MainNavigationMenu::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationMenuGenerator::class)] class NavigationMenuTest extends TestCase { public function testConstructor() diff --git a/tests/Feature/NumericalPageOrderingHelperTest.php b/tests/Feature/NumericalPageOrderingHelperTest.php index 9e344bb2..56bedf18 100644 --- a/tests/Feature/NumericalPageOrderingHelperTest.php +++ b/tests/Feature/NumericalPageOrderingHelperTest.php @@ -19,13 +19,13 @@ * * It also works within sidebar groups, so that multiple groups can have the same prefix independent of other groups. * - * @covers \Hyde\Framework\Features\Navigation\NumericalPageOrderingHelper - * @covers \Hyde\Framework\Features\Navigation\DocumentationSidebar - * @covers \Hyde\Framework\Factories\NavigationDataFactory - * @covers \Hyde\Support\Models\RouteKey * * @see \Hyde\Framework\Testing\Unit\NumericalPageOrderingHelperUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NumericalPageOrderingHelper::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\DocumentationSidebar::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\NavigationDataFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Models\RouteKey::class)] class NumericalPageOrderingHelperTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/PageCollectionTest.php b/tests/Feature/PageCollectionTest.php index 423844ab..38ce661f 100644 --- a/tests/Feature/PageCollectionTest.php +++ b/tests/Feature/PageCollectionTest.php @@ -17,11 +17,9 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Collection; -/** - * @covers \Hyde\Foundation\Kernel\PageCollection - * @covers \Hyde\Foundation\Concerns\BaseFoundationCollection - * @covers \Hyde\Foundation\Facades\Pages - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\PageCollection::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Concerns\BaseFoundationCollection::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Facades\Pages::class)] class PageCollectionTest extends TestCase { public function testBootMethodCreatesNewPageCollectionAndDiscoversPagesAutomatically() diff --git a/tests/Feature/PaginatorTest.php b/tests/Feature/PaginatorTest.php index 41587d0f..4dc29eed 100644 --- a/tests/Feature/PaginatorTest.php +++ b/tests/Feature/PaginatorTest.php @@ -10,9 +10,7 @@ use Hyde\Testing\TestCase; use InvalidArgumentException; -/** - * @covers \Hyde\Support\Paginator - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Paginator::class)] class PaginatorTest extends TestCase { public function testItCanBeInstantiated(): void diff --git a/tests/Feature/PharSupportTest.php b/tests/Feature/PharSupportTest.php index 8047239f..7cb1f6e3 100644 --- a/tests/Feature/PharSupportTest.php +++ b/tests/Feature/PharSupportTest.php @@ -8,9 +8,7 @@ use Hyde\Hyde; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Foundation\PharSupport - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\PharSupport::class)] class PharSupportTest extends TestCase { public function tearDown(): void @@ -53,7 +51,7 @@ public function testVendorPathCanRunInPhar() PharSupport::mock('running', true); PharSupport::mock('hasVendorDirectory', false); - $this->assertEquals($this->replaceSlashes(Hyde::path("{$this->getBaseVendorPath()}/framework")), Hyde::vendorPath()); + $this->assertSame($this->replaceSlashes(Hyde::path("{$this->getBaseVendorPath()}/framework")), Hyde::vendorPath()); } public function testVendorPathCanRunInPharWithPathArgument() @@ -61,7 +59,7 @@ public function testVendorPathCanRunInPharWithPathArgument() PharSupport::mock('running', true); PharSupport::mock('hasVendorDirectory', false); - $this->assertEquals($this->replaceSlashes(Hyde::path("{$this->getBaseVendorPath()}/framework/file.php")), Hyde::vendorPath('file.php')); + $this->assertSame($this->replaceSlashes(Hyde::path("{$this->getBaseVendorPath()}/framework/file.php")), Hyde::vendorPath('file.php')); } protected function getBaseVendorPath(): string diff --git a/tests/Feature/ReadingTimeTest.php b/tests/Feature/ReadingTimeTest.php index c55014d6..88086455 100644 --- a/tests/Feature/ReadingTimeTest.php +++ b/tests/Feature/ReadingTimeTest.php @@ -8,9 +8,7 @@ use Hyde\Support\ReadingTime; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Support\ReadingTime - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\ReadingTime::class)] class ReadingTimeTest extends UnitTestCase { public static function setUpBeforeClass(): void diff --git a/tests/Feature/RedirectTest.php b/tests/Feature/RedirectTest.php index e1ef8633..bdf2764f 100644 --- a/tests/Feature/RedirectTest.php +++ b/tests/Feature/RedirectTest.php @@ -10,9 +10,7 @@ use Hyde\Support\Models\Redirect; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Support\Models\Redirect - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Models\Redirect::class)] class RedirectTest extends TestCase { public function testCanCreateARedirect() diff --git a/tests/Feature/RouteCollectionTest.php b/tests/Feature/RouteCollectionTest.php index 5a4d7a2d..d36be120 100644 --- a/tests/Feature/RouteCollectionTest.php +++ b/tests/Feature/RouteCollectionTest.php @@ -17,11 +17,9 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Collection; -/** - * @covers \Hyde\Foundation\Kernel\RouteCollection - * @covers \Hyde\Foundation\Concerns\BaseFoundationCollection - * @covers \Hyde\Foundation\Facades\Routes - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\RouteCollection::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Concerns\BaseFoundationCollection::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Facades\Routes::class)] class RouteCollectionTest extends TestCase { public function testBootMethodDiscoversAllPages() diff --git a/tests/Feature/Services/BladeDownProcessorTest.php b/tests/Feature/Services/BladeDownProcessorTest.php index d6e55a0b..6e941a29 100644 --- a/tests/Feature/Services/BladeDownProcessorTest.php +++ b/tests/Feature/Services/BladeDownProcessorTest.php @@ -7,9 +7,7 @@ use Hyde\Markdown\Processing\BladeDownProcessor; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Markdown\Processing\BladeDownProcessor - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Processing\BladeDownProcessor::class)] class BladeDownProcessorTest extends TestCase { public function testItRendersBladeEchoSyntax() diff --git a/tests/Feature/Services/BuildTaskServiceTest.php b/tests/Feature/Services/BuildTaskServiceTest.php index 00891a9c..2026767d 100644 --- a/tests/Feature/Services/BuildTaskServiceTest.php +++ b/tests/Feature/Services/BuildTaskServiceTest.php @@ -13,20 +13,17 @@ use Illuminate\Support\Facades\File; /** - * @covers \Hyde\Framework\Services\BuildTaskService - * @covers \Hyde\Framework\Features\BuildTasks\BuildTask - * @covers \Hyde\Framework\Features\BuildTasks\PreBuildTask - * @covers \Hyde\Framework\Features\BuildTasks\PostBuildTask - * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap - * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed - * * @see \Hyde\Framework\Testing\Unit\BuildTaskServiceUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Services\BuildTaskService::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\BuildTasks\BuildTask::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\BuildTasks\PreBuildTask::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\BuildTasks\PostBuildTask::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\BuildSiteCommand::class)] class BuildTaskServiceTest extends TestCase { - /** - * @covers \Hyde\Console\Commands\BuildSiteCommand::runPostBuildActions - */ public function testBuildCommandCanRunBuildTasks() { $this->withSiteUrl(); @@ -55,7 +52,7 @@ public function testGetPostBuildTasksReturnsArrayMergedWithConfig() $service = $this->makeService(); $tasks = $service->getRegisteredTasks(); - $this->assertSame(1, count(array_keys($tasks, SecondBuildTask::class))); + $this->assertCount(1, array_keys($tasks, SecondBuildTask::class)); } public function testGetPostBuildTasksMergesDuplicateKeys() @@ -66,7 +63,7 @@ public function testGetPostBuildTasksMergesDuplicateKeys() $service = $this->makeService(); $tasks = $service->getRegisteredTasks(); - $this->assertSame(1, count(array_keys($tasks, TestBuildTask::class))); + $this->assertCount(1, array_keys($tasks, TestBuildTask::class)); } public function testRunPostBuildTasksRunsConfiguredTasks() diff --git a/tests/Feature/Services/DocumentationSearchServiceTest.php b/tests/Feature/Services/DocumentationSearchServiceTest.php index 2ad1edc1..cb0fd00e 100644 --- a/tests/Feature/Services/DocumentationSearchServiceTest.php +++ b/tests/Feature/Services/DocumentationSearchServiceTest.php @@ -9,9 +9,7 @@ use Hyde\Testing\CreatesTemporaryFiles; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Framework\Actions\GeneratesDocumentationSearchIndex - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\GeneratesDocumentationSearchIndex::class)] class DocumentationSearchServiceTest extends UnitTestCase { use CreatesTemporaryFiles; diff --git a/tests/Feature/Services/DocumentationSidebarTest.php b/tests/Feature/Services/DocumentationSidebarTest.php index 6ce5db7a..ad14072d 100644 --- a/tests/Feature/Services/DocumentationSidebarTest.php +++ b/tests/Feature/Services/DocumentationSidebarTest.php @@ -19,16 +19,15 @@ use Hyde\Framework\Features\Navigation\NavigationMenuGenerator; /** - * @covers \Hyde\Framework\Features\Navigation\DocumentationSidebar - * @covers \Hyde\Framework\Features\Navigation\NavigationMenuGenerator - * @covers \Hyde\Framework\Features\Navigation\NavigationMenu - * @covers \Hyde\Framework\Factories\Concerns\HasFactory - * @covers \Hyde\Framework\Factories\NavigationDataFactory - * @covers \Hyde\Framework\Features\Navigation\NavigationItem - * * @see \Hyde\Framework\Testing\Unit\DocumentationSidebarUnitTest * @see \Hyde\Framework\Testing\Unit\DocumentationSidebarGetActiveGroupUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\DocumentationSidebar::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationMenuGenerator::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationMenu::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\Concerns\HasFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\NavigationDataFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationItem::class)] class DocumentationSidebarTest extends TestCase { protected function setUp(): void @@ -227,7 +226,7 @@ public function testIsGroupActiveReturnsFalseWhenSuppliedGroupIsNotActive() { Render::setPage(new DocumentationPage(matter: ['navigation.group' => 'foo'])); $mainNavigationMenu = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertFalse('bar' === $this->getGroupKey($mainNavigationMenu)); + $this->assertNotSame('bar', $this->getGroupKey($mainNavigationMenu)); } public function testIsGroupActiveReturnsTrueWhenSuppliedGroupIsActive() @@ -235,7 +234,7 @@ public function testIsGroupActiveReturnsTrueWhenSuppliedGroupIsActive() $this->makePage('foo', ['navigation.group' => 'foo']); Render::setPage(new DocumentationPage(matter: ['navigation.group' => 'foo'])); $mainNavigationMenu = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertTrue('foo' === $this->getGroupKey($mainNavigationMenu)); + $this->assertSame('foo', $this->getGroupKey($mainNavigationMenu)); } public function testIsGroupActiveReturnsTrueForDifferingCasing() @@ -243,7 +242,7 @@ public function testIsGroupActiveReturnsTrueForDifferingCasing() $this->makePage('foo', ['navigation.group' => 'Foo Bar']); Render::setPage(new DocumentationPage(matter: ['navigation.group' => 'Foo Bar'])); $mainNavigationMenu = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertTrue('foo-bar' === $this->getGroupKey($mainNavigationMenu)); + $this->assertSame('foo-bar', $this->getGroupKey($mainNavigationMenu)); } public function testIsGroupActiveReturnsTrueFirstGroupOfIndexPage() @@ -255,11 +254,11 @@ public function testIsGroupActiveReturnsTrueFirstGroupOfIndexPage() Render::setPage(DocumentationPage::get('index')); $mainNavigationMenu2 = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertTrue('bar' === $this->getGroupKey($mainNavigationMenu2)); + $this->assertSame('bar', $this->getGroupKey($mainNavigationMenu2)); $mainNavigationMenu1 = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertFalse('foo' === $this->getGroupKey($mainNavigationMenu1)); + $this->assertNotSame('foo', $this->getGroupKey($mainNavigationMenu1)); $mainNavigationMenu = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertFalse('baz' === $this->getGroupKey($mainNavigationMenu)); + $this->assertNotSame('baz', $this->getGroupKey($mainNavigationMenu)); } public function testIsGroupActiveReturnsTrueFirstSortedGroupOfIndexPage() @@ -271,11 +270,11 @@ public function testIsGroupActiveReturnsTrueFirstSortedGroupOfIndexPage() Render::setPage(DocumentationPage::get('index')); $mainNavigationMenu2 = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertTrue('foo' === $this->getGroupKey($mainNavigationMenu2)); + $this->assertSame('foo', $this->getGroupKey($mainNavigationMenu2)); $mainNavigationMenu1 = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertFalse('bar' === $this->getGroupKey($mainNavigationMenu1)); + $this->assertNotSame('bar', $this->getGroupKey($mainNavigationMenu1)); $mainNavigationMenu = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertFalse('baz' === $this->getGroupKey($mainNavigationMenu)); + $this->assertNotSame('baz', $this->getGroupKey($mainNavigationMenu)); } public function testAutomaticIndexPageGroupExpansionRespectsCustomNavigationMenuSettings() @@ -287,11 +286,11 @@ public function testAutomaticIndexPageGroupExpansionRespectsCustomNavigationMenu Render::setPage(DocumentationPage::get('index')); $mainNavigationMenu2 = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertFalse('foo' === $this->getGroupKey($mainNavigationMenu2)); + $this->assertNotSame('foo', $this->getGroupKey($mainNavigationMenu2)); $mainNavigationMenu1 = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertFalse('bar' === $this->getGroupKey($mainNavigationMenu1)); + $this->assertNotSame('bar', $this->getGroupKey($mainNavigationMenu1)); $mainNavigationMenu = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertTrue('baz' === $this->getGroupKey($mainNavigationMenu)); + $this->assertSame('baz', $this->getGroupKey($mainNavigationMenu)); } public function testCanHaveMultipleGroupedPagesWithTheSameNameLabels() @@ -340,7 +339,7 @@ public function testIsGroupActiveForIndexPageWithNoGroups() Render::setPage(DocumentationPage::get('index')); $mainNavigationMenu = NavigationMenuGenerator::handle(DocumentationSidebar::class); - $this->assertFalse('foo' === $this->getGroupKey($mainNavigationMenu)); + $this->assertNotSame('foo', $this->getGroupKey($mainNavigationMenu)); } public function testIndexPageAddedToSidebarWhenItIsTheOnlyPage() diff --git a/tests/Feature/Services/HydeSmartDocsTest.php b/tests/Feature/Services/HydeSmartDocsTest.php index 9648ce4b..9d534bbc 100644 --- a/tests/Feature/Services/HydeSmartDocsTest.php +++ b/tests/Feature/Services/HydeSmartDocsTest.php @@ -9,9 +9,7 @@ use Hyde\Testing\TestCase; use Illuminate\Support\HtmlString; -/** - * @covers \Hyde\Framework\Features\Documentation\SemanticDocumentationArticle - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Documentation\SemanticDocumentationArticle::class)] class HydeSmartDocsTest extends TestCase { public function testClassTokenizesDocument() diff --git a/tests/Feature/Services/Markdown/CodeblockFilepathProcessorTest.php b/tests/Feature/Services/Markdown/CodeblockFilepathProcessorTest.php index 294d439d..e1f3c49f 100644 --- a/tests/Feature/Services/Markdown/CodeblockFilepathProcessorTest.php +++ b/tests/Feature/Services/Markdown/CodeblockFilepathProcessorTest.php @@ -7,9 +7,7 @@ use Hyde\Markdown\Processing\CodeblockFilepathProcessor; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Markdown\Processing\CodeblockFilepathProcessor - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Processing\CodeblockFilepathProcessor::class)] class CodeblockFilepathProcessorTest extends TestCase { public function testPreprocessExpandsFilepath() diff --git a/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php b/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php index a0736900..b50becda 100644 --- a/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php +++ b/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php @@ -16,10 +16,9 @@ use Hyde\Markdown\Processing\DynamicMarkdownLinkProcessor; /** - * @covers \Hyde\Markdown\Processing\DynamicMarkdownLinkProcessor - * * @see \Hyde\Framework\Testing\Feature\DynamicMarkdownLinksFeatureTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Processing\DynamicMarkdownLinkProcessor::class)] class DynamicMarkdownLinkProcessorTest extends UnitTestCase { protected static bool $needsConfig = true; diff --git a/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php b/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php index b7ff55d5..0c55132d 100644 --- a/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php +++ b/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php @@ -9,9 +9,7 @@ use Hyde\Testing\UnitTestCase; use Hyde\Testing\UsesRealBladeInUnitTests; -/** - * @covers \Hyde\Markdown\Processing\ShortcodeProcessor - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Processing\ShortcodeProcessor::class)] class ShortcodeProcessorTest extends UnitTestCase { use UsesRealBladeInUnitTests; diff --git a/tests/Feature/Services/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php index 72f291ea..1951a588 100644 --- a/tests/Feature/Services/RssFeedServiceTest.php +++ b/tests/Feature/Services/RssFeedServiceTest.php @@ -13,10 +13,8 @@ use Hyde\Hyde; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Framework\Features\XmlGenerators\RssFeedGenerator - * @covers \Hyde\Framework\Features\XmlGenerators\BaseXmlGenerator - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\XmlGenerators\RssFeedGenerator::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\XmlGenerators\BaseXmlGenerator::class)] class RssFeedServiceTest extends TestCase { public function testServiceInstantiatesXmlElement() diff --git a/tests/Feature/Services/SitemapServiceTest.php b/tests/Feature/Services/SitemapServiceTest.php index c19d8a00..b9d973b2 100644 --- a/tests/Feature/Services/SitemapServiceTest.php +++ b/tests/Feature/Services/SitemapServiceTest.php @@ -13,10 +13,8 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; -/** - * @covers \Hyde\Framework\Features\XmlGenerators\SitemapGenerator - * @covers \Hyde\Framework\Features\XmlGenerators\BaseXmlGenerator - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\XmlGenerators\SitemapGenerator::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\XmlGenerators\BaseXmlGenerator::class)] class SitemapServiceTest extends TestCase { protected function setUp(): void diff --git a/tests/Feature/Services/ValidationServiceTest.php b/tests/Feature/Services/ValidationServiceTest.php index ef8090a2..bea640ab 100644 --- a/tests/Feature/Services/ValidationServiceTest.php +++ b/tests/Feature/Services/ValidationServiceTest.php @@ -11,11 +11,10 @@ use Hyde\Testing\TestCase; /** - * @covers \Hyde\Framework\Services\ValidationService - * @covers \Hyde\Support\Models\ValidationResult - * * @see \Hyde\Framework\Testing\Feature\Commands\ValidateCommandTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Services\ValidationService::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Models\ValidationResult::class)] class ValidationServiceTest extends TestCase { protected ValidationService $service; diff --git a/tests/Feature/SiteTest.php b/tests/Feature/SiteTest.php index c4d68cf0..394a05d8 100644 --- a/tests/Feature/SiteTest.php +++ b/tests/Feature/SiteTest.php @@ -8,9 +8,7 @@ use Hyde\Framework\Features\Metadata\GlobalMetadataBag; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Facades\Site - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Site::class)] class SiteTest extends TestCase { public function testUrl() diff --git a/tests/Feature/SitemapFeatureTest.php b/tests/Feature/SitemapFeatureTest.php index f2a79157..f2a55e04 100644 --- a/tests/Feature/SitemapFeatureTest.php +++ b/tests/Feature/SitemapFeatureTest.php @@ -18,11 +18,10 @@ * * @see \Hyde\Framework\Testing\Feature\Services\SitemapServiceTest * @see \Hyde\Framework\Testing\Feature\Commands\BuildSitemapCommandTest - * - * @covers \Hyde\Framework\Features\XmlGenerators\SitemapGenerator - * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap - * @covers \Hyde\Console\Commands\BuildSitemapCommand */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\XmlGenerators\SitemapGenerator::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\BuildSitemapCommand::class)] class SitemapFeatureTest extends TestCase { public function testTheSitemapFeature() diff --git a/tests/Feature/SitesWithoutBaseUrlAreHandledGracefullyTest.php b/tests/Feature/SitesWithoutBaseUrlAreHandledGracefullyTest.php index f8375464..78715413 100644 --- a/tests/Feature/SitesWithoutBaseUrlAreHandledGracefullyTest.php +++ b/tests/Feature/SitesWithoutBaseUrlAreHandledGracefullyTest.php @@ -21,20 +21,19 @@ * as their schemas generally do not allow relative URLs. In those cases, we * don't generate files at all, and we don't add any links to them either. * - * @coversNothing This test is not testing a specific class, but a general feature of the framework. + * This test is not testing a specific class, but a general feature of the framework. */ +#[\PHPUnit\Framework\Attributes\CoversNothing] class SitesWithoutBaseUrlAreHandledGracefullyTest extends TestCase { - public static function pageClassProvider(): array + public static function pageClassProvider(): \Iterator { - return [ - [MarkdownPage::class], - [MarkdownPost::class], - [DocumentationPage::class], - ]; + yield [MarkdownPage::class]; + yield [MarkdownPost::class]; + yield [DocumentationPage::class]; } - /** @dataProvider pageClassProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('pageClassProvider')] public function testLocalhostLinksAreNotAddedToCompiledHtmlWhenBaseUrlIsNull(string $class) { $this->withoutSiteUrl(); @@ -42,7 +41,7 @@ public function testLocalhostLinksAreNotAddedToCompiledHtmlWhenBaseUrlIsNull(str $this->assertStringNotContainsString('http://localhost', $this->getHtml($class)); } - /** @dataProvider pageClassProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('pageClassProvider')] public function testLocalhostLinksAreNotAddedToCompiledHtmlWhenBaseUrlIsNotSet(string $class) { $this->withoutSiteUrl(); @@ -50,7 +49,7 @@ public function testLocalhostLinksAreNotAddedToCompiledHtmlWhenBaseUrlIsNotSet(s $this->assertStringNotContainsString('http://localhost', $this->getHtml($class)); } - /** @dataProvider pageClassProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('pageClassProvider')] public function testLocalhostLinksAreNotAddedToCompiledHtmlWhenBaseUrlIsSetToLocalhost(string $class) { config(['hyde.url' => 'http://localhost']); @@ -58,7 +57,7 @@ public function testLocalhostLinksAreNotAddedToCompiledHtmlWhenBaseUrlIsSetToLoc $this->assertStringNotContainsString('http://localhost', $this->getHtml($class)); } - /** @dataProvider pageClassProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('pageClassProvider')] public function testSiteUrlLinksAreAddedToCompiledHtmlWhenBaseUrlIsSetToValidUrl(string $class) { $this->withSiteUrl(); diff --git a/tests/Feature/SourceDirectoriesCanBeChangedTest.php b/tests/Feature/SourceDirectoriesCanBeChangedTest.php index 59deaf47..91dbc2d0 100644 --- a/tests/Feature/SourceDirectoriesCanBeChangedTest.php +++ b/tests/Feature/SourceDirectoriesCanBeChangedTest.php @@ -15,11 +15,11 @@ class SourceDirectoriesCanBeChangedTest extends TestCase { - public static function tearDownAfterClass(): void + protected function tearDown(): void { - parent::tearDownAfterClass(); - File::deleteDirectory('_source'); + + parent::tearDown(); } public function testBaselines() diff --git a/tests/Feature/SourceFileParserTest.php b/tests/Feature/SourceFileParserTest.php index 4593096f..e63d1e86 100644 --- a/tests/Feature/SourceFileParserTest.php +++ b/tests/Feature/SourceFileParserTest.php @@ -12,9 +12,7 @@ use Hyde\Pages\MarkdownPost; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Framework\Actions\SourceFileParser - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\SourceFileParser::class)] class SourceFileParserTest extends TestCase { public function testBladePageParser() diff --git a/tests/Feature/StaticPageBuilderTest.php b/tests/Feature/StaticPageBuilderTest.php index 8042597e..6969adda 100644 --- a/tests/Feature/StaticPageBuilderTest.php +++ b/tests/Feature/StaticPageBuilderTest.php @@ -16,13 +16,11 @@ use Hyde\Pages\MarkdownPost; use Hyde\Testing\TestCase; use Illuminate\Support\Facades\Config; -use Illuminate\Support\Facades\File; /** * Feature tests for the StaticPageBuilder class. - * - * @covers \Hyde\Framework\Actions\StaticPageBuilder */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\StaticPageBuilder::class)] class StaticPageBuilderTest extends TestCase { protected function setUp(): void @@ -63,7 +61,7 @@ public function testCanBuildBladePage() $this->assertFileExists(Hyde::path('_site/foo.html')); $this->assertStringEqualsFile(Hyde::path('_site/foo.html'), 'bar'); - unlink(BladePage::sourceDirectory().'/foo.blade.php'); + Filesystem::unlink(BladePage::sourceDirectory().'/foo.blade.php'); Filesystem::unlink('_site/foo.html'); } @@ -152,7 +150,7 @@ public function testSiteDirectoryCanBeCustomized() $this->assertFileExists(Hyde::path('foo/foo.html')); $this->validateBasicHtml(file_get_contents(Hyde::path('foo/foo.html'))); - File::deleteDirectory(Hyde::path('foo')); + Filesystem::deleteDirectory('foo'); } public function testSiteDirectoryCanBeCustomizedWithNestedPages() @@ -164,7 +162,7 @@ public function testSiteDirectoryCanBeCustomizedWithNestedPages() $this->assertFileExists(Hyde::path('foo/posts/foo.html')); $this->validateBasicHtml(file_get_contents(Hyde::path('foo/posts/foo.html'))); - File::deleteDirectory(Hyde::path('foo')); + Filesystem::deleteDirectory('foo'); } public function testCanRebuildBladePage() @@ -173,7 +171,7 @@ public function testCanRebuildBladePage() StaticPageBuilder::handle(Pages::getPage('_pages/foo.blade.php')); $this->assertFileExists('_site/foo.html'); - unlink(Hyde::path('_site/foo.html')); + Filesystem::unlink('_site/foo.html'); } public function testCanRebuildMarkdownPage() @@ -182,7 +180,7 @@ public function testCanRebuildMarkdownPage() StaticPageBuilder::handle(Pages::getPage('_pages/foo.md')); $this->assertFileExists('_site/foo.html'); - unlink(Hyde::path('_site/foo.html')); + Filesystem::unlink('_site/foo.html'); } public function testCanRebuildMarkdownPost() @@ -191,7 +189,7 @@ public function testCanRebuildMarkdownPost() StaticPageBuilder::handle(Pages::getPage('_posts/foo.md')); $this->assertFileExists('_site/posts/foo.html'); - unlink(Hyde::path('_site/posts/foo.html')); + Filesystem::unlink('_site/posts/foo.html'); } public function testCanRebuildDocumentationPage() @@ -200,6 +198,6 @@ public function testCanRebuildDocumentationPage() StaticPageBuilder::handle(Pages::getPage('_pages/foo.md')); $this->assertFileExists('_site/foo.html'); - unlink(Hyde::path('_site/foo.html')); + Filesystem::unlink('_site/foo.html'); } } diff --git a/tests/Feature/StaticSiteServiceTest.php b/tests/Feature/StaticSiteServiceTest.php index fc4449b1..0010020c 100644 --- a/tests/Feature/StaticSiteServiceTest.php +++ b/tests/Feature/StaticSiteServiceTest.php @@ -14,12 +14,10 @@ use Hyde\Framework\HydeServiceProvider; use Hyde\Framework\Actions\StaticPageBuilder; -/** - * @covers \Hyde\Console\Commands\BuildSiteCommand - * @covers \Hyde\Framework\Services\BuildService - * @covers \Hyde\Framework\Actions\PreBuildTasks\CleanSiteDirectory - * @covers \Hyde\Framework\Actions\PreBuildTasks\TransferMediaAssets - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Commands\BuildSiteCommand::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Services\BuildService::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\PreBuildTasks\CleanSiteDirectory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\PreBuildTasks\TransferMediaAssets::class)] class StaticSiteServiceTest extends TestCase { protected function setUp(): void @@ -160,13 +158,11 @@ public function testNodeActionOutputs() { Process::fake(); - $this->artisan('build --run-prettier --run-vite') + $this->artisan('build --vite') ->expectsOutput('Building frontend assets for production! This may take a second.') - ->expectsOutput('Prettifying code! This may take a second.') ->assertExitCode(0); Process::assertRan(fn ($process) => $process->command === 'npm run build'); - Process::assertRan(fn ($process) => $process->command === 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line'); } public function testPrettyUrlsOptionOutput() diff --git a/tests/Feature/Support/MediaFileTest.php b/tests/Feature/Support/MediaFileTest.php index 9ed44ccd..8d284490 100644 --- a/tests/Feature/Support/MediaFileTest.php +++ b/tests/Feature/Support/MediaFileTest.php @@ -11,10 +11,9 @@ use Hyde\Framework\Exceptions\FileNotFoundException; /** - * @covers \Hyde\Support\Filesystem\MediaFile - * * @see \Hyde\Framework\Testing\Unit\Support\MediaFileUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Filesystem\MediaFile::class)] class MediaFileTest extends TestCase { public function testMediaFileCreationAndBasicProperties() diff --git a/tests/Feature/Support/ProjectFileTest.php b/tests/Feature/Support/ProjectFileTest.php index 892ae7ff..8331016d 100644 --- a/tests/Feature/Support/ProjectFileTest.php +++ b/tests/Feature/Support/ProjectFileTest.php @@ -9,9 +9,7 @@ use Hyde\Support\Filesystem\ProjectFile; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Support\Filesystem\ProjectFile - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Filesystem\ProjectFile::class)] class ProjectFileTest extends TestCase { public function testCanConstruct() diff --git a/tests/Feature/Support/SourceFileTest.php b/tests/Feature/Support/SourceFileTest.php index 5a92e007..d344c762 100644 --- a/tests/Feature/Support/SourceFileTest.php +++ b/tests/Feature/Support/SourceFileTest.php @@ -11,9 +11,7 @@ use Hyde\Support\Filesystem\SourceFile; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Support\Filesystem\SourceFile - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Filesystem\SourceFile::class)] class SourceFileTest extends TestCase { public function testCanConstruct() diff --git a/tests/Feature/TypedConfigFacadeTest.php b/tests/Feature/TypedConfigFacadeTest.php index dd5af604..65cc5ac3 100644 --- a/tests/Feature/TypedConfigFacadeTest.php +++ b/tests/Feature/TypedConfigFacadeTest.php @@ -9,9 +9,7 @@ use TypeError; use stdClass; -/** - * @covers \Hyde\Facades\Config - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Config::class)] class TypedConfigFacadeTest extends TestCase { public function testGetArray() diff --git a/tests/Feature/Views/MetadataViewTest.php b/tests/Feature/Views/MetadataViewTest.php index 1e517e8e..fb23472e 100644 --- a/tests/Feature/Views/MetadataViewTest.php +++ b/tests/Feature/Views/MetadataViewTest.php @@ -14,11 +14,10 @@ * as this test does not cover all configuration cases and possible formatting options. * * This test is useful both as a regression test, and also to ensure all tags are covered. - * - * @covers \Hyde\Framework\Features\Metadata\MetadataBag - * @covers \Hyde\Framework\Features\Metadata\PageMetadataBag - * @covers \Hyde\Framework\Features\Metadata\GlobalMetadataBag */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\MetadataBag::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\PageMetadataBag::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Metadata\GlobalMetadataBag::class)] class MetadataViewTest extends TestCase { protected function setUp(): void @@ -27,6 +26,8 @@ protected function setUp(): void $this->withSiteUrl(); config(['hyde.cache_busting' => false]); + + @unlink('app/storage/framework/runtime/vite.hot'); } protected function build(?string $page = null): void @@ -60,13 +61,13 @@ protected function assertAllTagsWereCovered(string $page, array $tags): void $expected = file_get_contents(Hyde::path("_site/$page.html")); $actual = json_encode($tags); - $this->assertEquals( + $this->assertSame( substr_count($expected, 'assertEquals( + $this->assertSame( substr_count($expected, 'assertSame($expectedOutput, ColoredBlockquotes::resolve($input)); } - public static function blockquoteProvider(): array + public static function blockquoteProvider(): \Iterator { - return [ - [ - '>danger This is a danger blockquote', - <<<'HTML' + yield [ + '>danger This is a danger blockquote', + <<<'HTML'

This is a danger blockquote

HTML, - ], - [ - '>info This is an info blockquote', - <<<'HTML' + ]; + yield [ + '>info This is an info blockquote', + <<<'HTML'

This is an info blockquote

HTML, - ], - [ - '>success This is a success blockquote', - <<<'HTML' + ]; + yield [ + '>success This is a success blockquote', + <<<'HTML'

This is a success blockquote

HTML, - ], - [ - '>warning This is a warning blockquote', - <<<'HTML' + ]; + yield [ + '>warning This is a warning blockquote', + <<<'HTML'

This is a warning blockquote

HTML, - ], ]; } } diff --git a/tests/Unit/Console/Helpers/ViewPublishGroupTest.php b/tests/Unit/Console/Helpers/ViewPublishGroupTest.php index fb7942d0..d621c96c 100644 --- a/tests/Unit/Console/Helpers/ViewPublishGroupTest.php +++ b/tests/Unit/Console/Helpers/ViewPublishGroupTest.php @@ -11,9 +11,7 @@ use Hyde\Console\Helpers\ViewPublishGroup; use Illuminate\Support\Collection; -/** - * @covers \Hyde\Console\Helpers\ViewPublishGroup - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Helpers\ViewPublishGroup::class)] class ViewPublishGroupTest extends UnitTestCase { protected static bool $needsKernel = true; @@ -47,11 +45,11 @@ public function testCanCreateGroup() $this->assertInstanceOf(ViewPublishGroup::class, $group); - $this->assertSame($group->group, 'layouts'); - $this->assertSame($group->name, 'Layouts'); - $this->assertSame($group->description, "Publish the 'layouts' files for customization."); + $this->assertSame('layouts', $group->group); + $this->assertSame('Layouts', $group->name); + $this->assertSame("Publish the 'layouts' files for customization.", $group->description); $this->assertSame($group->source, ViewPublishGroupTest::$packageDirectory.'/framework/resources/views/layouts'); - $this->assertSame($group->target, 'resources/views/vendor/hyde/layouts'); + $this->assertSame('resources/views/vendor/hyde/layouts', $group->target); $this->assertSame($group->files, ['app.blade.php', 'page.blade.php', 'post.blade.php']); } @@ -59,24 +57,24 @@ public function testCanCreateGroupWithCustomName() { $group = ViewPublishGroup::fromGroup('layouts', 'Custom Layouts'); - $this->assertSame($group->name, 'Custom Layouts'); - $this->assertSame($group->description, "Publish the 'layouts' files for customization."); + $this->assertSame('Custom Layouts', $group->name); + $this->assertSame("Publish the 'layouts' files for customization.", $group->description); } public function testCanCreateGroupWithCustomDescription() { $group = ViewPublishGroup::fromGroup('layouts', null, 'Custom description'); - $this->assertSame($group->name, 'Layouts'); - $this->assertSame($group->description, 'Custom description'); + $this->assertSame('Layouts', $group->name); + $this->assertSame('Custom description', $group->description); } public function testCanCreateGroupWithCustomNameAndDescription() { $group = ViewPublishGroup::fromGroup('layouts', 'Custom Layouts', 'Custom description'); - $this->assertSame($group->name, 'Custom Layouts'); - $this->assertSame($group->description, 'Custom description'); + $this->assertSame('Custom Layouts', $group->name); + $this->assertSame('Custom description', $group->description); } public function testCanGetPublishableFilesMap() diff --git a/tests/Unit/ConsoleHelperTest.php b/tests/Unit/ConsoleHelperTest.php index ff3307e1..988adf10 100644 --- a/tests/Unit/ConsoleHelperTest.php +++ b/tests/Unit/ConsoleHelperTest.php @@ -8,9 +8,7 @@ use Hyde\Testing\UnitTestCase; use Symfony\Component\Console\Input\InputInterface; -/** - * @covers \Hyde\Console\Helpers\ConsoleHelper - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Helpers\ConsoleHelper::class)] class ConsoleHelperTest extends UnitTestCase { protected function tearDown(): void diff --git a/tests/Unit/ConsoleServiceProviderUnitTest.php b/tests/Unit/ConsoleServiceProviderUnitTest.php index 07a792be..75fd259d 100644 --- a/tests/Unit/ConsoleServiceProviderUnitTest.php +++ b/tests/Unit/ConsoleServiceProviderUnitTest.php @@ -7,9 +7,7 @@ use Hyde\Console\ConsoleServiceProvider; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Console\ConsoleServiceProvider - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\ConsoleServiceProvider::class)] class ConsoleServiceProviderUnitTest extends UnitTestCase { public function testProviderRegistersLogo() diff --git a/tests/Unit/CoreDataObjectTest.php b/tests/Unit/CoreDataObjectTest.php index 091a9f45..d0575752 100644 --- a/tests/Unit/CoreDataObjectTest.php +++ b/tests/Unit/CoreDataObjectTest.php @@ -9,9 +9,7 @@ use Hyde\Pages\MarkdownPage; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Framework\Factories\Concerns\CoreDataObject - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\Concerns\CoreDataObject::class)] class CoreDataObjectTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/CreatesNewMarkdownPostFileTest.php b/tests/Unit/CreatesNewMarkdownPostFileTest.php index 338db38c..332f7412 100644 --- a/tests/Unit/CreatesNewMarkdownPostFileTest.php +++ b/tests/Unit/CreatesNewMarkdownPostFileTest.php @@ -10,10 +10,9 @@ use Hyde\Framework\Actions\CreatesNewMarkdownPostFile; /** - * @covers \Hyde\Framework\Actions\CreatesNewMarkdownPostFile - * * @see \Hyde\Framework\Testing\Feature\Commands\MakePostCommandTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\CreatesNewMarkdownPostFile::class)] class CreatesNewMarkdownPostFileTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/CustomExceptionsTest.php b/tests/Unit/CustomExceptionsTest.php index d0ac2ae0..dac82c17 100644 --- a/tests/Unit/CustomExceptionsTest.php +++ b/tests/Unit/CustomExceptionsTest.php @@ -15,14 +15,12 @@ use Exception; use Hyde\Framework\Exceptions\InvalidConfigurationException; -/** - * @covers \Hyde\Framework\Exceptions\FileConflictException - * @covers \Hyde\Framework\Exceptions\FileNotFoundException - * @covers \Hyde\Framework\Exceptions\RouteNotFoundException - * @covers \Hyde\Framework\Exceptions\UnsupportedPageTypeException - * @covers \Hyde\Framework\Exceptions\InvalidConfigurationException - * @covers \Hyde\Framework\Exceptions\ParseException - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\FileConflictException::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\FileNotFoundException::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\RouteNotFoundException::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\UnsupportedPageTypeException::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\InvalidConfigurationException::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\ParseException::class)] class CustomExceptionsTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/DataCollectionUnitTest.php b/tests/Unit/DataCollectionUnitTest.php index 8ebff95c..1cdd68d3 100644 --- a/tests/Unit/DataCollectionUnitTest.php +++ b/tests/Unit/DataCollectionUnitTest.php @@ -16,10 +16,9 @@ use Hyde\Framework\Exceptions\ParseException; /** - * @covers \Hyde\Support\DataCollection - * * @see \Hyde\Framework\Testing\Feature\DataCollectionTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\DataCollection::class)] class DataCollectionUnitTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/DateStringTest.php b/tests/Unit/DateStringTest.php index 6f17c975..3f9c32e2 100644 --- a/tests/Unit/DateStringTest.php +++ b/tests/Unit/DateStringTest.php @@ -8,9 +8,7 @@ use Hyde\Support\Models\DateString; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Support\Models\DateString - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Models\DateString::class)] class DateStringTest extends UnitTestCase { public function testItCanParseDateString() diff --git a/tests/Unit/DocumentationSidebarGetActiveGroupUnitTest.php b/tests/Unit/DocumentationSidebarGetActiveGroupUnitTest.php index 06d8f27d..3f46ff80 100644 --- a/tests/Unit/DocumentationSidebarGetActiveGroupUnitTest.php +++ b/tests/Unit/DocumentationSidebarGetActiveGroupUnitTest.php @@ -16,11 +16,10 @@ use Hyde\Framework\Features\Navigation\DocumentationSidebar; /** - * @covers \Hyde\Framework\Features\Navigation\DocumentationSidebar - * * @see \Hyde\Framework\Testing\Feature\Services\DocumentationSidebarTest * @see \Hyde\Framework\Testing\Unit\DocumentationSidebarGetActiveGroupUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\DocumentationSidebar::class)] class DocumentationSidebarGetActiveGroupUnitTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/DocumentationSidebarUnitTest.php b/tests/Unit/DocumentationSidebarUnitTest.php index 27e1e382..afe744b8 100644 --- a/tests/Unit/DocumentationSidebarUnitTest.php +++ b/tests/Unit/DocumentationSidebarUnitTest.php @@ -11,13 +11,12 @@ use Hyde\Framework\Features\Navigation\DocumentationSidebar; /** - * @covers \Hyde\Framework\Features\Navigation\DocumentationSidebar - * @covers \Hyde\Framework\Features\Navigation\NavigationMenu - * * @see \Hyde\Framework\Testing\Feature\Services\DocumentationSidebarTest * @see \Hyde\Framework\Testing\Unit\DocumentationSidebarGetActiveGroupUnitTest * @see \Hyde\Framework\Testing\Unit\NavigationMenuUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\DocumentationSidebar::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationMenu::class)] class DocumentationSidebarUnitTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/EnsureCodeFollowsNamingConventionTest.php b/tests/Unit/EnsureCodeFollowsNamingConventionTest.php index 8f9a638f..0e510a63 100644 --- a/tests/Unit/EnsureCodeFollowsNamingConventionTest.php +++ b/tests/Unit/EnsureCodeFollowsNamingConventionTest.php @@ -59,7 +59,8 @@ public function testCommandsDescriptionsFollowNamingConventions() $this->assertIsString($description); $this->assertNotEmpty($description); - $this->assertTrue($description[0] === strtoupper($description[0]), + $this->assertSame(strtoupper($description[0]), + $description[0], "Command class $class description does not start with an uppercase letter.\n ".realpath($filepath) ); diff --git a/tests/Unit/ExampleUnitTest.php b/tests/Unit/ExampleUnitTest.php index c5e092f9..0ecfea6e 100644 --- a/tests/Unit/ExampleUnitTest.php +++ b/tests/Unit/ExampleUnitTest.php @@ -6,9 +6,7 @@ use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Hyde - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Hyde::class)] class ExampleUnitTest extends UnitTestCase { public function testExample() diff --git a/tests/Unit/ExtensionsUnitTest.php b/tests/Unit/ExtensionsUnitTest.php index 60b7653d..d1666295 100644 --- a/tests/Unit/ExtensionsUnitTest.php +++ b/tests/Unit/ExtensionsUnitTest.php @@ -23,13 +23,12 @@ use stdClass; /** - * @covers \Hyde\Foundation\HydeKernel - * @covers \Hyde\Foundation\Concerns\HydeExtension - * @covers \Hyde\Foundation\Concerns\ManagesExtensions - * * @see \Hyde\Framework\Testing\Feature\HydeKernelTest * @see \Hyde\Framework\Testing\Feature\HydeExtensionFeatureTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\HydeKernel::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Concerns\HydeExtension::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Concerns\ManagesExtensions::class)] class ExtensionsUnitTest extends UnitTestCase { protected HydeKernel $kernel; diff --git a/tests/Unit/Facades/AssetFacadeUnitTest.php b/tests/Unit/Facades/AssetFacadeUnitTest.php index da5b1573..67d7c3f8 100644 --- a/tests/Unit/Facades/AssetFacadeUnitTest.php +++ b/tests/Unit/Facades/AssetFacadeUnitTest.php @@ -11,9 +11,7 @@ use Hyde\Support\Models\RenderData; use Hyde\Framework\Exceptions\FileNotFoundException; -/** - * @covers \Hyde\Facades\Asset - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Asset::class)] class AssetFacadeUnitTest extends UnitTestCase { protected function setUp(): void diff --git a/tests/Unit/Facades/AuthorFacadeTest.php b/tests/Unit/Facades/AuthorFacadeTest.php index f4e4a273..64f4e287 100644 --- a/tests/Unit/Facades/AuthorFacadeTest.php +++ b/tests/Unit/Facades/AuthorFacadeTest.php @@ -9,9 +9,7 @@ use Hyde\Framework\Features\Blogging\Models\PostAuthor; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Facades\Author - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Author::class)] class AuthorFacadeTest extends UnitTestCase { protected static bool $needsKernel = true; @@ -32,7 +30,7 @@ public function testCreate() $author = Author::create('John Doe', 'https://johndoe.com'); $this->assertIsArray($author); - $this->assertFalse(isset($author['username'])); + $this->assertArrayNotHasKey('username', $author); $this->assertSame('John Doe', $author['name']); $this->assertSame('https://johndoe.com', $author['website']); diff --git a/tests/Unit/Facades/HydeFrontFacadeTest.php b/tests/Unit/Facades/HydeFrontFacadeTest.php index e3f42381..6b809334 100644 --- a/tests/Unit/Facades/HydeFrontFacadeTest.php +++ b/tests/Unit/Facades/HydeFrontFacadeTest.php @@ -8,9 +8,7 @@ use Hyde\Facades\HydeFront; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Facades\HydeFront - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\HydeFront::class)] class HydeFrontFacadeTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/Facades/NavigationFacadeTest.php b/tests/Unit/Facades/NavigationFacadeTest.php index 7ece76bd..b53312c6 100644 --- a/tests/Unit/Facades/NavigationFacadeTest.php +++ b/tests/Unit/Facades/NavigationFacadeTest.php @@ -7,9 +7,7 @@ use Hyde\Facades\Navigation; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Facades\Navigation - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Navigation::class)] class NavigationFacadeTest extends UnitTestCase { public function testItemWithoutLabel() diff --git a/tests/Unit/Facades/RouteFacadeTest.php b/tests/Unit/Facades/RouteFacadeTest.php index e1018322..05560114 100644 --- a/tests/Unit/Facades/RouteFacadeTest.php +++ b/tests/Unit/Facades/RouteFacadeTest.php @@ -12,9 +12,7 @@ use Hyde\Support\Models\Route; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Foundation\Facades\Routes - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Facades\Routes::class)] class RouteFacadeTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/Facades/ViteFacadeTest.php b/tests/Unit/Facades/ViteFacadeTest.php index 6e79e286..b0666bc3 100644 --- a/tests/Unit/Facades/ViteFacadeTest.php +++ b/tests/Unit/Facades/ViteFacadeTest.php @@ -10,9 +10,7 @@ use Illuminate\Support\HtmlString; use InvalidArgumentException; -/** - * @covers \Hyde\Facades\Vite - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Vite::class)] class ViteFacadeTest extends UnitTestCase { use CreatesTemporaryFiles; @@ -105,9 +103,7 @@ public function testAssetsMethodGeneratesCorrectHtmlForMultipleFiles() $this->assertSame($expected, (string) $html); } - /** - * @dataProvider cssFileExtensionsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('cssFileExtensionsProvider')] public function testAssetsMethodSupportsAllCssFileExtensions(string $extension) { $html = Vite::assets(["resources/css/app.$extension"]); @@ -122,9 +118,7 @@ public function testAssetsMethodSupportsAllCssFileExtensions(string $extension) } } - /** - * @dataProvider jsFileExtensionsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('jsFileExtensionsProvider')] public function testAssetsMethodSupportsAllJsFileExtensions(string $extension) { $html = Vite::assets(["resources/js/app.$extension"]); @@ -162,29 +156,25 @@ public function testAssetMethodGeneratesCorrectHtmlForCssFile() $this->assertSame($expected, (string) $html); } - public static function cssFileExtensionsProvider(): array + public static function cssFileExtensionsProvider(): \Iterator { - return [ - ['css'], - ['less'], - ['sass'], - ['scss'], - ['styl'], - ['stylus'], - ['pcss'], - ['postcss'], - ['js'], - ]; + yield ['css']; + yield ['less']; + yield ['sass']; + yield ['scss']; + yield ['styl']; + yield ['stylus']; + yield ['pcss']; + yield ['postcss']; + yield ['js']; } - public static function jsFileExtensionsProvider(): array + public static function jsFileExtensionsProvider(): \Iterator { - return [ - ['js'], - ['jsx'], - ['ts'], - ['tsx'], - ['css'], - ]; + yield ['js']; + yield ['jsx']; + yield ['ts']; + yield ['tsx']; + yield ['css']; } } diff --git a/tests/Unit/FeatureEnumTest.php b/tests/Unit/FeatureEnumTest.php index bb1ee28d..033ad0cd 100644 --- a/tests/Unit/FeatureEnumTest.php +++ b/tests/Unit/FeatureEnumTest.php @@ -7,9 +7,7 @@ use Hyde\Testing\UnitTestCase; use Hyde\Enums\Feature; -/** - * @covers \Hyde\Enums\Feature - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Enums\Feature::class)] class FeatureEnumTest extends UnitTestCase { public function testEnumCases() diff --git a/tests/Unit/FeaturedImageUnitTest.php b/tests/Unit/FeaturedImageUnitTest.php index 26ab3ffc..285cc1ab 100644 --- a/tests/Unit/FeaturedImageUnitTest.php +++ b/tests/Unit/FeaturedImageUnitTest.php @@ -11,10 +11,9 @@ use Hyde\Testing\UnitTestCase; /** - * @covers \Hyde\Framework\Features\Blogging\Models\FeaturedImage - * * @see \Hyde\Framework\Testing\Feature\FeaturedImageTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Blogging\Models\FeaturedImage::class)] class FeaturedImageUnitTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/FileConflictExceptionTest.php b/tests/Unit/FileConflictExceptionTest.php index 13116df2..c46d99e6 100644 --- a/tests/Unit/FileConflictExceptionTest.php +++ b/tests/Unit/FileConflictExceptionTest.php @@ -8,9 +8,7 @@ use Hyde\Framework\Exceptions\FileConflictException; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Framework\Exceptions\FileConflictException - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\FileConflictException::class)] class FileConflictExceptionTest extends UnitTestCase { public function testItCanBeInstantiated() diff --git a/tests/Unit/FileFinderTest.php b/tests/Unit/FileFinderTest.php index fadf155d..1602a79f 100644 --- a/tests/Unit/FileFinderTest.php +++ b/tests/Unit/FileFinderTest.php @@ -9,9 +9,7 @@ use Hyde\Testing\CreatesTemporaryFiles; use Hyde\Foundation\Kernel\Filesystem; -/** - * @covers \Hyde\Framework\Actions\Internal\FileFinder - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\Internal\FileFinder::class)] class FileFinderTest extends UnitTestCase { use CreatesTemporaryFiles; diff --git a/tests/Unit/FilesystemFacadeMimeTypeHelperUnitTest.php b/tests/Unit/FilesystemFacadeMimeTypeHelperUnitTest.php index d6dbf8d4..45a7b83f 100644 --- a/tests/Unit/FilesystemFacadeMimeTypeHelperUnitTest.php +++ b/tests/Unit/FilesystemFacadeMimeTypeHelperUnitTest.php @@ -6,25 +6,20 @@ use Hyde\Testing\UnitTestCase; /** - * @covers \Hyde\Facades\Filesystem - * * @see \Hyde\Framework\Testing\Feature\FilesystemFacadeTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Filesystem::class)] class FilesystemFacadeMimeTypeHelperUnitTest extends UnitTestCase { protected static bool $needsKernel = true; - /** - * @dataProvider mimeTypeProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('mimeTypeProvider')] public function testFindMimeTypeWithKnownExtensions(string $extension, string $expectedMimeType) { $this->assertSame($expectedMimeType, Filesystem::findMimeType("file.$extension")); } - /** - * @dataProvider mimeTypeProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('mimeTypeProvider')] public function testFindMimeTypeWithRemoteUrls(string $extension, string $expectedMimeType) { $this->assertSame($expectedMimeType, Filesystem::findMimeType("https://example.com/file.$extension")); @@ -60,21 +55,19 @@ public function testFindMimeTypeWithCaseSensitivity() $this->assertSame('text/plain', Filesystem::findMimeType('file.TXT')); } - public static function mimeTypeProvider(): array + public static function mimeTypeProvider(): \Iterator { - return [ - ['txt', 'text/plain'], - ['md', 'text/markdown'], - ['html', 'text/html'], - ['css', 'text/css'], - ['svg', 'image/svg+xml'], - ['png', 'image/png'], - ['jpg', 'image/jpeg'], - ['jpeg', 'image/jpeg'], - ['gif', 'image/gif'], - ['json', 'application/json'], - ['js', 'application/javascript'], - ['xml', 'application/xml'], - ]; + yield ['txt', 'text/plain']; + yield ['md', 'text/markdown']; + yield ['html', 'text/html']; + yield ['css', 'text/css']; + yield ['svg', 'image/svg+xml']; + yield ['png', 'image/png']; + yield ['jpg', 'image/jpeg']; + yield ['jpeg', 'image/jpeg']; + yield ['gif', 'image/gif']; + yield ['json', 'application/json']; + yield ['js', 'application/javascript']; + yield ['xml', 'application/xml']; } } diff --git a/tests/Unit/FilesystemFacadeUnitTest.php b/tests/Unit/FilesystemFacadeUnitTest.php index 8aa29c7b..f196a482 100644 --- a/tests/Unit/FilesystemFacadeUnitTest.php +++ b/tests/Unit/FilesystemFacadeUnitTest.php @@ -11,12 +11,11 @@ use Illuminate\Support\LazyCollection; /** - * @covers \Hyde\Facades\Filesystem - * @covers \Hyde\Foundation\Kernel\Filesystem - * @covers \Hyde\Framework\Concerns\Internal\ForwardsIlluminateFilesystem - * * @see \Hyde\Framework\Testing\Feature\FilesystemFacadeTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Filesystem::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\Filesystem::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Concerns\Internal\ForwardsIlluminateFilesystem::class)] class FilesystemFacadeUnitTest extends UnitTestCase { protected static bool $needsKernel = true; @@ -334,6 +333,23 @@ public function testEnsureDirectoryExists() Filesystem::ensureDirectoryExists('path'); } + public function testEnsureParentDirectoryExists() + { + $mock = $this->mockFilesystem(); + + $mock->shouldReceive('dirname') + ->with(Hyde::path('file.txt')) + ->once() + ->andReturn(Hyde::path('parent')); + + $mock->shouldReceive('ensureDirectoryExists') + ->with(Hyde::path('parent'), 0755, true) + ->once() + ->andReturnNull(); + + Filesystem::ensureParentDirectoryExists('file.txt'); + } + public function testMakeDirectory() { $this->createExpectation('makeDirectory', true, Hyde::path('path')); diff --git a/tests/Unit/Foundation/FilesystemHasMediaFilesTest.php b/tests/Unit/Foundation/FilesystemHasMediaFilesTest.php index 3f079d98..edfd66b8 100644 --- a/tests/Unit/Foundation/FilesystemHasMediaFilesTest.php +++ b/tests/Unit/Foundation/FilesystemHasMediaFilesTest.php @@ -14,9 +14,7 @@ use Illuminate\Filesystem\Filesystem as BaseFilesystem; use Mockery\MockInterface; -/** - * @covers \Hyde\Foundation\Kernel\Filesystem - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\Filesystem::class)] class FilesystemHasMediaFilesTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php b/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php index 4aa4af46..805c346c 100644 --- a/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php +++ b/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php @@ -11,9 +11,7 @@ use Illuminate\View\Factory; use Mockery; -/** - * @covers \Hyde\Foundation\Kernel\Hyperlinks::relativeLink - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\Hyperlinks::class)] class HyperlinkFileHelperRelativeLinkTest extends UnitTestCase { use InteractsWithPages; diff --git a/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php b/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php index 3151a977..930db701 100644 --- a/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php +++ b/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php @@ -7,9 +7,7 @@ use Hyde\Hyde; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Foundation\Kernel\Hyperlinks::formatLink - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\Hyperlinks::class)] class HyperlinkFormatHtmlPathTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php b/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php index fa7ed72f..6791e42e 100644 --- a/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php +++ b/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php @@ -10,9 +10,7 @@ use Hyde\Testing\FluentTestingHelpers; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Foundation\Kernel\Hyperlinks - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Kernel\Hyperlinks::class)] class HyperlinksUrlPathHelpersTest extends UnitTestCase { use FluentTestingHelpers; diff --git a/tests/Unit/FoundationFacadesTest.php b/tests/Unit/FoundationFacadesTest.php index fa56fe07..cf743262 100644 --- a/tests/Unit/FoundationFacadesTest.php +++ b/tests/Unit/FoundationFacadesTest.php @@ -13,11 +13,9 @@ use Hyde\Foundation\HydeKernel; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Foundation\Facades\Files - * @covers \Hyde\Foundation\Facades\Pages - * @covers \Hyde\Foundation\Facades\Routes - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Facades\Files::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Facades\Pages::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Facades\Routes::class)] class FoundationFacadesTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/FrontMatterModelTest.php b/tests/Unit/FrontMatterModelTest.php index 09e6c134..a2e0a000 100644 --- a/tests/Unit/FrontMatterModelTest.php +++ b/tests/Unit/FrontMatterModelTest.php @@ -7,9 +7,7 @@ use Hyde\Markdown\Models\FrontMatter; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Markdown\Models\FrontMatter - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Models\FrontMatter::class)] class FrontMatterModelTest extends UnitTestCase { public function testConstructorCreatesNewFrontMatterModel() diff --git a/tests/Unit/GenerateBuildManifestTest.php b/tests/Unit/GenerateBuildManifestTest.php index 8b2ec50c..88b3800d 100644 --- a/tests/Unit/GenerateBuildManifestTest.php +++ b/tests/Unit/GenerateBuildManifestTest.php @@ -10,9 +10,7 @@ use function Hyde\unixsum_file; -/** - * @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateBuildManifest - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\PostBuildTasks\GenerateBuildManifest::class)] class GenerateBuildManifestTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/GeneratesSidebarTableOfContentsTest.php b/tests/Unit/GeneratesSidebarTableOfContentsTest.php index e340e1bf..0b0b30ed 100644 --- a/tests/Unit/GeneratesSidebarTableOfContentsTest.php +++ b/tests/Unit/GeneratesSidebarTableOfContentsTest.php @@ -10,10 +10,9 @@ use Hyde\Testing\UnitTestCase; /** - * @covers \Hyde\Framework\Actions\GeneratesTableOfContents - * * @see \Hyde\Framework\Testing\Feature\Views\SidebarTableOfContentsViewTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Actions\GeneratesTableOfContents::class)] class GeneratesSidebarTableOfContentsTest extends UnitTestCase { protected static bool $needsConfig = true; diff --git a/tests/Unit/HeadingRendererUnitTest.php b/tests/Unit/HeadingRendererUnitTest.php index 3724f0f2..e6e271e0 100644 --- a/tests/Unit/HeadingRendererUnitTest.php +++ b/tests/Unit/HeadingRendererUnitTest.php @@ -16,10 +16,9 @@ use Mockery; /** - * @covers \Hyde\Markdown\Processing\HeadingRenderer - * * @see \Hyde\Framework\Testing\Feature\MarkdownHeadingRendererTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Processing\HeadingRenderer::class)] class HeadingRendererUnitTest extends UnitTestCase { use UsesRealBladeInUnitTests; @@ -234,17 +233,13 @@ public function testPostProcessHandlesNoHeadingTags() $this->assertSame('

Paragraph

', (new HeadingRenderer())->postProcess($html)); } - /** - * @dataProvider headingIdentifierProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('headingIdentifierProvider')] public function testHeadingIdentifierGeneration($input, $expected) { $this->assertSame($expected, HeadingRenderer::makeIdentifier($input)); } - /** - * @dataProvider headingIdentifierProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('headingIdentifierProvider')] public function testHeadingIdentifierGenerationWithEscapedInput($input, $expected) { $this->assertSame(HeadingRenderer::makeIdentifier($input), HeadingRenderer::makeIdentifier(e($input))); @@ -274,43 +269,37 @@ protected function validateHeadingPermalinkStates(HeadingRenderer $renderer, Chi } } - public static function headingIdentifierProvider(): array + public static function headingIdentifierProvider(): \Iterator { - return [ - // Basic cases - ['Hello World', 'hello-world'], - ['Simple Heading', 'simple-heading'], - ['Heading With Numbers 123', 'heading-with-numbers-123'], - - // Special characters - ['Heading with & symbol', 'heading-with-and-symbol'], - ['Heading with < > symbols', 'heading-with-symbols'], - ['Heading with "quotes"', 'heading-with-quotes'], - ['Heading with / and \\', 'heading-with-and'], - ['Heading with punctuation!?!', 'heading-with-punctuation'], - ['Hyphenated-heading-name', 'hyphenated-heading-name'], - - // Emojis - ['Heading with emoji 🎉', 'heading-with-emoji'], - ['Another emoji 🤔 test', 'another-emoji-test'], - ['Multiple emojis 🎉🤔✨', 'multiple-emojis'], - - // Accented and non-ASCII characters - ['Accented é character', 'accented-e-character'], - ['Café Crème', 'cafe-creme'], - ['Łódź and święto', 'lodz-and-swieto'], - ['中文标题', 'zhong-wen-biao-ti'], - ['日本語の見出し', 'ri-ben-yu-nojian-chu-shi'], - ['한국어 제목', 'hangugeo-jemog'], - - // Edge cases - [' Leading spaces', 'leading-spaces'], - ['Trailing spaces ', 'trailing-spaces'], - [' Surrounded by spaces ', 'surrounded-by-spaces'], - ['----', ''], - ['%%%%%%%', ''], - [' ', ''], - ['1234567890', '1234567890'], - ]; + // Basic cases + yield ['Hello World', 'hello-world']; + yield ['Simple Heading', 'simple-heading']; + yield ['Heading With Numbers 123', 'heading-with-numbers-123']; + // Special characters + yield ['Heading with & symbol', 'heading-with-and-symbol']; + yield ['Heading with < > symbols', 'heading-with-symbols']; + yield ['Heading with "quotes"', 'heading-with-quotes']; + yield ['Heading with / and \\', 'heading-with-and']; + yield ['Heading with punctuation!?!', 'heading-with-punctuation']; + yield ['Hyphenated-heading-name', 'hyphenated-heading-name']; + // Emojis + yield ['Heading with emoji 🎉', 'heading-with-emoji']; + yield ['Another emoji 🤔 test', 'another-emoji-test']; + yield ['Multiple emojis 🎉🤔✨', 'multiple-emojis']; + // Accented and non-ASCII characters + yield ['Accented é character', 'accented-e-character']; + yield ['Café Crème', 'cafe-creme']; + yield ['Łódź and święto', 'lodz-and-swieto']; + yield ['中文标题', 'zhong-wen-biao-ti']; + yield ['日本語の見出し', 'ri-ben-yu-nojian-chu-shi']; + yield ['한국어 제목', 'hangugeo-jemog']; + // Edge cases + yield [' Leading spaces', 'leading-spaces']; + yield ['Trailing spaces ', 'trailing-spaces']; + yield [' Surrounded by spaces ', 'surrounded-by-spaces']; + yield ['----', '']; + yield ['%%%%%%%', '']; + yield [' ', '']; + yield ['1234567890', '1234567890']; } } diff --git a/tests/Unit/HtmlTestingSupportMetaTest.php b/tests/Unit/HtmlTestingSupportMetaTest.php index 3c109d74..bdec65b7 100644 --- a/tests/Unit/HtmlTestingSupportMetaTest.php +++ b/tests/Unit/HtmlTestingSupportMetaTest.php @@ -20,9 +20,8 @@ * * @see \Hyde\Testing\Support\TestView * @see \Hyde\Testing\Support\HtmlTesting - * - * @coversNothing */ +#[\PHPUnit\Framework\Attributes\CoversNothing] class HtmlTestingSupportMetaTest extends UnitTestCase { use TestsBladeViews; diff --git a/tests/Unit/HydeBasePathCanBeChangedTest.php b/tests/Unit/HydeBasePathCanBeChangedTest.php index c4e266e5..bc6fc742 100644 --- a/tests/Unit/HydeBasePathCanBeChangedTest.php +++ b/tests/Unit/HydeBasePathCanBeChangedTest.php @@ -7,11 +7,7 @@ use Hyde\Hyde; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Foundation\HydeKernel::getBasePath - * @covers \Hyde\Foundation\HydeKernel::setBasePath - * @covers \Hyde\Foundation\HydeKernel::path - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\HydeKernel::class)] class HydeBasePathCanBeChangedTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/HydeConfigFilesAreMatchingTest.php b/tests/Unit/HydeConfigFilesAreMatchingTest.php index 5a692548..4796af57 100644 --- a/tests/Unit/HydeConfigFilesAreMatchingTest.php +++ b/tests/Unit/HydeConfigFilesAreMatchingTest.php @@ -49,8 +49,8 @@ public function testMarkdownConfigFilesAreMatching() protected function assertFileEqualsIgnoringNewlineType(string $expected, string $actual): void { - static::assertFileExists($expected); - static::assertFileExists($actual); + $this->assertFileExists($expected); + $this->assertFileExists($actual); $this->assertSame(file_get_contents($expected), file_get_contents($actual)); } diff --git a/tests/Unit/HydeFileHelpersTest.php b/tests/Unit/HydeFileHelpersTest.php index d373c9b2..b3a45abc 100644 --- a/tests/Unit/HydeFileHelpersTest.php +++ b/tests/Unit/HydeFileHelpersTest.php @@ -12,9 +12,7 @@ use Hyde\Support\Facades\Render; use Illuminate\Support\Facades\View; -/** - * @covers \Hyde\Foundation\HydeKernel - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\HydeKernel::class)] class HydeFileHelpersTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/HydeGetBasePathHasFallbackTest.php b/tests/Unit/HydeGetBasePathHasFallbackTest.php index 32de083a..64d9da9c 100644 --- a/tests/Unit/HydeGetBasePathHasFallbackTest.php +++ b/tests/Unit/HydeGetBasePathHasFallbackTest.php @@ -7,9 +7,7 @@ use Hyde\Hyde; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Foundation\HydeKernel::getBasePath - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\HydeKernel::class)] class HydeGetBasePathHasFallbackTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/HydeHelperFacadeMakeSlugTest.php b/tests/Unit/HydeHelperFacadeMakeSlugTest.php index 0d1279cc..75c271e7 100644 --- a/tests/Unit/HydeHelperFacadeMakeSlugTest.php +++ b/tests/Unit/HydeHelperFacadeMakeSlugTest.php @@ -43,7 +43,7 @@ public function testMakeSlugHelperHandlesMultipleSpaces() public function testMakeSlugHelperHandlesSpecialCharacters() { - $this->assertSame('hello-world', Hyde::makeSlug('Hello & World!')); + $this->assertSame('hello-and-world', Hyde::makeSlug('Hello & World!')); } public function testMakeSlugHelperConvertsUppercaseToLowercase() @@ -111,7 +111,7 @@ public function testMakeSlugHelperHandlesComplexMixedInput() public function testMakeSlugHelperHandlesEdgeCases() { $this->assertSame('', Hyde::makeSlug('')); - $this->assertSame('at', Hyde::makeSlug('!@#$%^&*()')); + $this->assertSame('at-and', Hyde::makeSlug('!@#$%^&*()')); $this->assertSame('', Hyde::makeSlug('... ...')); $this->assertSame('multiple-dashes', Hyde::makeSlug('multiple---dashes')); } diff --git a/tests/Unit/HydeHelperFacadeTest.php b/tests/Unit/HydeHelperFacadeTest.php index f8b5d2df..3a16fa04 100644 --- a/tests/Unit/HydeHelperFacadeTest.php +++ b/tests/Unit/HydeHelperFacadeTest.php @@ -9,9 +9,7 @@ use Hyde\Hyde; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Foundation\HydeKernel - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\HydeKernel::class)] class HydeHelperFacadeTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/HydePageDataFactoryTest.php b/tests/Unit/HydePageDataFactoryTest.php index 4590a54a..65b26353 100644 --- a/tests/Unit/HydePageDataFactoryTest.php +++ b/tests/Unit/HydePageDataFactoryTest.php @@ -11,9 +11,7 @@ use Hyde\Pages\MarkdownPage; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Framework\Factories\HydePageDataFactory - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\HydePageDataFactory::class)] class HydePageDataFactoryTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/HydePageSerializableUnitTest.php b/tests/Unit/HydePageSerializableUnitTest.php index 149e184d..17c84d87 100644 --- a/tests/Unit/HydePageSerializableUnitTest.php +++ b/tests/Unit/HydePageSerializableUnitTest.php @@ -12,14 +12,12 @@ use Hyde\Pages\MarkdownPost; use Hyde\Pages\DocumentationPage; -/** - * @covers \Hyde\Pages\Concerns\HydePage - * @covers \Hyde\Pages\HtmlPage - * @covers \Hyde\Pages\BladePage - * @covers \Hyde\Pages\MarkdownPage - * @covers \Hyde\Pages\MarkdownPost - * @covers \Hyde\Pages\DocumentationPage - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\Concerns\HydePage::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\HtmlPage::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\BladePage::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\MarkdownPage::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\MarkdownPost::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\DocumentationPage::class)] class HydePageSerializableUnitTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/IncludesFacadeUnitTest.php b/tests/Unit/IncludesFacadeUnitTest.php index 548132af..99834714 100644 --- a/tests/Unit/IncludesFacadeUnitTest.php +++ b/tests/Unit/IncludesFacadeUnitTest.php @@ -18,11 +18,10 @@ use Hyde\Testing\MocksKernelFeatures; /** - * @covers \Hyde\Support\Includes - * * @see \Hyde\Framework\Testing\Feature\IncludesFacadeTest */ #[AllowDynamicProperties] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Includes::class)] class IncludesFacadeUnitTest extends UnitTestCase { use MocksKernelFeatures; diff --git a/tests/Unit/InteractivePublishCommandHelperTest.php b/tests/Unit/InteractivePublishCommandHelperTest.php index 8b669e08..22198a4a 100644 --- a/tests/Unit/InteractivePublishCommandHelperTest.php +++ b/tests/Unit/InteractivePublishCommandHelperTest.php @@ -10,9 +10,7 @@ use Illuminate\Filesystem\Filesystem; use Mockery; -/** - * @covers \Hyde\Console\Helpers\InteractivePublishCommandHelper - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Console\Helpers\InteractivePublishCommandHelper::class)] class InteractivePublishCommandHelperTest extends UnitTestCase { protected static bool $needsKernel = true; @@ -69,6 +67,7 @@ public function testOnlyFiltersPublishableFiles(): void public function testPublishFiles(): void { + $this->filesystem->shouldReceive('dirname')->times(3)->andReturn(Hyde::path('resources/views/vendor/hyde/layouts')); $this->filesystem->shouldReceive('ensureDirectoryExists')->times(3); $this->filesystem->shouldReceive('copy')->times(3); @@ -80,7 +79,8 @@ public function testPublishFiles(): void $helper->publishFiles(); - $this->filesystem->shouldHaveReceived('ensureDirectoryExists')->with(Hyde::path('resources/views/vendor/hyde/layouts'))->times(3); + $this->filesystem->shouldHaveReceived('dirname')->times(3); + $this->filesystem->shouldHaveReceived('ensureDirectoryExists')->with(Hyde::path('resources/views/vendor/hyde/layouts'), 0755, true)->times(3); $this->filesystem->shouldHaveReceived('copy')->with( Hyde::path('packages/framework/resources/views/layouts/app.blade.php'), diff --git a/tests/Unit/InteractsWithDirectoriesConcernTest.php b/tests/Unit/InteractsWithDirectoriesConcernTest.php index 9d23ff0b..ca2c8778 100644 --- a/tests/Unit/InteractsWithDirectoriesConcernTest.php +++ b/tests/Unit/InteractsWithDirectoriesConcernTest.php @@ -8,9 +8,7 @@ use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Hyde; -/** - * @covers \Hyde\Framework\Concerns\InteractsWithDirectories - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Concerns\InteractsWithDirectories::class)] class InteractsWithDirectoriesConcernTest extends UnitTestCase { use InteractsWithDirectories; diff --git a/tests/Unit/LoadConfigurationTest.php b/tests/Unit/LoadConfigurationTest.php index ff3e966f..c1581ef3 100644 --- a/tests/Unit/LoadConfigurationTest.php +++ b/tests/Unit/LoadConfigurationTest.php @@ -8,11 +8,18 @@ use Hyde\Foundation\Internal\LoadConfiguration; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Foundation\Internal\LoadConfiguration - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Internal\LoadConfiguration::class)] class LoadConfigurationTest extends UnitTestCase { + public static function tearDownAfterClass(): void + { + // Patch PHPUnit craziness by disabling this method + // I don't know why it errors, but I have spent + // far too much of my life trying to fix it. + + // TODO: Check if this is broken after the Pest 4 upgrade. + } + public function testItLoadsRuntimeConfiguration() { $app = new Application(getcwd()); diff --git a/tests/Unit/MarkdownFacadeTest.php b/tests/Unit/MarkdownFacadeTest.php index 654a3e7f..c33090e7 100644 --- a/tests/Unit/MarkdownFacadeTest.php +++ b/tests/Unit/MarkdownFacadeTest.php @@ -9,9 +9,7 @@ use Hyde\Markdown\Models\Markdown; use Hyde\Framework\Services\MarkdownService; -/** - * @covers \Hyde\Markdown\Models\Markdown - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Models\Markdown::class)] class MarkdownFacadeTest extends UnitTestCase { public function testRender(): void @@ -27,4 +25,13 @@ public function testRender(): void $this->verifyMockeryExpectations(); } + + public static function tearDownAfterClass(): void + { + // Patch PHPUnit craziness by disabling this method + // I don't know why it errors, but I have spent + // far too much of my life trying to fix it. + + // TODO: Check if this is broken after the Pest 4 upgrade. + } } diff --git a/tests/Unit/MarkdownHelpersTest.php b/tests/Unit/MarkdownHelpersTest.php index 963a9714..711e630f 100644 --- a/tests/Unit/MarkdownHelpersTest.php +++ b/tests/Unit/MarkdownHelpersTest.php @@ -11,10 +11,8 @@ use Hyde\Testing\TestCase; use Illuminate\Support\HtmlString; -/** - * @covers \Hyde\Markdown\Models\MarkdownDocument - * @covers \Hyde\Markdown\Models\Markdown - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Models\MarkdownDocument::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Markdown\Models\Markdown::class)] class MarkdownHelpersTest extends TestCase { public function testConstructorCreatesNewMarkdownDocument() diff --git a/tests/Unit/MetaFacadeTest.php b/tests/Unit/MetaFacadeTest.php index 555fc071..7ad80192 100644 --- a/tests/Unit/MetaFacadeTest.php +++ b/tests/Unit/MetaFacadeTest.php @@ -8,9 +8,7 @@ use Hyde\Framework\Features\Metadata\GlobalMetadataBag; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Facades\Meta - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Facades\Meta::class)] class MetaFacadeTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/NavigationDataFactoryUnitTest.php b/tests/Unit/NavigationDataFactoryUnitTest.php index f6ffc8e3..7f209a45 100644 --- a/tests/Unit/NavigationDataFactoryUnitTest.php +++ b/tests/Unit/NavigationDataFactoryUnitTest.php @@ -12,9 +12,7 @@ use Hyde\Framework\Factories\NavigationDataFactory; use Hyde\Framework\Factories\Concerns\CoreDataObject; -/** - * @covers \Hyde\Framework\Factories\NavigationDataFactory - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\NavigationDataFactory::class)] class NavigationDataFactoryUnitTest extends UnitTestCase { protected function setUp(): void diff --git a/tests/Unit/NavigationGroupTest.php b/tests/Unit/NavigationGroupTest.php index 2b9483c2..c66070c4 100644 --- a/tests/Unit/NavigationGroupTest.php +++ b/tests/Unit/NavigationGroupTest.php @@ -13,9 +13,7 @@ use Hyde\Framework\Features\Navigation\NavigationItem; use Hyde\Framework\Features\Navigation\NavigationGroup; -/** - * @covers \Hyde\Framework\Features\Navigation\NavigationGroup - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationGroup::class)] class NavigationGroupTest extends UnitTestCase { public static function setUpBeforeClass(): void diff --git a/tests/Unit/NavigationItemIsActiveHelperTest.php b/tests/Unit/NavigationItemIsActiveHelperTest.php index d46aa2d7..b056da7e 100644 --- a/tests/Unit/NavigationItemIsActiveHelperTest.php +++ b/tests/Unit/NavigationItemIsActiveHelperTest.php @@ -14,10 +14,9 @@ use Mockery; /** - * @covers \Hyde\Framework\Features\Navigation\NavigationItem - * * @see \Hyde\Framework\Testing\Unit\NavigationItemTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationItem::class)] class NavigationItemIsActiveHelperTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/NavigationItemTest.php b/tests/Unit/NavigationItemTest.php index 235cc81a..29dee70d 100644 --- a/tests/Unit/NavigationItemTest.php +++ b/tests/Unit/NavigationItemTest.php @@ -14,21 +14,35 @@ use Hyde\Testing\UnitTestCase; use Mockery; use Hyde\Framework\Features\Navigation\NavigationGroup; +use Illuminate\Support\Facades\Facade; /** * This unit test covers the basics of the NavigationItem class. * For the full feature test, see the MainNavigationMenuTest class. * - * @covers \Hyde\Framework\Features\Navigation\NavigationItem * * @see \Hyde\Framework\Testing\Unit\NavigationItemIsActiveHelperTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationItem::class)] class NavigationItemTest extends UnitTestCase { protected static bool $needsKernel = true; protected static bool $needsConfig = true; protected static bool $needsRender = true; + protected function setUp(): void + { + // Clear any previous render facade instances + Facade::clearResolvedInstance('render'); + } + + protected function tearDown(): void + { + // Clean up mocks after each test + Mockery::close(); + Facade::clearResolvedInstance('render'); + } + public function testConstruct() { $this->assertInstanceOf(NavigationItem::class, new NavigationItem('foo', 'Test')); @@ -110,7 +124,10 @@ public function testFromRoute() public function testToString() { - Render::shouldReceive('getRouteKey')->once()->andReturn('index'); + // Create a fresh mock for this specific test to avoid interference + $mock = Mockery::mock(RenderData::class); + $mock->shouldReceive('getRouteKey')->andReturn('index'); + Render::swap($mock); $this->assertSame('index.html', (string) NavigationItem::create(Routes::get('index'))); } diff --git a/tests/Unit/NavigationMenuUnitTest.php b/tests/Unit/NavigationMenuUnitTest.php index 8de2aba9..8358b461 100644 --- a/tests/Unit/NavigationMenuUnitTest.php +++ b/tests/Unit/NavigationMenuUnitTest.php @@ -10,12 +10,11 @@ use Hyde\Framework\Features\Navigation\MainNavigationMenu; /** - * @covers \Hyde\Framework\Features\Navigation\NavigationMenu - * @covers \Hyde\Framework\Features\Navigation\MainNavigationMenu - * * @see \Hyde\Framework\Testing\Feature\NavigationMenuTest * @see \Hyde\Framework\Testing\Unit\DocumentationSidebarUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NavigationMenu::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\MainNavigationMenu::class)] class NavigationMenuUnitTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/NumericalPageOrderingHelperUnitTest.php b/tests/Unit/NumericalPageOrderingHelperUnitTest.php index b9fb2073..f317b106 100644 --- a/tests/Unit/NumericalPageOrderingHelperUnitTest.php +++ b/tests/Unit/NumericalPageOrderingHelperUnitTest.php @@ -9,10 +9,9 @@ use Hyde\Framework\Features\Navigation\NumericalPageOrderingHelper; /** - * @covers \Hyde\Framework\Features\Navigation\NumericalPageOrderingHelper - * * @see \Hyde\Framework\Testing\Feature\NumericalPageOrderingHelperTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Navigation\NumericalPageOrderingHelper::class)] class NumericalPageOrderingHelperUnitTest extends UnitTestCase { protected static bool $needsConfig = true; @@ -124,9 +123,8 @@ public function testIdentifiersForDeeplyNestedPagesWithoutNumericalPrefixesAreNo /** * @param class-string<\Hyde\Pages\Concerns\HydePage> $type - * - * @dataProvider pageTypeProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('pageTypeProvider')] public function testIdentifiersWithNumericalPrefixesAreDetectedForPageType(string $type) { $this->assertTrue(NumericalPageOrderingHelper::hasNumericalPrefix('01-home.'.$type::$fileExtension)); @@ -136,9 +134,8 @@ public function testIdentifiersWithNumericalPrefixesAreDetectedForPageType(strin /** * @param class-string<\Hyde\Pages\Concerns\HydePage> $type - * - * @dataProvider pageTypeProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('pageTypeProvider')] public function testIdentifiersWithoutNumericalPrefixesAreNotDetectedForPageType(string $type) { $this->assertFalse(NumericalPageOrderingHelper::hasNumericalPrefix('home.'.$type::$fileExtension)); @@ -148,9 +145,8 @@ public function testIdentifiersWithoutNumericalPrefixesAreNotDetectedForPageType /** * @param class-string<\Hyde\Pages\Concerns\HydePage> $type - * - * @dataProvider pageTypeProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('pageTypeProvider')] public function testIdentifiersWithNumericalPrefixesAreDetectedWhenUsingSnakeCaseDelimitersForPageType(string $type) { $this->assertTrue(NumericalPageOrderingHelper::hasNumericalPrefix('01_home.'.$type::$fileExtension)); @@ -160,9 +156,8 @@ public function testIdentifiersWithNumericalPrefixesAreDetectedWhenUsingSnakeCas /** * @param class-string<\Hyde\Pages\Concerns\HydePage> $type - * - * @dataProvider pageTypeProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('pageTypeProvider')] public function testSplitNumericPrefixForDeeplyNestedPagesForPageType(string $type) { $this->assertSame([1, 'foo/bar/home.'.$type::$fileExtension], NumericalPageOrderingHelper::splitNumericPrefix('foo/bar/01-home.'.$type::$fileExtension)); diff --git a/tests/Unit/PageModelParsingTest.php b/tests/Unit/PageModelParsingTest.php index e50175a1..358b91ca 100644 --- a/tests/Unit/PageModelParsingTest.php +++ b/tests/Unit/PageModelParsingTest.php @@ -11,13 +11,12 @@ /** * Test the constructor actions and schema constructors for page models. - * - * @covers \Hyde\Framework\Factories\Concerns\HasFactory - * @covers \Hyde\Framework\Factories\NavigationDataFactory - * @covers \Hyde\Framework\Factories\FeaturedImageFactory - * @covers \Hyde\Framework\Factories\HydePageDataFactory - * @covers \Hyde\Framework\Factories\BlogPostDataFactory */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\Concerns\HasFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\NavigationDataFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\FeaturedImageFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\HydePageDataFactory::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Factories\BlogPostDataFactory::class)] class PageModelParsingTest extends UnitTestCase { use CreatesTemporaryFiles; diff --git a/tests/Unit/Pages/BladePageUnitTest.php b/tests/Unit/Pages/BladePageUnitTest.php index 14cec200..0e8ea4b2 100644 --- a/tests/Unit/Pages/BladePageUnitTest.php +++ b/tests/Unit/Pages/BladePageUnitTest.php @@ -13,9 +13,7 @@ use Hyde\Framework\Features\Metadata\PageMetadataBag; use Hyde\Framework\Factories\Concerns\CoreDataObject; -/** - * @covers \Hyde\Pages\BladePage - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\BladePage::class)] class BladePageUnitTest extends BaseHydePageUnitTest { public function testSourceDirectory() diff --git a/tests/Unit/Pages/DocumentationPageUnitTest.php b/tests/Unit/Pages/DocumentationPageUnitTest.php index bc727ef4..3e37ce76 100644 --- a/tests/Unit/Pages/DocumentationPageUnitTest.php +++ b/tests/Unit/Pages/DocumentationPageUnitTest.php @@ -15,9 +15,7 @@ use Hyde\Framework\Factories\Concerns\CoreDataObject; use Hyde\Framework\Features\Metadata\PageMetadataBag; -/** - * @covers \Hyde\Pages\DocumentationPage - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\DocumentationPage::class)] class DocumentationPageUnitTest extends BaseMarkdownPageUnitTest { public function testSourceDirectory() diff --git a/tests/Unit/Pages/HtmlPageTest.php b/tests/Unit/Pages/HtmlPageTest.php index f976cb44..8bcd46e4 100644 --- a/tests/Unit/Pages/HtmlPageTest.php +++ b/tests/Unit/Pages/HtmlPageTest.php @@ -7,9 +7,7 @@ use Hyde\Pages\HtmlPage; use Hyde\Testing\TestCase; -/** - * @covers \Hyde\Pages\HtmlPage - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\HtmlPage::class)] class HtmlPageTest extends TestCase { public function testHtmlPageCanBeCompiled() diff --git a/tests/Unit/Pages/HtmlPageUnitTest.php b/tests/Unit/Pages/HtmlPageUnitTest.php index 4603f594..0838e934 100644 --- a/tests/Unit/Pages/HtmlPageUnitTest.php +++ b/tests/Unit/Pages/HtmlPageUnitTest.php @@ -13,9 +13,7 @@ use Hyde\Framework\Features\Metadata\PageMetadataBag; use Hyde\Framework\Factories\Concerns\CoreDataObject; -/** - * @covers \Hyde\Pages\HtmlPage - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\HtmlPage::class)] class HtmlPageUnitTest extends BaseHydePageUnitTest { public function testSourceDirectory() diff --git a/tests/Unit/Pages/InMemoryPageTest.php b/tests/Unit/Pages/InMemoryPageTest.php index 5ae1ccce..42aef71f 100644 --- a/tests/Unit/Pages/InMemoryPageTest.php +++ b/tests/Unit/Pages/InMemoryPageTest.php @@ -9,10 +9,9 @@ use Hyde\Testing\TestCase; /** - * @covers \Hyde\Pages\InMemoryPage - * * @see \Hyde\Framework\Testing\Unit\Pages\InMemoryPageUnitTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\InMemoryPage::class)] class InMemoryPageTest extends TestCase { public function testConstructWithContentsString() diff --git a/tests/Unit/Pages/InMemoryPageUnitTest.php b/tests/Unit/Pages/InMemoryPageUnitTest.php index acfb0da0..ed76a546 100644 --- a/tests/Unit/Pages/InMemoryPageUnitTest.php +++ b/tests/Unit/Pages/InMemoryPageUnitTest.php @@ -15,10 +15,9 @@ use Hyde\Framework\Factories\Concerns\CoreDataObject; /** - * @covers \Hyde\Pages\InMemoryPage - * * @see \Hyde\Framework\Testing\Unit\Pages\InMemoryPageTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\InMemoryPage::class)] class InMemoryPageUnitTest extends BaseHydePageUnitTest { public function testSourceDirectory() diff --git a/tests/Unit/Pages/MarkdownPageUnitTest.php b/tests/Unit/Pages/MarkdownPageUnitTest.php index 1c45d018..2401f58e 100644 --- a/tests/Unit/Pages/MarkdownPageUnitTest.php +++ b/tests/Unit/Pages/MarkdownPageUnitTest.php @@ -15,9 +15,7 @@ use Hyde\Framework\Factories\Concerns\CoreDataObject; use Hyde\Framework\Features\Metadata\PageMetadataBag; -/** - * @covers \Hyde\Pages\MarkdownPage - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\MarkdownPage::class)] class MarkdownPageUnitTest extends BaseMarkdownPageUnitTest { public function testSourceDirectory() diff --git a/tests/Unit/Pages/MarkdownPostParserTest.php b/tests/Unit/Pages/MarkdownPostParserTest.php index 8c933156..0dc3c2c2 100644 --- a/tests/Unit/Pages/MarkdownPostParserTest.php +++ b/tests/Unit/Pages/MarkdownPostParserTest.php @@ -44,8 +44,8 @@ public function testCanParseMarkdownFile() $this->assertInstanceOf(Markdown::class, $post->markdown); $this->assertIsString($post->markdown->body()); $this->assertIsString($post->identifier); - $this->assertTrue(strlen((string) $post->markdown) > 32); - $this->assertTrue(strlen($post->identifier) > 8); + $this->assertGreaterThan(32, strlen((string) $post->markdown)); + $this->assertGreaterThan(8, strlen($post->identifier)); } public function testParsedMarkdownPostContainsValidFrontMatter() diff --git a/tests/Unit/Pages/MarkdownPostUnitTest.php b/tests/Unit/Pages/MarkdownPostUnitTest.php index 7768d9c2..bd72a040 100644 --- a/tests/Unit/Pages/MarkdownPostUnitTest.php +++ b/tests/Unit/Pages/MarkdownPostUnitTest.php @@ -15,9 +15,7 @@ use Hyde\Framework\Factories\Concerns\CoreDataObject; use Hyde\Framework\Features\Metadata\PageMetadataBag; -/** - * @covers \Hyde\Pages\MarkdownPost - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\MarkdownPost::class)] class MarkdownPostUnitTest extends BaseMarkdownPageUnitTest { public function testSourceDirectory() diff --git a/tests/Unit/Pages/PageModelGetFileHelpersTest.php b/tests/Unit/Pages/PageModelGetFileHelpersTest.php index 0586b311..0c632b55 100644 --- a/tests/Unit/Pages/PageModelGetFileHelpersTest.php +++ b/tests/Unit/Pages/PageModelGetFileHelpersTest.php @@ -27,7 +27,7 @@ public function testBladePageFilesHelperReturnsBladePageArray() $array = BladePage::files(); $this->assertCount(3, $array); $this->assertIsArray($array); - $this->assertEquals(['404', 'index', 'test-page'], $array); + $this->assertSame(['404', 'index', 'test-page'], $array); } public function testMarkdownPageFilesHelperReturnsMarkdownPageArray() @@ -37,7 +37,7 @@ public function testMarkdownPageFilesHelperReturnsMarkdownPageArray() $array = MarkdownPage::files(); $this->assertCount(1, $array); $this->assertIsArray($array); - $this->assertEquals(['test-page'], $array); + $this->assertSame(['test-page'], $array); } public function testMarkdownPostFilesHelperReturnsMarkdownPostArray() @@ -47,7 +47,7 @@ public function testMarkdownPostFilesHelperReturnsMarkdownPostArray() $array = MarkdownPost::files(); $this->assertCount(1, $array); $this->assertIsArray($array); - $this->assertEquals(['test-post'], $array); + $this->assertSame(['test-post'], $array); } public function testDocumentationPageFilesHelperReturnsDocumentationPageArray() @@ -57,7 +57,7 @@ public function testDocumentationPageFilesHelperReturnsDocumentationPageArray() $array = DocumentationPage::files(); $this->assertCount(1, $array); $this->assertIsArray($array); - $this->assertEquals(['test-page'], $array); + $this->assertSame(['test-page'], $array); } public function testBladePageAllHelperReturnsBladePageCollection() diff --git a/tests/Unit/Pages/PageModelParseHelperTest.php b/tests/Unit/Pages/PageModelParseHelperTest.php index 885a35a8..f1c69e00 100644 --- a/tests/Unit/Pages/PageModelParseHelperTest.php +++ b/tests/Unit/Pages/PageModelParseHelperTest.php @@ -11,9 +11,7 @@ use Hyde\Pages\MarkdownPost; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Pages\Concerns\HydePage::parse - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Pages\Concerns\HydePage::class)] class PageModelParseHelperTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/PostAuthorTest.php b/tests/Unit/PostAuthorTest.php index f7ad7902..d182c54d 100644 --- a/tests/Unit/PostAuthorTest.php +++ b/tests/Unit/PostAuthorTest.php @@ -13,10 +13,8 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Config; -/** - * @covers \Hyde\Framework\Features\Blogging\Models\PostAuthor - * @covers \Hyde\Foundation\Concerns\HasKernelData - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Features\Blogging\Models\PostAuthor::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Foundation\Concerns\HasKernelData::class)] class PostAuthorTest extends UnitTestCase { use FluentTestingHelpers; @@ -160,7 +158,7 @@ public function testFacadeCreateMethodAcceptsExtraParameters() { $author = Author::create('foo', 'https://example.com'); - $this->assertFalse(isset($author['username'])); + $this->assertArrayNotHasKey('username', $author); $this->assertSame('foo', $author['name']); $this->assertSame('https://example.com', $author['website']); } @@ -169,7 +167,7 @@ public function testFacadeCreateMethodAcceptsAllParameters() { $author = Author::create(...$this->exampleData()); - $this->assertFalse(isset($author['username'])); + $this->assertArrayNotHasKey('username', $author); $this->assertSame('Mr. Hyde', $author['name']); $this->assertSame('https://HydePHP.com', $author['website']); $this->assertSame('A mysterious figure. Is he as evil as he seems? And what did he do with Dr. Jekyll?', $author['bio']); @@ -398,7 +396,7 @@ public function testToArrayMethodReturnsArrayRepresentationOfAuthor() { $author = new PostAuthor('username', 'John Doe', 'https://example.com'); - $this->assertEquals([ + $this->assertSame([ 'username' => 'username', 'name' => 'John Doe', 'website' => 'https://example.com', @@ -409,7 +407,7 @@ public function testJsonSerializeMethodReturnsArrayRepresentationOfAuthor() { $author = new PostAuthor('username', 'John Doe', 'https://example.com'); - $this->assertEquals([ + $this->assertSame([ 'username' => 'username', 'name' => 'John Doe', 'website' => 'https://example.com', @@ -420,7 +418,7 @@ public function testArraySerializeMethodReturnsArrayRepresentationOfAuthor() { $author = new PostAuthor('username', 'John Doe', 'https://example.com'); - $this->assertEquals([ + $this->assertSame([ 'username' => 'username', 'name' => 'John Doe', 'website' => 'https://example.com', diff --git a/tests/Unit/RenderHelperTest.php b/tests/Unit/RenderHelperTest.php index e9919524..02627bbb 100644 --- a/tests/Unit/RenderHelperTest.php +++ b/tests/Unit/RenderHelperTest.php @@ -15,10 +15,8 @@ use Hyde\Support\Models\RenderData; use Illuminate\Support\Facades\View; -/** - * @covers \Hyde\Support\Models\RenderData - * @covers \Hyde\Support\Facades\Render - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Models\RenderData::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Facades\Render::class)] class RenderHelperTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/RouteKeyTest.php b/tests/Unit/RouteKeyTest.php index 7a0c107f..0eb00c91 100644 --- a/tests/Unit/RouteKeyTest.php +++ b/tests/Unit/RouteKeyTest.php @@ -13,9 +13,7 @@ use Hyde\Support\Models\RouteKey; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Support\Models\RouteKey - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Models\RouteKey::class)] class RouteKeyTest extends UnitTestCase { protected static bool $needsConfig = true; diff --git a/tests/Unit/RouteNotFoundExceptionTest.php b/tests/Unit/RouteNotFoundExceptionTest.php index caa8dea1..9e42395f 100644 --- a/tests/Unit/RouteNotFoundExceptionTest.php +++ b/tests/Unit/RouteNotFoundExceptionTest.php @@ -7,9 +7,7 @@ use Hyde\Framework\Exceptions\RouteNotFoundException; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Framework\Exceptions\RouteNotFoundException - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\RouteNotFoundException::class)] class RouteNotFoundExceptionTest extends UnitTestCase { public function testItCanBeInstantiated() diff --git a/tests/Unit/RouteTest.php b/tests/Unit/RouteTest.php index c5157cf0..b1e55ae3 100644 --- a/tests/Unit/RouteTest.php +++ b/tests/Unit/RouteTest.php @@ -10,9 +10,7 @@ use Hyde\Support\Models\RouteKey; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Support\Models\Route - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Models\Route::class)] class RouteTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/SchemaContractsTest.php b/tests/Unit/SchemaContractsTest.php index 6e83b0f1..be178855 100644 --- a/tests/Unit/SchemaContractsTest.php +++ b/tests/Unit/SchemaContractsTest.php @@ -34,39 +34,39 @@ class SchemaContractsTest extends UnitTestCase public function testSchemasAreNotAccidentallyChanged() { - $this->assertSame([ + $this->assertSame(PageSchema::PAGE_SCHEMA, [ 'title' => 'string', 'description' => 'string', 'canonicalUrl' => 'string', 'navigation' => NavigationSchema::NAVIGATION_SCHEMA, - ], PageSchema::PAGE_SCHEMA); + ]); - $this->assertSame([ + $this->assertSame(NavigationSchema::NAVIGATION_SCHEMA, [ 'label' => 'string', 'priority' => 'int', 'hidden' => 'bool', 'group' => 'string', - ], NavigationSchema::NAVIGATION_SCHEMA); + ]); - $this->assertSame([ + $this->assertSame(BlogPostSchema::BLOG_POST_SCHEMA, [ 'title' => 'string', 'description' => 'string', 'category' => 'string', 'date' => 'string', 'author' => ['string', AuthorSchema::AUTHOR_SCHEMA], 'image' => ['string', FeaturedImageSchema::FEATURED_IMAGE_SCHEMA], - ], BlogPostSchema::BLOG_POST_SCHEMA); + ]); - $this->assertSame([ + $this->assertSame(AuthorSchema::AUTHOR_SCHEMA, [ 'name' => 'string', 'username' => 'string', 'website' => 'string', 'bio' => 'string', 'avatar' => 'string', 'socials' => 'array', - ], AuthorSchema::AUTHOR_SCHEMA); + ]); - $this->assertSame([ + $this->assertSame(FeaturedImageSchema::FEATURED_IMAGE_SCHEMA, [ 'source' => 'string', 'altText' => 'string', 'alt' => 'string', @@ -77,7 +77,7 @@ public function testSchemasAreNotAccidentallyChanged() 'authorName' => 'string', 'authorUrl' => 'string', 'copyright' => 'string', - ], FeaturedImageSchema::FEATURED_IMAGE_SCHEMA); + ]); } public function testAllSchemasAreTested() diff --git a/tests/Unit/SerializableTest.php b/tests/Unit/SerializableTest.php index 021f6a4a..7b63816c 100644 --- a/tests/Unit/SerializableTest.php +++ b/tests/Unit/SerializableTest.php @@ -9,9 +9,7 @@ use Hyde\Support\Contracts\SerializableContract; use Illuminate\Contracts\Support\Arrayable; -/** - * @covers \Hyde\Support\Concerns\Serializable - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Concerns\Serializable::class)] class SerializableTest extends UnitTestCase { public function testToArray() diff --git a/tests/Unit/ServeCommandOptionsUnitTest.php b/tests/Unit/ServeCommandOptionsUnitTest.php index eeaa62b5..0f19f45e 100644 --- a/tests/Unit/ServeCommandOptionsUnitTest.php +++ b/tests/Unit/ServeCommandOptionsUnitTest.php @@ -9,16 +9,15 @@ use Hyde\Foundation\HydeKernel; use Illuminate\Process\Factory; use Illuminate\Console\OutputStyle; -use Hyde\Console\Commands\ServeCommand; +use Hyde\RealtimeCompiler\Console\Commands\ServeCommand; use Illuminate\Support\Facades\Process; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Formatter\OutputFormatterInterface; /** - * @covers \Hyde\Console\Commands\ServeCommand - * * @see \Hyde\Framework\Testing\Feature\Commands\ServeCommandTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\RealtimeCompiler\Console\Commands\ServeCommand::class)] class ServeCommandOptionsUnitTest extends UnitTestCase { protected function setUp(): void @@ -111,10 +110,10 @@ public function testSavePreviewOptionPropagatesToEnvironmentVariables() $this->assertSame('enabled', $command->getEnvironmentVariables()['HYDE_SERVER_SAVE_PREVIEW']); $command = $this->getMock(['save-preview' => null]); - $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_SERVER_SAVE_PREVIEW'])); + $this->assertArrayNotHasKey('HYDE_SERVER_SAVE_PREVIEW', $command->getEnvironmentVariables()); $command = $this->getMock(); - $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_SERVER_SAVE_PREVIEW'])); + $this->assertArrayNotHasKey('HYDE_SERVER_SAVE_PREVIEW', $command->getEnvironmentVariables()); } public function testDashboardOptionPropagatesToEnvironmentVariables() @@ -129,10 +128,10 @@ public function testDashboardOptionPropagatesToEnvironmentVariables() $this->assertSame('enabled', $command->getEnvironmentVariables()['HYDE_SERVER_DASHBOARD']); $command = $this->getMock(['dashboard' => null]); - $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_SERVER_DASHBOARD'])); + $this->assertArrayNotHasKey('HYDE_SERVER_DASHBOARD', $command->getEnvironmentVariables()); $command = $this->getMock(); - $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_SERVER_DASHBOARD'])); + $this->assertArrayNotHasKey('HYDE_SERVER_DASHBOARD', $command->getEnvironmentVariables()); } public function testPrettyUrlsOptionPropagatesToEnvironmentVariables() @@ -147,10 +146,10 @@ public function testPrettyUrlsOptionPropagatesToEnvironmentVariables() $this->assertSame('enabled', $command->getEnvironmentVariables()['HYDE_PRETTY_URLS']); $command = $this->getMock(['pretty-urls' => null]); - $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_PRETTY_URLS'])); + $this->assertArrayNotHasKey('HYDE_PRETTY_URLS', $command->getEnvironmentVariables()); $command = $this->getMock(); - $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_PRETTY_URLS'])); + $this->assertArrayNotHasKey('HYDE_PRETTY_URLS', $command->getEnvironmentVariables()); } public function testPlayCdnOptionPropagatesToEnvironmentVariables() @@ -165,10 +164,10 @@ public function testPlayCdnOptionPropagatesToEnvironmentVariables() $this->assertSame('enabled', $command->getEnvironmentVariables()['HYDE_PLAY_CDN']); $command = $this->getMock(['play-cdn' => null]); - $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_PLAY_CDN'])); + $this->assertArrayNotHasKey('HYDE_PLAY_CDN', $command->getEnvironmentVariables()); $command = $this->getMock(); - $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_PLAY_CDN'])); + $this->assertArrayNotHasKey('HYDE_PLAY_CDN', $command->getEnvironmentVariables()); } public function testParseEnvironmentOption() diff --git a/tests/Unit/Support/MediaFileUnitTest.php b/tests/Unit/Support/MediaFileUnitTest.php index 1be4b464..613c614c 100644 --- a/tests/Unit/Support/MediaFileUnitTest.php +++ b/tests/Unit/Support/MediaFileUnitTest.php @@ -16,10 +16,9 @@ use Illuminate\Filesystem\Filesystem as BaseFilesystem; /** - * @covers \Hyde\Support\Filesystem\MediaFile - * * @see \Hyde\Framework\Testing\Feature\Support\MediaFileTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Support\Filesystem\MediaFile::class)] class MediaFileUnitTest extends UnitTestCase { protected static bool $needsKernel = true; @@ -327,7 +326,7 @@ public function testGetMimeTypeReturnsTextPlainForNonExistentFile() $this->assertSame('text/plain', MediaFile::make('nonexistent.xyz')->getMimeType()); } - /** @dataProvider bootableMethodsProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('bootableMethodsProvider')] public function testExceptionIsThrownWhenBootingFileThatDoesNotExist(string $bootableMethod) { $this->mockFilesystem->shouldReceive('missing') @@ -615,12 +614,10 @@ protected function mockCurrentPage(string $page): void Render::shouldReceive('getRouteKey')->andReturn($page); } - public static function bootableMethodsProvider(): array + public static function bootableMethodsProvider(): \Iterator { - return [ - ['getLength'], - ['getMimeType'], - ['getHash'], - ]; + yield ['getLength']; + yield ['getMimeType']; + yield ['getHash']; } } diff --git a/tests/Unit/TestingSupportHelpersMetaTest.php b/tests/Unit/TestingSupportHelpersMetaTest.php index 55abd8b7..b4c94eb5 100644 --- a/tests/Unit/TestingSupportHelpersMetaTest.php +++ b/tests/Unit/TestingSupportHelpersMetaTest.php @@ -15,10 +15,9 @@ * * @see \Hyde\Testing\Support * @see \Hyde\Testing\MocksKernelFeatures - * - * @coversNothing */ #[AllowDynamicProperties] +#[\PHPUnit\Framework\Attributes\CoversNothing] class TestingSupportHelpersMetaTest extends UnitTestCase { use MocksKernelFeatures; diff --git a/tests/Unit/TracksExecutionTimeTest.php b/tests/Unit/TracksExecutionTimeTest.php index e85b94a4..0a57664d 100644 --- a/tests/Unit/TracksExecutionTimeTest.php +++ b/tests/Unit/TracksExecutionTimeTest.php @@ -7,9 +7,7 @@ use Hyde\Framework\Concerns\TracksExecutionTime; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Framework\Concerns\TracksExecutionTime - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Concerns\TracksExecutionTime::class)] class TracksExecutionTimeTest extends UnitTestCase { public function testStartClock() diff --git a/tests/Unit/UnixsumTest.php b/tests/Unit/UnixsumTest.php index 81b800ed..feb1e2b4 100644 --- a/tests/Unit/UnixsumTest.php +++ b/tests/Unit/UnixsumTest.php @@ -35,17 +35,17 @@ public function testMethodReturnsSameValueForSameStringUsingNormalMethod() public function testMethodReturnsDifferentValueForDifferentString() { - $this->assertNotEquals(unixsum('foo'), unixsum('bar')); + $this->assertNotSame(unixsum('foo'), unixsum('bar')); } public function testFunctionIsCaseSensitive() { - $this->assertNotEquals(unixsum('foo'), unixsum('FOO')); + $this->assertNotSame(unixsum('foo'), unixsum('FOO')); } public function testFunctionIsSpaceSensitive() { - $this->assertNotEquals(unixsum(' foo '), unixsum('foo')); + $this->assertNotSame(unixsum(' foo '), unixsum('foo')); } public function testMethodReturnsSameValueRegardlessOfEndOfLineSequence() diff --git a/tests/Unit/UnsupportedPageTypeExceptionTest.php b/tests/Unit/UnsupportedPageTypeExceptionTest.php index 36e972b9..bcecfcf4 100644 --- a/tests/Unit/UnsupportedPageTypeExceptionTest.php +++ b/tests/Unit/UnsupportedPageTypeExceptionTest.php @@ -7,9 +7,7 @@ use Hyde\Framework\Exceptions\UnsupportedPageTypeException; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Framework\Exceptions\UnsupportedPageTypeException - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\UnsupportedPageTypeException::class)] class UnsupportedPageTypeExceptionTest extends UnitTestCase { public function testItCanBeInstantiated() diff --git a/tests/Unit/ValidatesExistenceTest.php b/tests/Unit/ValidatesExistenceTest.php index efcc3b88..77b538a3 100644 --- a/tests/Unit/ValidatesExistenceTest.php +++ b/tests/Unit/ValidatesExistenceTest.php @@ -9,10 +9,8 @@ use Hyde\Pages\BladePage; use Hyde\Testing\UnitTestCase; -/** - * @covers \Hyde\Framework\Concerns\ValidatesExistence - * @covers \Hyde\Framework\Exceptions\FileNotFoundException - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Concerns\ValidatesExistence::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Exceptions\FileNotFoundException::class)] class ValidatesExistenceTest extends UnitTestCase { protected static bool $needsKernel = true; diff --git a/tests/Unit/ViewDiffServiceTest.php b/tests/Unit/ViewDiffServiceTest.php index fc0cbfac..d8f06f2f 100644 --- a/tests/Unit/ViewDiffServiceTest.php +++ b/tests/Unit/ViewDiffServiceTest.php @@ -11,9 +11,7 @@ use function Hyde\unixsum; use function Hyde\unixsum_file; -/** - * @covers \Hyde\Framework\Services\ViewDiffService - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Services\ViewDiffService::class)] class ViewDiffServiceTest extends UnitTestCase { protected static bool $needsKernel = true; @@ -25,7 +23,7 @@ public function testGetFilecache() $this->assertIsArray($fileCache); $this->assertArrayHasKey('resources/views/layouts/app.blade.php', $fileCache); $this->assertArrayHasKey('unixsum', $fileCache['resources/views/layouts/app.blade.php']); - $this->assertEquals(32, strlen($fileCache['resources/views/layouts/app.blade.php']['unixsum'])); + $this->assertSame(32, strlen($fileCache['resources/views/layouts/app.blade.php']['unixsum'])); } public function testGetChecksums() diff --git a/tests/Unit/Views/BlogPostFeedComponentViewTest.php b/tests/Unit/Views/BlogPostFeedComponentViewTest.php index 9cf2198f..cc729807 100644 --- a/tests/Unit/Views/BlogPostFeedComponentViewTest.php +++ b/tests/Unit/Views/BlogPostFeedComponentViewTest.php @@ -10,8 +10,9 @@ use Hyde\Testing\TestsBladeViews; /** - * @coversNothing Test to ensure the blog post feed component can be rendered + * Test to ensure the blog post feed component can be rendered. */ +#[\PHPUnit\Framework\Attributes\CoversNothing] class BlogPostFeedComponentViewTest extends TestCase { use TestsBladeViews; diff --git a/tests/Unit/Views/BreadcrumbsComponentViewTest.php b/tests/Unit/Views/BreadcrumbsComponentViewTest.php index a434da46..8617965c 100644 --- a/tests/Unit/Views/BreadcrumbsComponentViewTest.php +++ b/tests/Unit/Views/BreadcrumbsComponentViewTest.php @@ -13,10 +13,9 @@ use Hyde\Framework\Views\Components\BreadcrumbsComponent; /** - * @covers \Hyde\Framework\Views\Components\BreadcrumbsComponent - * * @see \Hyde\Framework\Testing\Unit\BreadcrumbsComponentTest */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Views\Components\BreadcrumbsComponent::class)] class BreadcrumbsComponentViewTest extends TestCase { public function testRenderedBladeView() diff --git a/tests/Unit/Views/FeaturedImageViewTest.php b/tests/Unit/Views/FeaturedImageViewTest.php index cd4c39b7..b2a11f96 100644 --- a/tests/Unit/Views/FeaturedImageViewTest.php +++ b/tests/Unit/Views/FeaturedImageViewTest.php @@ -43,7 +43,7 @@ public function testTheView() $this->assertStringContainsString('Creative Commons', $component); $this->assertStringContainsString('href="https://licence.example.com" rel="license nofollow noopener"', $component); - $this->assertEquals( + $this->assertSame( $this->stripWhitespace('Image by John Doe. License Creative Commons.'), $this->stripWhitespace($this->stripHtml($component)) ); diff --git a/tests/Unit/Views/LinkComponentViewTest.php b/tests/Unit/Views/LinkComponentViewTest.php index 7d8839ac..89de6e5e 100644 --- a/tests/Unit/Views/LinkComponentViewTest.php +++ b/tests/Unit/Views/LinkComponentViewTest.php @@ -9,9 +9,7 @@ use Hyde\Foundation\Facades\Routes; use Illuminate\Support\Facades\Blade; -/** - * @covers \Hyde\Framework\Views\Components\LinkComponent - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Hyde\Framework\Views\Components\LinkComponent::class)] class LinkComponentViewTest extends TestCase { public function testLinkComponentCanBeRendered()