Skip to content

Commit

Permalink
Merge pull request #1653 from hydephp/improve-test-suite
Browse files Browse the repository at this point in the history
Internal: Improve test suite hydephp/develop@bcd26e3
  • Loading branch information
github-actions committed Apr 10, 2024
1 parent 29bf246 commit a5b3a9f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Hyde\Framework\Testing\Feature;
namespace Hyde\Framework\Testing\Feature\Views;

use Hyde\Foundation\HydeKernel;
use Hyde\Hyde;
use Hyde\Testing\TestCase;
use Hyde\Foundation\HydeKernel;

/**
* This tests ensures all metadata is rendered correctly in the compiled pages.
Expand Down
6 changes: 2 additions & 4 deletions tests/Feature/Views/SidebarBrandViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Hyde\Framework\Testing\Feature\Views;

use Hyde\Hyde;
use Hyde\Facades\Features;
use Hyde\Testing\TestCase;
use Hyde\Foundation\HydeKernel;
use Hyde\Testing\TestsBladeViews;
use Hyde\Pages\DocumentationPage;

Expand Down Expand Up @@ -59,9 +59,7 @@ public function testSidebarBrandViewWithDefaultHeaderTextAndHomeRoute()

public function testSidebarBrandViewWithoutDarkmodeFeature()
{
$mock = $this->mock(HydeKernel::class)->makePartial();
$mock->shouldReceive('hasFeature')->with('darkmode')->andReturn(false);
HydeKernel::setInstance($mock);
Features::mock('darkmode', false);

$view = $this->view(view('hyde::components.docs.sidebar-brand'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

declare(strict_types=1);

namespace Hyde\Framework\Testing\Feature;
namespace Hyde\Framework\Testing\Feature\Views;

use Hyde\Framework\Features\Navigation\DocumentationSidebar;
use Hyde\Hyde;
use Throwable;
use Hyde\Testing\TestCase;
use Illuminate\Contracts\View\View;
use Throwable;
use Hyde\Framework\Features\Navigation\DocumentationSidebar;

/**
* Very high level test of the sidebar views and their combinations of layouts.
Expand Down Expand Up @@ -39,8 +38,7 @@ public function testBaseSidebar()
->assertSeeHtml('<a href="index.html">Back to home page</a>')
->assertSeeHtml('<span class="sr-only">Toggle dark theme</span>')
->assertDontSee('<a href="docs/index.html">')
->assertDontSee('<li class="sidebar-item')
->allGood();
->assertDontSee('<li class="sidebar-item');

$this->assertViewWasRendered(view('hyde::components.docs.sidebar-items', [
'sidebar' => DocumentationSidebar::create(),
Expand All @@ -66,8 +64,7 @@ public function testBaseSidebarWithCustomFooterText()
$this->renderComponent(view('hyde::components.docs.sidebar'))
->assertSeeHtml('<footer id="sidebar-footer"')
->assertSeeHtml('<p>My <strong>Markdown</strong> Footer Text</p>')
->assertDontSee('Back to home page')
->allGood();
->assertDontSee('Back to home page');
}

public function testBaseSidebarCustomHeaderBrand()
Expand All @@ -76,8 +73,7 @@ public function testBaseSidebarCustomHeaderBrand()

$this->renderComponent(view('hyde::components.docs.sidebar'))
->assertSeeText('My Custom Header')
->assertDontSee('HydePHP Docs')
->allGood();
->assertDontSee('HydePHP Docs');

$this->assertViewWasRendered(view('hyde::components.docs.sidebar-brand'));
}
Expand All @@ -92,8 +88,7 @@ public function testBaseSidebarWithItems()
->assertSeeHtml('<a href="docs/index.html">')
->assertSeeHtml('<nav id="sidebar-navigation"')
->assertSeeHtml('<ul id="sidebar-items" role="list" class="pl-2">')
->assertSeeHtml('<li class="sidebar-item')
->allGood();
->assertSeeHtml('<li class="sidebar-item');

$this->assertViewWasRendered(view('hyde::components.docs.sidebar-items', [
'sidebar' => DocumentationSidebar::create(),
Expand All @@ -120,8 +115,7 @@ public function testSidebarWithGroupedItems()
->assertSeeHtml('class="sidebar-group-toggle')
->assertSeeHtml('class="sidebar-group-toggle-icon')
->assertSeeHtml('class="sidebar-group-items')
->assertSee('groupOpen')
->allGood();
->assertSee('groupOpen');

$this->assertViewWasRendered(view('hyde::components.docs.sidebar-items', [
'sidebar' => DocumentationSidebar::create(),
Expand Down Expand Up @@ -152,8 +146,7 @@ public function testSidebarWithNonCollapsibleGroupedItems()
->assertSeeHtml('class="sidebar-group-items')
->assertDontSee('sidebar-group-toggle')
->assertDontSee('sidebar-group-toggle-icon')
->assertDontSee('groupOpen')
->allGood();
->assertDontSee('groupOpen');

$this->assertViewWasRendered(view('hyde::components.docs.sidebar-items', [
'sidebar' => DocumentationSidebar::create(),
Expand All @@ -167,16 +160,7 @@ protected function renderComponent(View $view): self
{
try {
$this->html = $view->render();
/** @noinspection LaravelFunctionsInspection */
if (env('TEST_HTML_DEBUG', false)) {
file_put_contents(Hyde::path('_site/test.html'), $this->html);
echo "\e[0;32mCreated file: \e[0m".realpath(Hyde::path('_site/test.html'));
}
} catch (Throwable $exception) {
/** @noinspection LaravelFunctionsInspection */
if (env('TEST_HTML_DEBUG', false)) {
throw $exception;
}
$this->fail($exception->getMessage());
}

