Skip to content

Commit

Permalink
Merge pull request #1960 from hydephp/test-cleanup
Browse files Browse the repository at this point in the history
Internal: Test code refactors and cleanup hydephp/develop@1eb4502
  • Loading branch information
github-actions authored and caendesilva committed Dec 21, 2024
1 parent 1fabbd8 commit d0ee682
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 140 deletions.
2 changes: 1 addition & 1 deletion tests/Unit/AssetServiceUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AssetServiceUnitTest extends UnitTestCase
{
protected function setUp(): void
{
self::setupKernel();
self::resetKernel();
self::mockConfig();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/BaseFoundationCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BaseFoundationCollectionTest extends UnitTestCase
{
public function testBaseFoundationCollectionInitialization()
{
$this->setupKernel();
self::resetKernel();

$booted = BaseFoundationCollectionTestClass::init(HydeKernel::getInstance())->boot();

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/BreadcrumbsComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BreadcrumbsComponentTest extends UnitTestCase
{
protected function setUp(): void
{
self::setupKernel();
self::resetKernel();
self::mockConfig();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/BuildTaskUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function testCanWriteToOutput()

public function testCreatedSiteFile()
{
self::setupKernel();
self::resetKernel();

$task = new BufferedTestBuildTask();

Expand All @@ -164,7 +164,7 @@ public function testCreatedSiteFile()

public function testCreatedSiteFileWithAbsolutePath()
{
self::setupKernel();
self::resetKernel();

$task = new BufferedTestBuildTask();

Expand Down
35 changes: 32 additions & 3 deletions tests/Unit/Facades/AuthorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,37 @@
namespace Hyde\Framework\Testing\Unit\Facades;

use Hyde\Facades\Author;
use Hyde\Testing\UnitTestCase;
use Hyde\Framework\Features\Blogging\Models\PostAuthor;
use Hyde\Testing\TestCase;

/**
* @covers \Hyde\Facades\Author
*/
class AuthorTest extends TestCase
class AuthorTest extends UnitTestCase
{
protected function setUp(): void
{
self::mockConfig(['hyde.authors' => [
Author::create('mr_hyde', 'Mr. Hyde', 'https://hydephp.com'),
]]);
}

public function testCreate()
{
$author = Author::create('john_doe', 'John Doe', 'https://johndoe.com');

$this->assertSame('john_doe', $author->username);
$this->assertSame('John Doe', $author->name);
$this->assertSame('https://johndoe.com', $author->website);
}

$this->assertEquals(Author::create('foo', null, null), Author::create('foo'));
public function testCreateWithOnlyRequiredFields()
{
$author = Author::create('john_doe');

$this->assertSame('john_doe', $author->username);
$this->assertSame('john_doe', $author->name);
$this->assertNull($author->website);
}

public function testGet()
Expand All @@ -31,7 +45,15 @@ public function testGet()
$this->assertSame('mr_hyde', $author->username);
$this->assertSame('Mr. Hyde', $author->name);
$this->assertSame('https://hydephp.com', $author->website);
}

public function testGetWithNotSetUsername()
{
$this->assertEquals(Author::create('foo'), Author::get('foo'));
}

public function testGetAliasesPostAuthor()
{
$this->assertEquals(PostAuthor::get('foo'), Author::get('foo'));
}

Expand All @@ -40,5 +62,12 @@ public function testAll()
$authors = Author::all();
$this->assertCount(1, $authors);
$this->assertContainsOnlyInstancesOf(PostAuthor::class, $authors);
$this->assertEquals(Author::get('mr_hyde'), $authors->first());
}

public function testAllWithNoAuthors()
{
self::mockConfig(['hyde.authors' => []]);
$this->assertEmpty(Author::all());
}
}
4 changes: 1 addition & 3 deletions tests/Unit/HtmlTestingSupportMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class HtmlTestingSupportMetaTest extends UnitTestCase

protected function setUp(): void
{
parent::setUp();

self::setupKernel();
self::resetKernel();

$this->html ??= file_get_contents(Hyde::vendorPath('resources/views/homepages/welcome.blade.php'));
}
Expand Down
7 changes: 5 additions & 2 deletions tests/Unit/NavItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
*/
class NavItemTest extends UnitTestCase
{
protected static bool $needsKernel = true;
protected static bool $needsConfig = true;
public static function setUpBeforeClass(): void
{
self::resetKernel();
self::mockConfig();
}

protected function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/NavigationDataFactoryUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NavigationDataFactoryUnitTest extends UnitTestCase
{
protected function setUp(): void
{
self::setupKernel();
self::resetKernel();
self::mockConfig();
}

Expand Down
62 changes: 0 additions & 62 deletions tests/Unit/Pages/PageModelGetAllFilesHelperTest.php

This file was deleted.

63 changes: 0 additions & 63 deletions tests/Unit/Pages/PageModelGetHelperTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Unit/UnixsumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testMethodReturnsSameValueForStringWithMixedEndOfLineSequences()

public function testMethodReturnsSameValueWhenLoadedFromFileUsingShorthand()
{
self::setupKernel();
self::resetKernel();

$string = "foo\nbar\r\nbaz\r\n";

Expand Down

0 comments on commit d0ee682

Please sign in to comment.