Skip to content

Commit

Permalink
Run tests without documentation search feature
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 13, 2023
1 parent 7af976b commit ee5fa78
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/framework/tests/Feature/PageCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function test_get_page_returns_parsed_page_object_for_given_source_path()
public function test_get_pages_returns_collection_of_pages_of_given_class()
{
$this->withoutDefaultPages();
$this->withoutDocumentationSearch();

$this->file('_pages/foo.blade.php');
$this->file('_pages/foo.md');
Expand All @@ -103,11 +104,13 @@ public function test_get_pages_returns_collection_of_pages_of_given_class()
$this->assertEquals(new HtmlPage('foo'), Pages::getPages(HtmlPage::class)->first());

$this->restoreDefaultPages();
$this->restoreDocumentationSearch();
}

public function test_get_pages_returns_all_pages_when_not_supplied_with_class_string()
{
$this->withoutDefaultPages();
$this->withoutDocumentationSearch();

$this->file('_pages/foo.blade.php');
$this->file('_pages/foo.md');
Expand All @@ -125,13 +128,16 @@ public function test_get_pages_returns_all_pages_when_not_supplied_with_class_st
$this->assertEquals(new HtmlPage('foo'), $collection->get('_pages/foo.html'));

$this->restoreDefaultPages();
$this->restoreDocumentationSearch();
}

public function test_get_pages_returns_empty_collection_when_no_pages_are_discovered()
{
$this->withoutDefaultPages();
$this->withoutDocumentationSearch();
$this->assertEmpty(Pages::getPages());
$this->restoreDefaultPages();
$this->restoreDocumentationSearch();
}

public function test_pages_are_not_discovered_for_disabled_features()
Expand All @@ -155,6 +161,8 @@ public function test_pages_are_not_discovered_for_disabled_features()

public function test_pages_with_custom_source_directories_are_discovered_properly()
{
$this->withoutDocumentationSearch();

BladePage::setSourceDirectory('.source/pages');
MarkdownPage::setSourceDirectory('.source/pages');
MarkdownPost::setSourceDirectory('.source/posts');
Expand All @@ -177,6 +185,8 @@ public function test_pages_with_custom_source_directories_are_discovered_properl
$this->assertEquals(new MarkdownPage('foo'), $collection->get('.source/pages/foo.md'));
$this->assertEquals(new MarkdownPost('foo'), $collection->get('.source/posts/foo.md'));
$this->assertEquals(new DocumentationPage('foo'), $collection->get('.source/docs/foo.md'));

$this->restoreDocumentationSearch();
}

public function test_get_file_throws_exception_when_file_is_not_found()
Expand Down
23 changes: 23 additions & 0 deletions packages/testing/src/ResetsApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Hyde\Facades\Filesystem;
use Hyde\Hyde;
use function config;

trait ResetsApplication
{
Expand Down Expand Up @@ -50,6 +51,28 @@ protected function restoreDefaultPages(): void
copy(Hyde::vendorPath('resources/views/pages/404.blade.php'), Hyde::path('_pages/404.blade.php'));
}

/** @experimental We may want to make this a part of {@see static::withoutDefaultPages()} */
protected function withoutDocumentationSearch(): void
{
$features = config('hyde.features');

$flipped = array_flip($features);
unset($flipped['documentation-search']);
$features = array_flip($flipped);

config(['hyde.features' => $features]);
}

/** @experimental We may want to make this a part of {@see static::restoreDefaultPages()} */
protected function restoreDocumentationSearch(): void
{
$features = config('hyde.features');

$features[] = 'documentation-search';

config(['hyde.features' => $features]);
}

protected static function unlinkUnlessDefault(string $filepath): void
{
$protected = [
Expand Down

0 comments on commit ee5fa78

Please sign in to comment.