Expand Down Expand Up @@ -226,11 +210,4 @@ protected function assertDontSee(string $text): self

return $this;
}

protected function allGood(): self
{
// Just an empty helper so we get easier Git diffs when adding new assertions.

return $this;
}
}
12 changes: 6 additions & 6 deletions tests/Unit/BreadcrumbsComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

namespace Hyde\Framework\Testing\Unit;

use Hyde\Framework\Views\Components\BreadcrumbsComponent;
use Mockery;
use Illuminate\View\Factory;
use Hyde\Pages\MarkdownPage;
use Hyde\Support\Facades\Render;
use Hyde\Support\Models\Route;
use Hyde\Testing\UnitTestCase;
use Illuminate\Support\Facades\Facade;
use Hyde\Support\Facades\Render;
use Illuminate\Support\Facades\View;
use Illuminate\View\Factory;
use Mockery;
use Illuminate\Support\Facades\Facade;
use Hyde\Framework\Views\Components\BreadcrumbsComponent;

/**
* @covers \Hyde\Framework\Views\Components\BreadcrumbsComponent
*
* @see \Hyde\Framework\Testing\Unit\BreadcrumbsComponentViewTest
* @see \Hyde\Framework\Testing\Unit\Views\BreadcrumbsComponentViewTest
*/
class BreadcrumbsComponentTest extends UnitTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

declare(strict_types=1);

namespace Hyde\Framework\Testing\Unit;
namespace Hyde\Framework\Testing\Unit\Views;

use Hyde\Framework\Views\Components\BreadcrumbsComponent;
use Hyde\Testing\TestCase;
use Hyde\Pages\MarkdownPage;
use Hyde\Support\Facades\Render;
use Hyde\Testing\TestCase;
use Illuminate\Support\Facades\Blade;
use Hyde\Framework\Views\Components\BreadcrumbsComponent;

/**
* @covers \Hyde\Framework\Views\Components\BreadcrumbsComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Hyde\Framework\Testing\Unit\Views\Components;
namespace Hyde\Framework\Testing\Unit\Views;

use Hyde\Foundation\Facades\Routes;
use Hyde\Support\Facades\Render;
use Hyde\Testing\TestCase;
use Hyde\Support\Facades\Render;
use Hyde\Foundation\Facades\Routes;
use Illuminate\Support\Facades\Blade;

/**
Expand Down

0 comments on commit a5b3a9f

Please sign in to comment.