Skip to content

Commit c4006ef

Browse files
authored
Merge pull request #1303 from hydephp/update-unit-tests
Update unit tests
2 parents 1eb533e + 893a0f0 commit c4006ef

File tree

5 files changed

+63
-72
lines changed

5 files changed

+63
-72
lines changed

packages/framework/tests/Unit/ConsoleKernelTest.php renamed to packages/framework/tests/Feature/ConsoleKernelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Hyde\Framework\Testing\Unit;
5+
namespace Hyde\Framework\Testing\Feature;
66

77
use Hyde\Foundation\Internal\LoadYamlConfiguration;
88
use Illuminate\Contracts\Console\Kernel;

packages/framework/tests/Unit/ConfigFileTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
use Hyde\Pages\HtmlPage;
1313
use Hyde\Pages\MarkdownPage;
1414
use Hyde\Pages\MarkdownPost;
15-
use Hyde\Testing\TestCase;
15+
use Hyde\Testing\UnitTestCase;
1616
use ReflectionClass;
1717

1818
/**
1919
* @see \Hyde\Framework\Testing\Unit\HydeConfigFilesAreMatchingTest
2020
*/
21-
class ConfigFileTest extends TestCase
21+
class ConfigFileTest extends UnitTestCase
2222
{
23+
protected static bool $needsKernel = true;
24+
protected static bool $needsConfig = true;
25+
2326
public function test_default_output_directory_value_matches_declared_value()
2427
{
2528
expect($this->getConfig('output_directory'))->toBe(Hyde::getOutputDirectory());

packages/framework/tests/Unit/DateStringTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,37 @@
1313
*/
1414
class DateStringTest extends UnitTestCase
1515
{
16-
public function test_it_can_parse_date_string()
16+
public function testItCanParseDateString()
1717
{
1818
$dateString = new DateString('2020-01-01');
1919
$this->assertEquals('2020-01-01', $dateString->string);
2020
}
2121

22-
public function test_it_can_parse_date_string_into_datetime_object()
22+
public function testItCanParseDateStringIntoDatetimeObject()
2323
{
2424
$dateString = new DateString('2020-01-01 UTC');
2525
$this->assertInstanceOf(DateTime::class, $dateString->dateTimeObject);
2626
}
2727

28-
public function test_it_can_format_date_string_into_machine_readable_string()
28+
public function testItCanFormatDateStringIntoMachineReadableString()
2929
{
3030
$dateString = new DateString('2020-01-01 UTC');
3131
$this->assertEquals('2020-01-01T00:00:00+00:00', $dateString->datetime);
3232
}
3333

34-
public function test_it_can_format_date_string_into_human_readable_string()
34+
public function testItCanFormatDateStringIntoHumanReadableString()
3535
{
3636
$dateString = new DateString('2020-01-01 UTC');
3737
$this->assertEquals('Wednesday Jan 1st, 2020, at 12:00am', $dateString->sentence);
3838
}
3939

40-
public function test_it_can_format_date_string_into_short_human_readable_string()
40+
public function testItCanFormatDateStringIntoShortHumanReadableString()
4141
{
4242
$dateString = new DateString('2020-01-01 UTC');
4343
$this->assertEquals('Jan 1st, 2020', $dateString->short);
4444
}
4545

46-
public function test_it_can_format_date_string_into_short_human_readable_string_using_magic_method()
46+
public function testItCanFormatDateStringIntoShortHumanReadableStringUsingMagicMethod()
4747
{
4848
$dateString = new DateString('2022-01-01 UTC');
4949
$this->assertEquals('Jan 1st, 2022', (string) $dateString);

packages/framework/tests/Unit/FrontMatterModelTest.php

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,114 +5,100 @@
55
namespace Hyde\Framework\Testing\Unit;
66

77
use Hyde\Markdown\Models\FrontMatter;
8-
use PHPUnit\Framework\TestCase;
8+
use Hyde\Testing\UnitTestCase;
99

1010
/**
1111
* @covers \Hyde\Markdown\Models\FrontMatter
1212
*/
13-
class FrontMatterModelTest extends TestCase
13+
class FrontMatterModelTest extends UnitTestCase
1414
{
15-
public function test_constructor_creates_new_front_matter_model()
15+
public function testConstructorCreatesNewFrontMatterModel()
1616
{
17-
$matter = new FrontMatter([]);
18-
$this->assertInstanceOf(FrontMatter::class, $matter);
17+
$this->assertInstanceOf(FrontMatter::class, new FrontMatter([]));
1918
}
2019

21-
public function test_constructor_arguments_are_optional()
20+
public function testConstructorArgumentsAreOptional()
2221
{
23-
$matter = new FrontMatter();
24-
$this->assertInstanceOf(FrontMatter::class, $matter);
22+
$this->assertInstanceOf(FrontMatter::class, new FrontMatter());
2523
}
2624

27-
public function test_constructor_arguments_are_assigned()
25+
public function testConstructorArgumentsAreAssigned()
2826
{
29-
$matter = new FrontMatter(['foo' => 'bar']);
30-
$this->assertEquals(['foo' => 'bar'], $matter->toArray());
27+
$this->assertEquals(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->toArray());
3128
}
3229

33-
public function test_static_from_array_method_creates_new_front_matter_model()
30+
public function testStaticFromArrayMethodCreatesNewFrontMatterModel()
3431
{
3532
$matter = FrontMatter::fromArray(['foo' => 'bar']);
3633
$this->assertInstanceOf(FrontMatter::class, $matter);
3734
$this->assertEquals(['foo' => 'bar'], $matter->toArray());
3835
}
3936

40-
public function test_to_string_magic_method_converts_model_array_into_yaml_front_matter()
37+
public function testToStringMagicMethodConvertsModelArrayIntoYamlFrontMatter()
4138
{
4239
$matter = new FrontMatter(['foo' => 'bar']);
43-
$this->assertEquals("---\nfoo: bar\n---\n", (string) $matter);
40+
$this->assertEquals("---\nfoo: bar\n---\n", (string) (new FrontMatter(['foo' => 'bar'])));
4441
}
4542

46-
public function test_magic_get_method_returns_front_matter_property()
43+
public function testMagicGetMethodReturnsFrontMatterProperty()
4744
{
48-
$matter = new FrontMatter(['foo' => 'bar']);
49-
$this->assertEquals('bar', $matter->foo);
45+
$this->assertEquals('bar', (new FrontMatter(['foo' => 'bar']))->foo);
5046
}
5147

52-
public function test_magic_get_method_returns_null_if_property_does_not_exist()
48+
public function testMagicGetMethodReturnsNullIfPropertyDoesNotExist()
5349
{
54-
$matter = new FrontMatter();
55-
$this->assertNull($matter->foo);
50+
$this->assertNull((new FrontMatter())->foo);
5651
}
5752

58-
public function test_get_method_returns_data_when_no_argument_is_specified()
53+
public function testGetMethodReturnsDataWhenNoArgumentIsSpecified()
5954
{
60-
$matter = new FrontMatter();
61-
$this->assertSame([], $matter->get());
55+
$this->assertSame([], (new FrontMatter())->get());
6256
}
6357

64-
public function test_get_method_returns_data_when_no_argument_is_specified_with_data()
58+
public function testGetMethodReturnsDataWhenNoArgumentIsSpecifiedWithData()
6559
{
66-
$matter = new FrontMatter(['foo' => 'bar']);
67-
$this->assertSame(['foo' => 'bar'], $matter->get());
60+
$this->assertSame(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->get());
6861
}
6962

70-
public function test_get_method_returns_null_if_specified_front_matter_key_does_not_exist()
63+
public function testGetMethodReturnsNullIfSpecifiedFrontMatterKeyDoesNotExist()
7164
{
72-
$matter = new FrontMatter();
73-
$this->assertNull($matter->get('bar'));
65+
$this->assertNull((new FrontMatter())->get('bar'));
7466
}
7567

76-
public function test_get_method_returns_specified_default_value_if_property_does_not_exist()
68+
public function testGetMethodReturnsSpecifiedDefaultValueIfPropertyDoesNotExist()
7769
{
7870
$matter = new FrontMatter();
7971
$this->assertEquals('default', $matter->get('bar', 'default'));
8072
}
8173

82-
public function test_get_method_returns_specified_front_matter_value_if_key_is_specified()
74+
public function testGetMethodReturnsSpecifiedFrontMatterValueIfKeyIsSpecified()
8375
{
84-
$matter = new FrontMatter(['foo' => 'bar']);
85-
$this->assertEquals('bar', $matter->get('foo'));
76+
$this->assertEquals('bar', (new FrontMatter(['foo' => 'bar']))->get('foo'));
8677
}
8778

88-
public function test_set_method_sets_front_matter_property()
79+
public function testSetMethodSetsFrontMatterProperty()
8980
{
90-
$matter = new FrontMatter();
91-
$matter->set('foo', 'bar');
92-
$this->assertEquals('bar', $matter->get('foo'));
81+
$this->assertEquals('bar', (new FrontMatter())->set('foo', 'bar')->get('foo'));
9382
}
9483

95-
public function test_set_method_returns_self()
84+
public function testSetMethodReturnsSelf()
9685
{
9786
$matter = new FrontMatter();
9887
$this->assertSame($matter, $matter->set('foo', 'bar'));
9988
}
10089

101-
public function test_has_method_returns_true_if_property_exists()
90+
public function testHasMethodReturnsTrueIfPropertyExists()
10291
{
103-
$matter = new FrontMatter(['foo' => 'bar']);
104-
$this->assertTrue($matter->has('foo'));
92+
$this->assertTrue((new FrontMatter(['foo' => 'bar']))->has('foo'));
10593
}
10694

107-
public function test_has_method_returns_false_if_property_does_not_exist()
95+
public function testHasMethodReturnsFalseIfPropertyDoesNotExist()
10896
{
109-
$matter = new FrontMatter();
110-
$this->assertFalse($matter->has('foo'));
97+
$this->assertFalse((new FrontMatter())->has('foo'));
11198
}
11299

113-
public function test_to_array_returns_front_matter_array()
100+
public function testToArrayReturnsFrontMatterArray()
114101
{
115-
$matter = new FrontMatter(['foo' => 'bar']);
116-
$this->assertEquals(['foo' => 'bar'], $matter->toArray());
102+
$this->assertEquals(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->toArray());
117103
}
118104
}

packages/framework/tests/Unit/HydeHelperFacadeMakeTitleTest.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,45 @@
55
namespace Hyde\Framework\Testing\Unit;
66

77
use Hyde\Hyde;
8-
use Hyde\Testing\TestCase;
8+
use Hyde\Testing\UnitTestCase;
99

10-
class HydeHelperFacadeMakeTitleTest extends TestCase
10+
class HydeHelperFacadeMakeTitleTest extends UnitTestCase
1111
{
12-
public function test_make_title_helper_parses_kebab_case_into_title()
12+
protected static bool $needsKernel = true;
13+
14+
public function testMakeTitleHelperParsesKebabCaseIntoTitle()
1315
{
14-
$this->assertEquals('Hello World', Hyde::makeTitle('hello-world'));
16+
$this->assertSame('Hello World', Hyde::makeTitle('hello-world'));
1517
}
1618

17-
public function test_make_title_helper_parses_snake_case_into_title()
19+
public function testMakeTitleHelperParsesSnakeCaseIntoTitle()
1820
{
19-
$this->assertEquals('Hello World', Hyde::makeTitle('hello_world'));
21+
$this->assertSame('Hello World', Hyde::makeTitle('hello_world'));
2022
}
2123

22-
public function test_make_title_helper_parses_camel_case_into_title()
24+
public function testMakeTitleHelperParsesCamelCaseIntoTitle()
2325
{
24-
$this->assertEquals('Hello World', Hyde::makeTitle('helloWorld'));
26+
$this->assertSame('Hello World', Hyde::makeTitle('helloWorld'));
2527
}
2628

27-
public function test_make_title_helper_parses_pascal_case_into_title()
29+
public function testMakeTitleHelperParsesPascalCaseIntoTitle()
2830
{
29-
$this->assertEquals('Hello World', Hyde::makeTitle('HelloWorld'));
31+
$this->assertSame('Hello World', Hyde::makeTitle('HelloWorld'));
3032
}
3133

32-
public function test_make_title_helper_parses_title_case_into_title()
34+
public function testMakeTitleHelperParsesTitleCaseIntoTitle()
3335
{
34-
$this->assertEquals('Hello World', Hyde::makeTitle('Hello World'));
36+
$this->assertSame('Hello World', Hyde::makeTitle('Hello World'));
3537
}
3638

37-
public function test_make_title_helper_parses_title_case_with_spaces_into_title()
39+
public function testMakeTitleHelperParsesTitleCaseWithSpacesIntoTitle()
3840
{
39-
$this->assertEquals('Hello World', Hyde::makeTitle('Hello World'));
41+
$this->assertSame('Hello World', Hyde::makeTitle('Hello World'));
4042
}
4143

42-
public function test_make_title_helper_does_not_capitalize_auxiliary_words()
44+
public function testMakeTitleHelperDoesNotCapitalizeAuxiliaryWords()
4345
{
44-
$this->assertEquals('The a an the in on by with of and or but',
46+
$this->assertSame('The a an the in on by with of and or but',
4547
Hyde::makeTitle('the_a_an_the_in_on_by_with_of_and_or_but'));
4648
}
4749
}

0 commit comments

Comments
 (0)