diff --git a/camel/Camel.php b/camel/Camel.php index 28d03d30..6cde9b2a 100644 --- a/camel/Camel.php +++ b/camel/Camel.php @@ -6,20 +6,21 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use Knuckles\Camel\Output\OutputEndpointData; +use Knuckles\Scribe\Configuration\PathConfig; use Knuckles\Scribe\Tools\Utils; use Symfony\Component\Yaml\Yaml; class Camel { - public static function cacheDir(string $docsName = 'scribe'): string + public static function cacheDir(PathConfig $pathConfiguration): string { - return ".$docsName/endpoints.cache"; + return $pathConfiguration->getTemporaryDirectoryPath() . "/endpoints.cache"; } - public static function camelDir(string $docsName = 'scribe'): string + public static function camelDir(PathConfig $pathConfiguration): string { - return ".$docsName/endpoints"; + return $pathConfiguration->getTemporaryDirectoryPath() . "/endpoints"; } /** diff --git a/phpunit.xml b/phpunit.xml index 813fd914..462cb722 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -41,6 +41,7 @@ tests/Unit/ExtractorTest.php tests/Unit/ExtractorPluginSystemTest.php tests/Unit/ConfigDifferTest.php + tests/Unit/PathConfigurationTest.php tests/Unit/ExtractedEndpointDataTest.php diff --git a/src/Commands/GenerateDocumentation.php b/src/Commands/GenerateDocumentation.php index c899377a..e1df60bd 100644 --- a/src/Commands/GenerateDocumentation.php +++ b/src/Commands/GenerateDocumentation.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\URL; use Illuminate\Support\Str; use Knuckles\Camel\Camel; +use Knuckles\Scribe\Configuration\PathConfig; use Knuckles\Scribe\GroupedEndpoints\GroupedEndpointsFactory; use Knuckles\Scribe\Matching\RouteMatcherInterface; use Knuckles\Scribe\Tools\ConsoleOutputUtils as c; @@ -24,6 +25,7 @@ class GenerateDocumentation extends Command {--no-extraction : Skip extraction of route and API info and just transform the YAML and Markdown files into HTML} {--no-upgrade-check : Skip checking for config file upgrades. Won't make things faster, but can be helpful if the command is buggy} {--config=scribe : choose which config file to use} + {--cache-directory= : choose which cache directory to use} "; protected $description = 'Generate API documentation from your Laravel/Dingo routes.'; @@ -34,7 +36,8 @@ class GenerateDocumentation extends Command protected bool $forcing; - protected string $configName; + /** @var PathConfig */ + protected PathConfig $pathConfiguration; public function handle(RouteMatcherInterface $routeMatcher, GroupedEndpointsFactory $groupedEndpointsFactory): void { @@ -47,9 +50,9 @@ public function handle(RouteMatcherInterface $routeMatcher, GroupedEndpointsFact } // Extraction stage - extract endpoint info either from app or existing Camel files (previously extracted data) - $groupedEndpointsInstance = $groupedEndpointsFactory->make($this, $routeMatcher, $this->configName); + $groupedEndpointsInstance = $groupedEndpointsFactory->make($this, $routeMatcher, $this->pathConfiguration); $extractedEndpoints = $groupedEndpointsInstance->get(); - $userDefinedEndpoints = Camel::loadUserDefinedEndpoints(Camel::camelDir($this->configName)); + $userDefinedEndpoints = Camel::loadUserDefinedEndpoints(Camel::camelDir($this->pathConfiguration)); $groupedEndpoints = $this->mergeUserDefinedEndpoints($extractedEndpoints, $userDefinedEndpoints); // Output stage @@ -61,7 +64,7 @@ public function handle(RouteMatcherInterface $routeMatcher, GroupedEndpointsFact $this->writeExampleCustomEndpoint(); } - $writer = new Writer($this->docConfig, $this->configName); + $writer = new Writer($this->docConfig, $this->pathConfiguration); $writer->writeDocs($groupedEndpoints); $this->upgradeConfigFileIfNeeded(); @@ -98,12 +101,17 @@ public function bootstrap(): void c::bootstrapOutput($this->output); - $this->configName = $this->option('config'); - if (!config($this->configName)) { - throw new \InvalidArgumentException("The specified config (config/{$this->configName}.php) doesn't exist."); + $configName = $this->option('config'); + if (!config($configName)) { + throw new \InvalidArgumentException("The specified config (config/{$configName}.php) doesn't exist."); } - $this->docConfig = new DocumentationConfig(config($this->configName)); + $this->pathConfiguration = new PathConfig($configName, $configName, true); + if ($this->hasOption('cache-directory') && !empty($this->option('cache-directory'))) { + $this->pathConfiguration = new PathConfig($this->option('cache-directory'), $configName, false); + } + + $this->docConfig = new DocumentationConfig(config($this->pathConfiguration->getScribeConfigurationPath())); // Force root URL so it works in Postman collection $baseUrl = $this->docConfig->get('base_url') ?? config('app.url'); @@ -146,7 +154,7 @@ protected function mergeUserDefinedEndpoints(array $groupedEndpoints, array $use protected function writeExampleCustomEndpoint(): void { // We add an example to guide users in case they need to add a custom endpoint. - copy(__DIR__ . '/../../resources/example_custom_endpoint.yaml', Camel::camelDir($this->configName) . '/custom.0.yaml'); + copy(__DIR__ . '/../../resources/example_custom_endpoint.yaml', Camel::camelDir($this->pathConfiguration) . '/custom.0.yaml'); } protected function upgradeConfigFileIfNeeded(): void @@ -155,12 +163,12 @@ protected function upgradeConfigFileIfNeeded(): void $this->info("Checking for any pending upgrades to your config file..."); try { - if (! $this->laravel['files']->exists($this->laravel->configPath("{$this->configName}.php"))) { + if (! $this->laravel['files']->exists($this->laravel->configPath($this->pathConfiguration->getScribeConfigurationPath('php', '.')))) { $this->info("No config file to upgrade."); return; } - $upgrader = Upgrader::ofConfigFile("config/{$this->configName}.php", __DIR__ . '/../../config/scribe.php') + $upgrader = Upgrader::ofConfigFile("config/" . $this->pathConfiguration->getScribeConfigurationPath('php', '.'), __DIR__ . '/../../config/scribe.php') ->dontTouch( 'routes', 'example_languages', 'database_connections_to_transact', 'strategies', 'laravel.middleware', 'postman.overrides', 'openapi.overrides', 'groups', 'examples.models_source' diff --git a/src/Configuration/PathConfig.php b/src/Configuration/PathConfig.php new file mode 100644 index 00000000..c46746cc --- /dev/null +++ b/src/Configuration/PathConfig.php @@ -0,0 +1,56 @@ +cacheDir = $cacheDir; + $this->scribeConfig = $scribeConfig; + $this->isHidden = $isHidden; + } + + /** + * @return string + */ + public function getScribeConfigurationPath(string $resolvePath = null, string $separator = '/'): string + { + if (is_null($resolvePath)) { + return $this->scribeConfig; + } + // Separate the path with a / + return sprintf("%s%s%s", $this->scribeConfig, $separator, $resolvePath); + } + + /** + * @return string + */ + public function getTemporaryDirectoryPath(string $resolvePath = null): string + { + $path = ($this->isHidden ? '.' : '') . $this->cacheDir; + if (is_null($resolvePath)) { + return $path; + } + // Separate the path with a / + return sprintf("%s/%s", $path, $resolvePath); + + } +} diff --git a/src/Extracting/ApiDetails.php b/src/Extracting/ApiDetails.php index febe4b9c..31186015 100644 --- a/src/Extracting/ApiDetails.php +++ b/src/Extracting/ApiDetails.php @@ -2,6 +2,7 @@ namespace Knuckles\Scribe\Extracting; +use Knuckles\Scribe\Configuration\PathConfig; use Knuckles\Scribe\Tools\ConsoleOutputUtils as c; use Knuckles\Scribe\Tools\Utils as u; use Knuckles\Scribe\Tools\DocumentationConfig; @@ -23,11 +24,19 @@ class ApiDetails private array $lastKnownFileContentHashes = []; - public function __construct(DocumentationConfig $config = null, bool $preserveUserChanges = true, string $docsName = 'scribe') - { - $this->markdownOutputPath = ".{$docsName}"; //.scribe by default + /** + * @param PathConfig $pathConfig + * @param DocumentationConfig|null $config + * @param bool $preserveUserChanges + */ + public function __construct( + PathConfig $pathConfig, + DocumentationConfig $config = null, + bool $preserveUserChanges = true + ) { + $this->markdownOutputPath = $pathConfig->getTemporaryDirectoryPath(); //.scribe by default // If no config is injected, pull from global. Makes testing easier. - $this->config = $config ?: new DocumentationConfig(config($docsName)); + $this->config = $config ?: new DocumentationConfig(config($pathConfig)); $this->baseUrl = $this->config->get('base_url') ?? config('app.url'); $this->preserveUserChanges = $preserveUserChanges; diff --git a/src/GroupedEndpoints/GroupedEndpointsFactory.php b/src/GroupedEndpoints/GroupedEndpointsFactory.php index 022454ef..ebfc5825 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFactory.php +++ b/src/GroupedEndpoints/GroupedEndpointsFactory.php @@ -3,34 +3,55 @@ namespace Knuckles\Scribe\GroupedEndpoints; use Knuckles\Scribe\Commands\GenerateDocumentation; +use Knuckles\Scribe\Configuration\PathConfig; use Knuckles\Scribe\Matching\RouteMatcherInterface; class GroupedEndpointsFactory { - public function make(GenerateDocumentation $command, RouteMatcherInterface $routeMatcher, string $docsName = 'scribe'): GroupedEndpointsContract - { + /** + * @param GenerateDocumentation $command + * @param RouteMatcherInterface $routeMatcher + * @param PathConfig $pathConfig + * @return GroupedEndpointsContract + */ + public function make( + GenerateDocumentation $command, + RouteMatcherInterface $routeMatcher, + PathConfig $pathConfig + ): GroupedEndpointsContract { if ($command->isForcing()) { - return static::fromApp($command, $routeMatcher, false, $docsName); + return static::fromApp($command, $routeMatcher, false, $pathConfig); } if ($command->shouldExtract()) { - return static::fromApp($command, $routeMatcher, true, $docsName); + return static::fromApp($command, $routeMatcher, true, $pathConfig); } - return static::fromCamelDir($docsName); + return static::fromCamelDir($pathConfig); } + /** + * @param GenerateDocumentation $command + * @param RouteMatcherInterface $routeMatcher + * @param bool $preserveUserChanges + * @param PathConfig $pathConfig + * @return GroupedEndpointsFromApp + */ public static function fromApp( GenerateDocumentation $command, RouteMatcherInterface $routeMatcher, bool $preserveUserChanges, - string $docsName = 'scribe' + PathConfig $pathConfig ): GroupedEndpointsFromApp { - return new GroupedEndpointsFromApp($command, $routeMatcher, $preserveUserChanges, $docsName); + return new GroupedEndpointsFromApp($command, $routeMatcher, $pathConfig, $preserveUserChanges); } - public static function fromCamelDir(string $docsName = 'scribe'): GroupedEndpointsFromCamelDir + /** + * @param PathConfig $pathConfig + * @return GroupedEndpointsFromCamelDir + */ + public static function fromCamelDir(PathConfig $pathConfig): GroupedEndpointsFromCamelDir { - return new GroupedEndpointsFromCamelDir($docsName); + return new GroupedEndpointsFromCamelDir($pathConfig); } } diff --git a/src/GroupedEndpoints/GroupedEndpointsFromApp.php b/src/GroupedEndpoints/GroupedEndpointsFromApp.php index 18209ffb..804826f6 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromApp.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromApp.php @@ -10,6 +10,7 @@ use Knuckles\Camel\Extraction\ExtractedEndpointData; use Knuckles\Camel\Output\OutputEndpointData; use Knuckles\Scribe\Commands\GenerateDocumentation; +use Knuckles\Scribe\Configuration\PathConfig; use Knuckles\Scribe\Exceptions\CouldntGetRouteDetails; use Knuckles\Scribe\Extracting\ApiDetails; use Knuckles\Scribe\Extracting\Extractor; @@ -33,15 +34,22 @@ class GroupedEndpointsFromApp implements GroupedEndpointsContract public static string $camelDir; public static string $cacheDir; + /** + * @param GenerateDocumentation $command + * @param RouteMatcherInterface $routeMatcher + * @param PathConfig $pathConfiguration + * @param bool $preserveUserChanges + */ public function __construct( - private GenerateDocumentation $command, private RouteMatcherInterface $routeMatcher, - private bool $preserveUserChanges = true, protected string $docsName = 'scribe' - ) - { + private GenerateDocumentation $command, + private RouteMatcherInterface $routeMatcher, + protected PathConfig $pathConfiguration, + private bool $preserveUserChanges = true + ) { $this->docConfig = $command->getDocConfig(); - static::$camelDir = Camel::camelDir($this->docsName); - static::$cacheDir = Camel::cacheDir($this->docsName); + static::$camelDir = Camel::camelDir($this->pathConfiguration); + static::$cacheDir = Camel::cacheDir($this->pathConfiguration); } public function get(): array @@ -282,7 +290,7 @@ protected function extractAndWriteApiDetailsToDisk(): void protected function makeApiDetails(): ApiDetails { - return new ApiDetails($this->docConfig, !$this->command->option('force'), $this->docsName); + return new ApiDetails($this->pathConfiguration, $this->docConfig, !$this->command->option('force')); } /** diff --git a/src/GroupedEndpoints/GroupedEndpointsFromCamelDir.php b/src/GroupedEndpoints/GroupedEndpointsFromCamelDir.php index ad80a69f..ab154827 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromCamelDir.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromCamelDir.php @@ -3,25 +3,26 @@ namespace Knuckles\Scribe\GroupedEndpoints; use Knuckles\Camel\Camel; +use Knuckles\Scribe\Configuration\PathConfig; class GroupedEndpointsFromCamelDir implements GroupedEndpointsContract { - protected string $docsName; + protected PathConfig $pathConfig; - public function __construct(string $docsName = 'scribe') + public function __construct(PathConfig $pathConfig) { - $this->docsName = $docsName; + $this->pathConfig = $pathConfig; } public function get(): array { - if (!is_dir(Camel::camelDir($this->docsName))) { + if (!is_dir(Camel::camelDir($this->pathConfig))) { throw new \InvalidArgumentException( - "Can't use --no-extraction because there are no endpoints in the " . Camel::camelDir($this->docsName) . " directory." + "Can't use --no-extraction because there are no endpoints in the " . Camel::camelDir($this->pathConfig) . " directory." ); } - return Camel::loadEndpointsIntoGroups(Camel::camelDir($this->docsName)); + return Camel::loadEndpointsIntoGroups(Camel::camelDir($this->pathConfig)); } public function hasEncounteredErrors(): bool diff --git a/src/Writing/Writer.php b/src/Writing/Writer.php index c3a03539..7bd51a93 100644 --- a/src/Writing/Writer.php +++ b/src/Writing/Writer.php @@ -3,6 +3,7 @@ namespace Knuckles\Scribe\Writing; use Illuminate\Support\Facades\Storage; +use Knuckles\Scribe\Configuration\PathConfig; use Knuckles\Scribe\Tools\ConsoleOutputUtils as c; use Knuckles\Scribe\Tools\DocumentationConfig; use Knuckles\Scribe\Tools\Globals; @@ -15,14 +16,12 @@ class Writer * The "name" of this docs instance. By default, it is "scribe". * Used for multi-docs. */ - public string $docsName; + public PathConfig $paths; private DocumentationConfig $config; private bool $isStatic; - private string $markdownOutputPath; - private ?string $staticTypeOutputPath; private ?string $laravelTypeOutputPath; @@ -40,21 +39,20 @@ class Writer private string $laravelAssetsPath; - public function __construct(DocumentationConfig $config = null, $docsName = 'scribe') + public function __construct(DocumentationConfig $config = null, PathConfig $pathConfig) { - $this->docsName = $docsName; + $this->paths = $pathConfig; // If no config is injected, pull from global, for easier testing. - $this->config = $config ?: new DocumentationConfig(config($docsName)); + $this->config = $config ?: new DocumentationConfig(config($this->paths->getScribeConfigurationPath())); $this->isStatic = $this->config->get('type') === 'static'; - $this->markdownOutputPath = ".{$docsName}"; //.scribe by default $this->laravelTypeOutputPath = $this->getLaravelTypeOutputPath(); $this->staticTypeOutputPath = rtrim($this->config->get('static.output_path', 'public/docs'), '/'); $this->laravelAssetsPath = $this->config->get('laravel.assets_directory') ? '/' . $this->config->get('laravel.assets_directory') - : "/vendor/$this->docsName"; + : "/vendor/" . $this->paths->getScribeConfigurationPath(); } /** @@ -86,8 +84,8 @@ protected function writePostmanCollection(array $groups): void $collectionPath = "{$this->staticTypeOutputPath}/collection.json"; file_put_contents($collectionPath, $collection); } else { - Storage::disk('local')->put("{$this->docsName}/collection.json", $collection); - $collectionPath = Storage::disk('local')->path("$this->docsName/collection.json"); + Storage::disk('local')->put($this->paths->getScribeConfigurationPath('collection.json'), $collection); + $collectionPath = Storage::disk('local')->path($this->paths->getScribeConfigurationPath('collection.json')); } c::success("Wrote Postman collection to: {$this->makePathFriendly($collectionPath)}"); @@ -105,8 +103,8 @@ protected function writeOpenAPISpec(array $parsedRoutes): void $specPath = "{$this->staticTypeOutputPath}/openapi.yaml"; file_put_contents($specPath, $spec); } else { - Storage::disk('local')->put("{$this->docsName}/openapi.yaml", $spec); - $specPath = Storage::disk('local')->path("$this->docsName/openapi.yaml"); + Storage::disk('local')->put($this->paths->getScribeConfigurationPath('openapi.yaml'), $spec); + $specPath = Storage::disk('local')->path($this->paths->getScribeConfigurationPath('openapi.yaml')); } c::success("Wrote OpenAPI specification to: {$this->makePathFriendly($specPath)}"); @@ -180,8 +178,8 @@ protected function performFinalTasksForLaravelType(): void // Rewrite asset links to go through Laravel $contents = preg_replace('#href="\.\./docs/css/(.+?)"#', 'href="{{ asset("' . $this->laravelAssetsPath . '/css/$1") }}"', $contents); $contents = preg_replace('#src="\.\./docs/(js|images)/(.+?)"#', 'src="{{ asset("' . $this->laravelAssetsPath . '/$1/$2") }}"', $contents); - $contents = str_replace('href="../docs/collection.json"', 'href="{{ route("' . $this->docsName . '.postman") }}"', $contents); - $contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("' . $this->docsName . '.openapi") }}"', $contents); + $contents = str_replace('href="../docs/collection.json"', 'href="{{ route("' . $this->paths->getScribeConfigurationPath('postman', '.') . '") }}"', $contents); + $contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("' . $this->paths->getScribeConfigurationPath('openapi', '.') . '") }}"', $contents); file_put_contents("$this->laravelTypeOutputPath/index.blade.php", $contents); } @@ -193,7 +191,7 @@ public function writeHtmlDocs(array $groupedEndpoints): void // Then we convert them to HTML, and throw in the endpoints as well. /** @var HtmlWriter $writer */ $writer = app()->makeWith(HtmlWriter::class, ['config' => $this->config]); - $writer->generate($groupedEndpoints, $this->markdownOutputPath, $this->staticTypeOutputPath); + $writer->generate($groupedEndpoints, $this->paths->getTemporaryDirectoryPath(), $this->staticTypeOutputPath); if (!$this->isStatic) { $this->performFinalTasksForLaravelType(); @@ -228,7 +226,10 @@ protected function getLaravelTypeOutputPath(): ?string { if ($this->isStatic) return null; - return config('view.paths.0', function_exists('base_path') ? base_path("resources/views") : "resources/views") . "/$this->docsName"; + return config( + 'view.paths.0', + function_exists('base_path') ? base_path("resources/views") : "resources/views" + ). "/" . $this->paths->getScribeConfigurationPath(); } /** diff --git a/tests/GenerateDocumentation/OutputTest.php b/tests/GenerateDocumentation/OutputTest.php index 52f4ede8..a6dc73d6 100644 --- a/tests/GenerateDocumentation/OutputTest.php +++ b/tests/GenerateDocumentation/OutputTest.php @@ -139,39 +139,82 @@ public function generates_laravel_type_output() /** @test */ public function supports_multi_docs_in_laravel_type_output() + { + $this->supports_base_test(["--config" => "scribe_admin"], '.scribe_admin'); + } + + /** @test */ + public function supports_separate_hidden_cache_directory() + { + $this->supports_base_test([ + "--config" => "scribe_admin", + "--cache-directory" => ".scribe_admin_dir" + ], '.scribe_admin_dir'); + } + + /** @test */ + public function supports_separate_non_hidden_cache_directory() + { + $this->supports_base_test([ + "--config" => "scribe_admin", + "--cache-directory" => "scribe_admin_dir" + ], 'scribe_admin_dir'); + } + + /** @test */ + public function supports_unrelated_temp_directory() + { + $this->supports_base_test([ + "--config" => "bananas_are_good", + "--cache-directory" => "5.5/Apple/26" + ], '5.5/Apple/26'); + } + + /** + * Base test for + * - supports_multi_docs_in_laravel_type_output + * - supports_separate_hidden_cache_directory + * - supports_separate_non_hidden_cache_directory + * - supports_unrelated_temp_directory + * + * @param $generate + * @param $assertDir + * @return void + */ + private function supports_base_test($generate, $assertDir) { RouteFacade::post('/api/withQueryParameters', [TestController::class, 'withQueryParameters']); - config(['scribe_admin' => config('scribe')]); + config([$generate['--config'] => config('scribe')]); $title = "The Real Admin API"; - config(['scribe_admin.title' => $title]); - config(['scribe_admin.type' => 'laravel']); - config(['scribe_admin.postman.enabled' => true]); - config(['scribe_admin.openapi.enabled' => true]); + config([$generate['--config'] . '.title' => $title]); + config([$generate['--config'] . '.type' => 'laravel']); + config([$generate['--config'] . '.postman.enabled' => true]); + config([$generate['--config'] . '.openapi.enabled' => true]); - $output = $this->generate(["--config" => "scribe_admin"]); + $output = $this->generate($generate); $this->assertStringContainsString( - "Wrote Blade docs to: vendor/orchestra/testbench-core/laravel/resources/views/scribe_admin", $output + "Wrote Blade docs to: vendor/orchestra/testbench-core/laravel/resources/views/" . $generate['--config'], $output ); $this->assertStringContainsString( - "Wrote Laravel assets to: vendor/orchestra/testbench-core/laravel/public/vendor/scribe_admin", $output + "Wrote Laravel assets to: vendor/orchestra/testbench-core/laravel/public/vendor/" . $generate['--config'], $output ); $this->assertStringContainsString( - "Wrote Postman collection to: vendor/orchestra/testbench-core/laravel/storage/app/scribe_admin/collection.json", $output + "Wrote Postman collection to: vendor/orchestra/testbench-core/laravel/storage/app/" . $generate['--config'] . "/collection.json", $output ); $this->assertStringContainsString( - "Wrote OpenAPI specification to: vendor/orchestra/testbench-core/laravel/storage/app/scribe_admin/openapi.yaml", $output + "Wrote OpenAPI specification to: vendor/orchestra/testbench-core/laravel/storage/app/" . $generate['--config'] . "/openapi.yaml", $output ); $paths = collect([ - Storage::disk('local')->path('scribe_admin/collection.json'), - Storage::disk('local')->path('scribe_admin/openapi.yaml'), - View::getFinder()->find('scribe_admin/index'), + Storage::disk('local')->path( $generate['--config'] . '/collection.json'), + Storage::disk('local')->path($generate['--config'] . '/openapi.yaml'), + View::getFinder()->find($generate['--config'] . '/index'), ]); $paths->each(fn($path) => $this->assertFileContainsString($path, $title)); $paths->each(fn($path) => unlink($path)); - $this->assertDirectoryExists(".scribe_admin"); - Utils::deleteDirectoryAndContents(".scribe_admin"); + $this->assertDirectoryExists($assertDir); + Utils::deleteDirectoryAndContents($assertDir); } /** @test */ diff --git a/tests/Unit/PathConfigurationTest.php b/tests/Unit/PathConfigurationTest.php new file mode 100644 index 00000000..da263a24 --- /dev/null +++ b/tests/Unit/PathConfigurationTest.php @@ -0,0 +1,37 @@ +assertEquals('.scribe', $pathConfig->getTemporaryDirectoryPath()); + } + + /** @test */ + public function object_resolves_into_non_hidden_string() + { + $pathConfig = new PathConfig('scribe', 'scribe', false); + $this->assertEquals('scribe', $pathConfig->getTemporaryDirectoryPath()); + } + + /** @test */ + public function object_resolves_into_hidden_string_for_subdirs() + { + $pathConfig = new PathConfig('scribe/bob', 'scribe', true); + $this->assertEquals('.scribe/bob', $pathConfig->getTemporaryDirectoryPath()); + } + + /** @test */ + public function object_resolves_into_non_hidden_string_for_subdirs() + { + $pathConfig = new PathConfig('scribe/bob/dave', 'scribe', false); + $this->assertEquals('scribe/bob/dave', $pathConfig->getTemporaryDirectoryPath()); + } +}