Skip to content

Commit

Permalink
Add macroable trait to Hyde facade
Browse files Browse the repository at this point in the history
Add macroable trait to Hyde facade
Register Hyde::touch() macro when testing
Use the new internal Hyde::touch() helper
  • Loading branch information
caendesilva committed Jul 5, 2022
1 parent 7ff6e08 commit a966654
Show file tree
Hide file tree
Showing 22 changed files with 393 additions and 83 deletions.
2 changes: 2 additions & 0 deletions packages/framework/src/Hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Hyde\Framework\Concerns\Internal\FileHelpers;
use Hyde\Framework\Concerns\Internal\FluentPathHelpers;
use Hyde\Framework\Helpers\HydeHelperFacade;
use Illuminate\Support\Traits\Macroable;

/**
* General facade for Hyde services.
Expand All @@ -21,6 +22,7 @@ class Hyde
use FileHelpers;
use FluentPathHelpers;
use HydeHelperFacade;
use Macroable;

protected static string $basePath;

Expand Down
10 changes: 5 additions & 5 deletions packages/framework/tests/Feature/AbstractPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function test_get_parser_class_returns_static_property()

public function test_get_parser_returns_the_configured_parser_class()
{
touch(Hyde::path('_posts/foo.md'));
Hyde::touch(('_posts/foo.md'));

MarkdownPage::$parserClass = MarkdownPostParser::class;
$this->assertInstanceOf(MarkdownPostParser::class, MarkdownPage::getParser('foo'));
Expand All @@ -84,7 +84,7 @@ public function test_get_parser_returns_the_configured_parser_class()

public function test_get_parser_returns_instantiated_parser_for_the_supplied_slug()
{
touch(Hyde::path('_pages/foo.md'));
Hyde::touch(('_pages/foo.md'));

$this->assertInstanceOf(MarkdownPageParser::class, $parser = MarkdownPage::getParser('foo'));
$this->assertEquals('foo', $parser->get()->slug);
Expand All @@ -94,7 +94,7 @@ public function test_get_parser_returns_instantiated_parser_for_the_supplied_slu

public function test_parse_parses_supplied_slug_into_a_page_model()
{
touch(Hyde::path('_pages/foo.md'));
Hyde::touch(('_pages/foo.md'));

$this->assertInstanceOf(MarkdownPage::class, $page = MarkdownPage::parse('foo'));
$this->assertEquals('foo', $page->slug);
Expand All @@ -104,14 +104,14 @@ public function test_parse_parses_supplied_slug_into_a_page_model()

public function test_files_returns_array_of_source_files()
{
touch(Hyde::path('_pages/foo.md'));
Hyde::touch(('_pages/foo.md'));
$this->assertEquals(['foo'], MarkdownPage::files());
unlink(Hyde::path('_pages/foo.md'));
}

public function test_all_returns_collection_of_all_source_files_parsed_into_the_model()
{
touch(Hyde::path('_pages/foo.md'));
Hyde::touch(('_pages/foo.md'));
$this->assertEquals(
collect([new MarkdownPage([], '', '', 'foo')]),
MarkdownPage::all()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function test_it_generates_a_json_file_with_a_search_index()
{
$this->resetDocs();

touch(Hyde::path('_docs/foo.md'));
Hyde::touch(('_docs/foo.md'));

$expected = [
[
Expand All @@ -51,9 +51,9 @@ public function test_it_generates_a_json_file_with_a_search_index()

public function test_it_adds_all_files_to_search_index()
{
touch(Hyde::path('_docs/foo.md'));
touch(Hyde::path('_docs/bar.md'));
touch(Hyde::path('_docs/baz.md'));
Hyde::touch(('_docs/foo.md'));
Hyde::touch(('_docs/bar.md'));
Hyde::touch(('_docs/baz.md'));

$this->assertCount(3, (new Action())->generate()->searchIndex);

Expand Down Expand Up @@ -97,9 +97,9 @@ public function test_generate_page_object_method_generates_a_page_object()

public function test_get_source_file_slugs_returns_valid_array_for_source_files()
{
touch(Hyde::path('_docs/a.md'));
touch(Hyde::path('_docs/b.md'));
touch(Hyde::path('_docs/c.md'));
Hyde::touch(('_docs/a.md'));
Hyde::touch(('_docs/b.md'));
Hyde::touch(('_docs/c.md'));

$this->assertEquals(
['a', 'b', 'c'], (new Action())->getSourceFileSlugs()
Expand Down Expand Up @@ -152,7 +152,7 @@ public function test_get_destination_for_slug_returns_pretty_url_when_enabled()

public function test_excluded_pages_are_not_present_in_the_search_index()
{
touch(Hyde::path('_docs/excluded.md'));
Hyde::touch(('_docs/excluded.md'));
config(['docs.exclude_from_search' => ['excluded']]);

$this->assertNotContains('excluded', (new Action())->getSourceFileSlugs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function test_rss_feed_is_generated_when_conditions_are_met()
config(['hyde.site_url' => 'https://example.com']);
config(['hyde.generate_rss_feed' => true]);

touch(Hyde::path('_posts/foo.md'));
Hyde::touch(('_posts/foo.md'));

$this->artisan('build')
->expectsOutput('Generating RSS feed...')
Expand All @@ -138,7 +138,7 @@ public function test_does_not_generate_search_files_when_conditions_are_not_met(

public function test_generates_search_files_when_conditions_are_met()
{
touch(Hyde::path('_docs/foo.md'));
Hyde::touch(('_docs/foo.md'));

$this->artisan('build')
->expectsOutput('Generating documentation site search index...')
Expand All @@ -148,7 +148,7 @@ public function test_generates_search_files_when_conditions_are_met()

public function test_site_directory_is_emptied_before_build()
{
touch(Hyde::path('_site/foo.html'));
Hyde::touch(('_site/foo.html'));
$this->artisan('build')
->expectsOutput('Removing all files from build directory.')
->assertExitCode(0);
Expand All @@ -158,7 +158,7 @@ public function test_site_directory_is_emptied_before_build()
public function test_output_directory_is_not_emptied_if_disabled_in_config()
{
config(['hyde.empty_output_directory' => false]);
touch(Hyde::path('_site/keep.html'));
Hyde::touch(('_site/keep.html'));

$this->artisan('build')
->doesntExpectOutput('Removing all files from build directory.')
Expand All @@ -173,7 +173,7 @@ public function test_aborts_when_non_standard_directory_is_emptied()
StaticPageBuilder::$outputPath = 'foo';

mkdir(Hyde::path('foo'));
touch(Hyde::path('foo/keep.html'));
Hyde::touch(('foo/keep.html'));

$this->artisan('build')
->expectsOutput('Removing all files from build directory.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test_media_files_can_be_transferred()
deleteDirectory(Hyde::path('_site/media'));
mkdir(Hyde::path('_site/media'));

touch(Hyde::path('_media/test.jpg'));
Hyde::touch(('_media/test.jpg'));

$this->artisan('rebuild _media')
->assertExitCode(0);
Expand Down Expand Up @@ -59,7 +59,7 @@ public function test_validate_catches_missing_file()

public function test_rebuild_documentation_page()
{
touch(Hyde::path('_docs/foo.md'));
Hyde::touch(('_docs/foo.md'));

$this->artisan('rebuild _docs/foo.md')
->assertExitCode(0);
Expand All @@ -72,7 +72,7 @@ public function test_rebuild_documentation_page()

public function test_rebuild_blog_post()
{
touch(Hyde::path('_posts/foo.md'));
Hyde::touch(('_posts/foo.md'));

$this->artisan('rebuild _posts/foo.md')
->assertExitCode(0);
Expand Down
22 changes: 11 additions & 11 deletions packages/framework/tests/Feature/DataCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public function test_get_markdown_files_method_returns_empty_array_if_no_files_a
public function test_get_markdown_files_method_returns_an_array_of_markdown_files_in_the_specified_directory()
{
mkdir(Hyde::path('_data/foo'));
touch(Hyde::path('_data/foo/foo.md'));
touch(Hyde::path('_data/foo/bar.md'));
Hyde::touch(('_data/foo/foo.md'));
Hyde::touch(('_data/foo/bar.md'));

$this->assertEquals([
Hyde::path('_data/foo/bar.md'),
Expand All @@ -94,8 +94,8 @@ public function test_get_markdown_files_method_does_not_include_files_in_subdire
{
mkdir(Hyde::path('_data/foo'));
mkdir(Hyde::path('_data/foo/bar'));
touch(Hyde::path('_data/foo/foo.md'));
touch(Hyde::path('_data/foo/bar/bar.md'));
Hyde::touch(('_data/foo/foo.md'));
Hyde::touch(('_data/foo/bar/bar.md'));
$this->assertEquals([
Hyde::path('_data/foo/foo.md'),
], (new DataCollection('foo'))->getMarkdownFiles());
Expand All @@ -105,8 +105,8 @@ public function test_get_markdown_files_method_does_not_include_files_in_subdire
public function test_get_markdown_files_method_does_not_include_files_with_extensions_other_than_md()
{
mkdir(Hyde::path('_data/foo'));
touch(Hyde::path('_data/foo/foo.md'));
touch(Hyde::path('_data/foo/bar.txt'));
Hyde::touch(('_data/foo/foo.md'));
Hyde::touch(('_data/foo/bar.txt'));
$this->assertEquals([
Hyde::path('_data/foo/foo.md'),
], (new DataCollection('foo'))->getMarkdownFiles());
Expand All @@ -121,8 +121,8 @@ public function test_static_markdown_helper_returns_new_data_collection_instance
public function test_static_markdown_helper_discovers_and_parses_markdown_files_in_the_specified_directory()
{
mkdir(Hyde::path('_data/foo'));
touch(Hyde::path('_data/foo/foo.md'));
touch(Hyde::path('_data/foo/bar.md'));
Hyde::touch(('_data/foo/foo.md'));
Hyde::touch(('_data/foo/bar.md'));

$collection = DataCollection::markdown('foo');

Expand All @@ -134,8 +134,8 @@ public function test_static_markdown_helper_discovers_and_parses_markdown_files_
public function test_static_markdown_helper_ignores_files_starting_with_an_underscore()
{
mkdir(Hyde::path('_data/foo'));
touch(Hyde::path('_data/foo/foo.md'));
touch(Hyde::path('_data/foo/_bar.md'));
Hyde::touch(('_data/foo/foo.md'));
Hyde::touch(('_data/foo/_bar.md'));
$this->assertCount(1, DataCollection::markdown('foo'));
File::deleteDirectory(Hyde::path('_data/foo'));
}
Expand Down Expand Up @@ -188,7 +188,7 @@ public function test_source_directory_can_be_changed()
{
DataCollection::$sourceDirectory = 'foo';
mkdir(Hyde::path('foo/bar'), recursive: true);
touch(Hyde::path('foo/bar/foo.md'));
Hyde::touch(('foo/bar/foo.md'));
$this->assertEquals([
Hyde::path('foo/bar/foo.md'),
], (new DataCollection('bar'))->getMarkdownFiles());
Expand Down
8 changes: 4 additions & 4 deletions packages/framework/tests/Feature/DiscoveryServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class DiscoveryServiceTest extends TestCase
{
public function createContentSourceTestFiles()
{
touch(Hyde::path(DiscoveryService::getFilePathForModelClassFiles(MarkdownPost::class).'/test.md'));
touch(Hyde::path(DiscoveryService::getFilePathForModelClassFiles(MarkdownPage::class).'/test.md'));
touch(Hyde::path(DiscoveryService::getFilePathForModelClassFiles(DocumentationPage::class).'/test.md'));
touch(Hyde::path(DiscoveryService::getFilePathForModelClassFiles(BladePage::class).'/test.blade.php'));
Hyde::touch((DiscoveryService::getFilePathForModelClassFiles(MarkdownPost::class).'/test.md'));
Hyde::touch((DiscoveryService::getFilePathForModelClassFiles(MarkdownPage::class).'/test.md'));
Hyde::touch((DiscoveryService::getFilePathForModelClassFiles(DocumentationPage::class).'/test.md'));
Hyde::touch((DiscoveryService::getFilePathForModelClassFiles(BladePage::class).'/test.blade.php'));
}

public function deleteContentSourceTestFiles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function test_get_method_returns_array()

public function test_generated_links_include_documentation_pages()
{
touch(Hyde::path('_docs/index.md'));
Hyde::touch(('_docs/index.md'));

$generator = new GeneratesNavigationMenu('index');
$this->assertIsArray($generator->links);
Expand Down Expand Up @@ -65,8 +65,8 @@ public function test_get_links_from_config_method()

public function test_files_starting_with_underscores_are_ignored()
{
touch(Hyde::path('_pages/_foo.md'));
touch(Hyde::path('_pages/_foo.blade.php'));
Hyde::touch(('_pages/_foo.md'));
Hyde::touch(('_pages/_foo.blade.php'));

$array = GeneratesNavigationMenu::getNavigationLinks();
$this->assertIsArray($array);
Expand Down
Loading

0 comments on commit a966654

Please sign in to comment.