Skip to content

Commit c14bc89

Browse files
author
github-actions
committed
Merge pull request #177 from hydephp/170-dont-display-estimated-search-index-generation-time-if-the-time-is-less-than-one-or-a-few-seconds
Don't display estimated search index generation time if it's less than 1 second hydephp/develop@8f24fae
1 parent 2f6f298 commit c14bc89

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

src/Commands/HydeBuildSearchCommand.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public function handle(): int
4040
$actionTime = microtime(true);
4141

4242
$this->comment('Generating documentation site search index...');
43-
$this->line('<fg=gray> > This will take an estimated '.round($this->guesstimateGenerationTime() / 1000).' seconds. Terminal may seem non-responsive.</>');
43+
$expected = $this->guesstimateGenerationTime();
44+
45+
if ($expected > 0) {
46+
$this->line("<fg=gray> > This will take an estimated $expected seconds. Terminal may seem non-responsive.</>");
47+
}
4448
GeneratesDocumentationSearchIndexFile::run();
4549

4650
$this->line(' > Created <info>'.GeneratesDocumentationSearchIndexFile::$filePath.'</> in '.
@@ -67,9 +71,12 @@ protected function createSearchPage(): void
6771
$this->getExecutionTimeInMs($actionTime)."ms\n");
6872
}
6973

70-
protected function guesstimateGenerationTime(): float
74+
/** @internal Estimated processing time per file in ms */
75+
public static float $guesstimationFactor = 52.5;
76+
77+
protected function guesstimateGenerationTime(): int
7178
{
72-
return count(CollectionService::getDocumentationPageFiles()) * 52.5;
79+
return round(count(CollectionService::getDocumentationPageFiles()) * static::$guesstimationFactor) / 1000;
7380
}
7481

7582
protected function getExecutionTimeInMs(float $timeStart): string

tests/Feature/Commands/HydeBuildSearchCommandTest.php

+56-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Hyde\Framework\Testing\Feature\Commands;
44

5+
use Hyde\Framework\Commands\HydeBuildSearchCommand;
56
use Hyde\Framework\Hyde;
67
use Hyde\Testing\TestCase;
78

@@ -10,14 +11,67 @@
1011
*/
1112
class HydeBuildSearchCommandTest extends TestCase
1213
{
13-
public function test_it_creates_the_search_json_file()
14+
protected function setUp(): void
15+
{
16+
parent::setUp();
17+
unlinkIfExists(Hyde::path('_site/docs/search.json'));
18+
unlinkIfExists(Hyde::path('_site/docs/search.html'));
19+
}
20+
21+
protected function tearDown(): void
1422
{
23+
unlinkIfExists(Hyde::path('_site/docs/search.html'));
1524
unlinkIfExists(Hyde::path('_site/docs/search.json'));
25+
HydeBuildSearchCommand::$guesstimationFactor = 52.5;
26+
parent::tearDown();
27+
}
28+
29+
public function test_it_creates_the_search_json_file()
30+
{
1631
$this->artisan('build:search')
1732
->expectsOutput('Generating documentation site search index...')
1833
->assertExitCode(0);
1934

2035
$this->assertFileExists(Hyde::path('_site/docs/search.json'));
21-
unlink(Hyde::path('_site/docs/search.json'));
36+
}
37+
38+
public function test_it_creates_the_search_page()
39+
{
40+
$this->artisan('build:search')
41+
->expectsOutput('Generating documentation site search index...')
42+
->assertExitCode(0);
43+
44+
$this->assertFileExists(Hyde::path('_site/docs/search.html'));
45+
}
46+
47+
public function test_it_does_not_create_the_search_page_if_disabled()
48+
{
49+
config(['docs.create_search_page' => false]);
50+
$this->artisan('build:search')
51+
->expectsOutput('Generating documentation site search index...')
52+
->assertExitCode(0);
53+
54+
$this->assertFileDoesNotExist(Hyde::path('_site/docs/search.html'));
55+
}
56+
57+
public function test_it_does_not_display_the_estimation_message_when_it_is_less_than_1_second()
58+
{
59+
HydeBuildSearchCommand::$guesstimationFactor = 0;
60+
61+
$this->artisan('build:search')
62+
->expectsOutput('Generating documentation site search index...')
63+
->doesntExpectOutputToContain('> This will take an estimated')
64+
->assertExitCode(0);
65+
}
66+
67+
public function test_it_displays_the_estimation_message_when_it_is_greater_than_1_second()
68+
{
69+
HydeBuildSearchCommand::$guesstimationFactor = 1000;
70+
touch(Hyde::path('_docs/foo.md'));
71+
$this->artisan('build:search')
72+
->expectsOutput('Generating documentation site search index...')
73+
->expectsOutputToContain('> This will take an estimated')
74+
->assertExitCode(0);
75+
unlink(Hyde::path('_docs/foo.md'));
2276
}
2377
}

0 commit comments

Comments
 (0)