Skip to content

Commit d0ee682

Browse files
github-actionscaendesilva
github-actions
authored andcommitted
Merge pull request #1960 from hydephp/test-cleanup
Internal: Test code refactors and cleanup hydephp/develop@1eb4502
1 parent 1fabbd8 commit d0ee682

11 files changed

+45
-140
lines changed

Diff for: tests/Unit/AssetServiceUnitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AssetServiceUnitTest extends UnitTestCase
1717
{
1818
protected function setUp(): void
1919
{
20-
self::setupKernel();
20+
self::resetKernel();
2121
self::mockConfig();
2222
}
2323

Diff for: tests/Unit/BaseFoundationCollectionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BaseFoundationCollectionTest extends UnitTestCase
1717
{
1818
public function testBaseFoundationCollectionInitialization()
1919
{
20-
$this->setupKernel();
20+
self::resetKernel();
2121

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

Diff for: tests/Unit/BreadcrumbsComponentTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class BreadcrumbsComponentTest extends UnitTestCase
2323
{
2424
protected function setUp(): void
2525
{
26-
self::setupKernel();
26+
self::resetKernel();
2727
self::mockConfig();
2828
}
2929

Diff for: tests/Unit/BuildTaskUnitTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function testCanWriteToOutput()
153153

154154
public function testCreatedSiteFile()
155155
{
156-
self::setupKernel();
156+
self::resetKernel();
157157

158158
$task = new BufferedTestBuildTask();
159159

@@ -164,7 +164,7 @@ public function testCreatedSiteFile()
164164

165165
public function testCreatedSiteFileWithAbsolutePath()
166166
{
167-
self::setupKernel();
167+
self::resetKernel();
168168

169169
$task = new BufferedTestBuildTask();
170170

Diff for: tests/Unit/Facades/AuthorTest.php

+32-3
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,37 @@
55
namespace Hyde\Framework\Testing\Unit\Facades;
66

77
use Hyde\Facades\Author;
8+
use Hyde\Testing\UnitTestCase;
89
use Hyde\Framework\Features\Blogging\Models\PostAuthor;
9-
use Hyde\Testing\TestCase;
1010

1111
/**
1212
* @covers \Hyde\Facades\Author
1313
*/
14-
class AuthorTest extends TestCase
14+
class AuthorTest extends UnitTestCase
1515
{
16+
protected function setUp(): void
17+
{
18+
self::mockConfig(['hyde.authors' => [
19+
Author::create('mr_hyde', 'Mr. Hyde', 'https://hydephp.com'),
20+
]]);
21+
}
22+
1623
public function testCreate()
1724
{
1825
$author = Author::create('john_doe', 'John Doe', 'https://johndoe.com');
1926

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

24-
$this->assertEquals(Author::create('foo', null, null), Author::create('foo'));
32+
public function testCreateWithOnlyRequiredFields()
33+
{
34+
$author = Author::create('john_doe');
35+
36+
$this->assertSame('john_doe', $author->username);
37+
$this->assertSame('john_doe', $author->name);
38+
$this->assertNull($author->website);
2539
}
2640

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

50+
public function testGetWithNotSetUsername()
51+
{
52+
$this->assertEquals(Author::create('foo'), Author::get('foo'));
53+
}
54+
55+
public function testGetAliasesPostAuthor()
56+
{
3557
$this->assertEquals(PostAuthor::get('foo'), Author::get('foo'));
3658
}
3759

@@ -40,5 +62,12 @@ public function testAll()
4062
$authors = Author::all();
4163
$this->assertCount(1, $authors);
4264
$this->assertContainsOnlyInstancesOf(PostAuthor::class, $authors);
65+
$this->assertEquals(Author::get('mr_hyde'), $authors->first());
66+
}
67+
68+
public function testAllWithNoAuthors()
69+
{
70+
self::mockConfig(['hyde.authors' => []]);
71+
$this->assertEmpty(Author::all());
4372
}
4473
}

Diff for: tests/Unit/HtmlTestingSupportMetaTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ class HtmlTestingSupportMetaTest extends UnitTestCase
3131

3232
protected function setUp(): void
3333
{
34-
parent::setUp();
35-
36-
self::setupKernel();
34+
self::resetKernel();
3735

3836
$this->html ??= file_get_contents(Hyde::vendorPath('resources/views/homepages/welcome.blade.php'));
3937
}

Diff for: tests/Unit/NavItemTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
*/
2626
class NavItemTest extends UnitTestCase
2727
{
28-
protected static bool $needsKernel = true;
29-
protected static bool $needsConfig = true;
28+
public static function setUpBeforeClass(): void
29+
{
30+
self::resetKernel();
31+
self::mockConfig();
32+
}
3033

3134
protected function setUp(): void
3235
{

Diff for: tests/Unit/NavigationDataFactoryUnitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class NavigationDataFactoryUnitTest extends UnitTestCase
1919
{
2020
protected function setUp(): void
2121
{
22-
self::setupKernel();
22+
self::resetKernel();
2323
self::mockConfig();
2424
}
2525

Diff for: tests/Unit/Pages/PageModelGetAllFilesHelperTest.php

-62
This file was deleted.

Diff for: tests/Unit/Pages/PageModelGetHelperTest.php

-63
This file was deleted.

Diff for: tests/Unit/UnixsumTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testMethodReturnsSameValueForStringWithMixedEndOfLineSequences()
6363

6464
public function testMethodReturnsSameValueWhenLoadedFromFileUsingShorthand()
6565
{
66-
self::setupKernel();
66+
self::resetKernel();
6767

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

0 commit comments

Comments
 (0)