From 71b2a81a07696185331dbf10ac59098b4dd98932 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 4 Jul 2022 20:13:52 +0200 Subject: [PATCH 1/7] Return pre-rounded and divided integer instead of float --- packages/framework/src/Commands/HydeBuildSearchCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Commands/HydeBuildSearchCommand.php b/packages/framework/src/Commands/HydeBuildSearchCommand.php index 19715a39a69..207152cc7f0 100644 --- a/packages/framework/src/Commands/HydeBuildSearchCommand.php +++ b/packages/framework/src/Commands/HydeBuildSearchCommand.php @@ -67,9 +67,9 @@ protected function createSearchPage(): void $this->getExecutionTimeInMs($actionTime)."ms\n"); } - protected function guesstimateGenerationTime(): float + protected function guesstimateGenerationTime(): int { - return count(CollectionService::getDocumentationPageFiles()) * 52.5; + return round(count(CollectionService::getDocumentationPageFiles()) * 52.5) / 1000; } protected function getExecutionTimeInMs(float $timeStart): string From 5bd943eafb0143a9b5fd86cd252bded12f18083a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 4 Jul 2022 20:16:23 +0200 Subject: [PATCH 2/7] Only print estimation time message if it is more than one second --- packages/framework/src/Commands/HydeBuildSearchCommand.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Commands/HydeBuildSearchCommand.php b/packages/framework/src/Commands/HydeBuildSearchCommand.php index 207152cc7f0..3e95ba77ac9 100644 --- a/packages/framework/src/Commands/HydeBuildSearchCommand.php +++ b/packages/framework/src/Commands/HydeBuildSearchCommand.php @@ -40,7 +40,10 @@ public function handle(): int $actionTime = microtime(true); $this->comment('Generating documentation site search index...'); - $this->line(' > This will take an estimated '.round($this->guesstimateGenerationTime() / 1000).' seconds. Terminal may seem non-responsive.'); + $expected = $this->guesstimateGenerationTime(); + if ($expected > 0) { + $this->line(" > This will take an estimated $expected seconds. Terminal may seem non-responsive."); + } GeneratesDocumentationSearchIndexFile::run(); $this->line(' > Created '.GeneratesDocumentationSearchIndexFile::$filePath.' in '. From c5a39dd0f3ef5628d7c3176d45258c75c4e34e9f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 4 Jul 2022 20:18:58 +0200 Subject: [PATCH 3/7] Improve test to cover full page search generation --- .../Commands/HydeBuildSearchCommandTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php index 928af2e59e2..b7bdaccf055 100644 --- a/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php @@ -20,4 +20,28 @@ public function test_it_creates_the_search_json_file() $this->assertFileExists(Hyde::path('_site/docs/search.json')); unlink(Hyde::path('_site/docs/search.json')); } + + public function test_it_creates_the_search_page() + { + unlinkIfExists(Hyde::path('_site/docs/search.html')); + $this->artisan('build:search') + ->expectsOutput('Generating documentation site search index...') + ->assertExitCode(0); + + $this->assertFileExists(Hyde::path('_site/docs/search.html')); + unlink(Hyde::path('_site/docs/search.html')); + unlink(Hyde::path('_site/docs/search.json')); + } + + public function test_it_does_not_create_the_search_page_if_disabled() + { + config(['docs.create_search_page' => false]); + unlinkIfExists(Hyde::path('_site/docs/search.html')); + $this->artisan('build:search') + ->expectsOutput('Generating documentation site search index...') + ->assertExitCode(0); + + $this->assertFileDoesNotExist(Hyde::path('_site/docs/search.html')); + unlink(Hyde::path('_site/docs/search.json')); + } } From 180345e72aac7e7b9ec06b14dfb50fb69fcf2bf3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 4 Jul 2022 20:27:56 +0200 Subject: [PATCH 4/7] Create internal guesstimationFactor property so it can be mocked --- packages/framework/src/Commands/HydeBuildSearchCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Commands/HydeBuildSearchCommand.php b/packages/framework/src/Commands/HydeBuildSearchCommand.php index 3e95ba77ac9..dee2a01f3ce 100644 --- a/packages/framework/src/Commands/HydeBuildSearchCommand.php +++ b/packages/framework/src/Commands/HydeBuildSearchCommand.php @@ -70,9 +70,11 @@ protected function createSearchPage(): void $this->getExecutionTimeInMs($actionTime)."ms\n"); } + /** @internal */ + public static float $guesstimationFactor = 52.5; protected function guesstimateGenerationTime(): int { - return round(count(CollectionService::getDocumentationPageFiles()) * 52.5) / 1000; + return round(count(CollectionService::getDocumentationPageFiles()) * static::$guesstimationFactor) / 1000; } protected function getExecutionTimeInMs(float $timeStart): string From 70dec797026a79ff6f2986f9814fbd7295190471 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 4 Jul 2022 20:29:23 +0200 Subject: [PATCH 5/7] Move shared test code to setup/teardown methods --- .../Commands/HydeBuildSearchCommandTest.php | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php index b7bdaccf055..f03d3e012f3 100644 --- a/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php @@ -10,38 +10,46 @@ */ class HydeBuildSearchCommandTest extends TestCase { - public function test_it_creates_the_search_json_file() + protected function setUp(): void { + parent::setUp(); + unlinkIfExists(Hyde::path('_site/docs/search.json')); + unlinkIfExists(Hyde::path('_site/docs/search.html')); + } + + protected function tearDown(): void + { + unlinkIfExists(Hyde::path('_site/docs/search.html')); unlinkIfExists(Hyde::path('_site/docs/search.json')); + parent::tearDown(); + } + + + public function test_it_creates_the_search_json_file() + { $this->artisan('build:search') ->expectsOutput('Generating documentation site search index...') ->assertExitCode(0); $this->assertFileExists(Hyde::path('_site/docs/search.json')); - unlink(Hyde::path('_site/docs/search.json')); } public function test_it_creates_the_search_page() { - unlinkIfExists(Hyde::path('_site/docs/search.html')); $this->artisan('build:search') ->expectsOutput('Generating documentation site search index...') ->assertExitCode(0); $this->assertFileExists(Hyde::path('_site/docs/search.html')); - unlink(Hyde::path('_site/docs/search.html')); - unlink(Hyde::path('_site/docs/search.json')); } public function test_it_does_not_create_the_search_page_if_disabled() { config(['docs.create_search_page' => false]); - unlinkIfExists(Hyde::path('_site/docs/search.html')); $this->artisan('build:search') ->expectsOutput('Generating documentation site search index...') ->assertExitCode(0); $this->assertFileDoesNotExist(Hyde::path('_site/docs/search.html')); - unlink(Hyde::path('_site/docs/search.json')); } } From f47bd5f76d48be80cd111b6ac5973718c364e205 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 4 Jul 2022 20:42:57 +0200 Subject: [PATCH 6/7] Test guesstimation time output message --- .../src/Commands/HydeBuildSearchCommand.php | 3 ++- .../Commands/HydeBuildSearchCommandTest.php | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Commands/HydeBuildSearchCommand.php b/packages/framework/src/Commands/HydeBuildSearchCommand.php index dee2a01f3ce..5e19637f0f4 100644 --- a/packages/framework/src/Commands/HydeBuildSearchCommand.php +++ b/packages/framework/src/Commands/HydeBuildSearchCommand.php @@ -41,6 +41,7 @@ public function handle(): int $this->comment('Generating documentation site search index...'); $expected = $this->guesstimateGenerationTime(); + if ($expected > 0) { $this->line(" > This will take an estimated $expected seconds. Terminal may seem non-responsive."); } @@ -70,7 +71,7 @@ protected function createSearchPage(): void $this->getExecutionTimeInMs($actionTime)."ms\n"); } - /** @internal */ + /** @internal Estimated processing time per file in ms */ public static float $guesstimationFactor = 52.5; protected function guesstimateGenerationTime(): int { diff --git a/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php index f03d3e012f3..433d731249d 100644 --- a/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php @@ -2,6 +2,7 @@ namespace Hyde\Framework\Testing\Feature\Commands; +use Hyde\Framework\Commands\HydeBuildSearchCommand; use Hyde\Framework\Hyde; use Hyde\Testing\TestCase; @@ -21,6 +22,7 @@ protected function tearDown(): void { unlinkIfExists(Hyde::path('_site/docs/search.html')); unlinkIfExists(Hyde::path('_site/docs/search.json')); + HydeBuildSearchCommand::$guesstimationFactor = 52.5; parent::tearDown(); } @@ -52,4 +54,25 @@ public function test_it_does_not_create_the_search_page_if_disabled() $this->assertFileDoesNotExist(Hyde::path('_site/docs/search.html')); } + + public function test_it_does_not_display_the_estimation_message_when_it_is_less_than_1_second() + { + HydeBuildSearchCommand::$guesstimationFactor = 0; + + $this->artisan('build:search') + ->expectsOutput('Generating documentation site search index...') + ->doesntExpectOutputToContain('> This will take an estimated') + ->assertExitCode(0); + } + + public function test_it_displays_the_estimation_message_when_it_is_greater_than_1_second() + { + HydeBuildSearchCommand::$guesstimationFactor = 1000; + touch(Hyde::path('_docs/foo.md')); + $this->artisan('build:search') + ->expectsOutput('Generating documentation site search index...') + ->expectsOutputToContain('> This will take an estimated') + ->assertExitCode(0); + unlink(Hyde::path('_docs/foo.md')); + } } From 992b9080a29c103b68b2a048cbcb32179b16c9b0 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 4 Jul 2022 18:43:07 +0000 Subject: [PATCH 7/7] Apply fixes from StyleCI --- packages/framework/src/Commands/HydeBuildSearchCommand.php | 1 + .../tests/Feature/Commands/HydeBuildSearchCommandTest.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Commands/HydeBuildSearchCommand.php b/packages/framework/src/Commands/HydeBuildSearchCommand.php index 5e19637f0f4..c03751179c3 100644 --- a/packages/framework/src/Commands/HydeBuildSearchCommand.php +++ b/packages/framework/src/Commands/HydeBuildSearchCommand.php @@ -73,6 +73,7 @@ protected function createSearchPage(): void /** @internal Estimated processing time per file in ms */ public static float $guesstimationFactor = 52.5; + protected function guesstimateGenerationTime(): int { return round(count(CollectionService::getDocumentationPageFiles()) * static::$guesstimationFactor) / 1000; diff --git a/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php index 433d731249d..ba71637d9ae 100644 --- a/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/HydeBuildSearchCommandTest.php @@ -26,7 +26,6 @@ protected function tearDown(): void parent::tearDown(); } - public function test_it_creates_the_search_json_file() { $this->artisan('build:search')