From 70236af5b65229affb6f95e3a32667fb9f455801 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Dec 2023 17:54:55 +0100 Subject: [PATCH] Run tests without documentation search feature --- .../tests/Feature/PageCollectionTest.php | 10 +++++++++ .../tests/Feature/RouteCollectionTest.php | 4 ++++ packages/testing/src/ResetsApplication.php | 22 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 19a961b761d..f055ae3bf24 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -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'); @@ -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'); @@ -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() @@ -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'); @@ -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() diff --git a/packages/framework/tests/Feature/RouteCollectionTest.php b/packages/framework/tests/Feature/RouteCollectionTest.php index 383ef835a47..e1b8c74a0dd 100644 --- a/packages/framework/tests/Feature/RouteCollectionTest.php +++ b/packages/framework/tests/Feature/RouteCollectionTest.php @@ -40,6 +40,7 @@ public function test_boot_method_discovers_all_pages() public function test_boot_method_discovers_all_page_types() { $this->withoutDefaultPages(); + $this->withoutDocumentationSearch(); $this->file('_pages/blade.blade.php'); $this->file('_pages/markdown.md'); @@ -61,6 +62,7 @@ public function test_boot_method_discovers_all_page_types() ], $collection->all()); $this->restoreDefaultPages(); + $this->restoreDocumentationSearch(); } public function test_get_routes_returns_all_routes() @@ -77,6 +79,7 @@ public function test_get_routes_returns_all_routes() public function test_get_routes_for_model_returns_collection_of_routes_of_given_class() { $this->withoutDefaultPages(); + $this->withoutDocumentationSearch(); $this->file('_pages/blade.blade.php'); $this->file('_pages/markdown.md'); @@ -94,6 +97,7 @@ public function test_get_routes_for_model_returns_collection_of_routes_of_given_ $this->assertEquals(new Route(new HtmlPage('html')), Routes::getRoutes(HtmlPage::class)->first()); $this->restoreDefaultPages(); + $this->restoreDocumentationSearch(); } public function test_add_route_adds_new_route() diff --git a/packages/testing/src/ResetsApplication.php b/packages/testing/src/ResetsApplication.php index f5db985f41f..96729828402 100644 --- a/packages/testing/src/ResetsApplication.php +++ b/packages/testing/src/ResetsApplication.php @@ -50,6 +50,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 = [