Skip to content

Commit

Permalink
Merge pull request #1303 from hydephp/update-unit-tests
Browse files Browse the repository at this point in the history
Update unit tests
  • Loading branch information
caendesilva authored Mar 15, 2023
2 parents 1eb533e + 893a0f0 commit c4006ef
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Hyde\Framework\Testing\Unit;
namespace Hyde\Framework\Testing\Feature;

use Hyde\Foundation\Internal\LoadYamlConfiguration;
use Illuminate\Contracts\Console\Kernel;
Expand Down
7 changes: 5 additions & 2 deletions packages/framework/tests/Unit/ConfigFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
use Hyde\Pages\HtmlPage;
use Hyde\Pages\MarkdownPage;
use Hyde\Pages\MarkdownPost;
use Hyde\Testing\TestCase;
use Hyde\Testing\UnitTestCase;
use ReflectionClass;

/**
* @see \Hyde\Framework\Testing\Unit\HydeConfigFilesAreMatchingTest
*/
class ConfigFileTest extends TestCase
class ConfigFileTest extends UnitTestCase
{
protected static bool $needsKernel = true;
protected static bool $needsConfig = true;

public function test_default_output_directory_value_matches_declared_value()
{
expect($this->getConfig('output_directory'))->toBe(Hyde::getOutputDirectory());
Expand Down
12 changes: 6 additions & 6 deletions packages/framework/tests/Unit/DateStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@
*/
class DateStringTest extends UnitTestCase
{
public function test_it_can_parse_date_string()
public function testItCanParseDateString()
{
$dateString = new DateString('2020-01-01');
$this->assertEquals('2020-01-01', $dateString->string);
}

public function test_it_can_parse_date_string_into_datetime_object()
public function testItCanParseDateStringIntoDatetimeObject()
{
$dateString = new DateString('2020-01-01 UTC');
$this->assertInstanceOf(DateTime::class, $dateString->dateTimeObject);
}

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

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

public function test_it_can_format_date_string_into_short_human_readable_string()
public function testItCanFormatDateStringIntoShortHumanReadableString()
{
$dateString = new DateString('2020-01-01 UTC');
$this->assertEquals('Jan 1st, 2020', $dateString->short);
}

public function test_it_can_format_date_string_into_short_human_readable_string_using_magic_method()
public function testItCanFormatDateStringIntoShortHumanReadableStringUsingMagicMethod()
{
$dateString = new DateString('2022-01-01 UTC');
$this->assertEquals('Jan 1st, 2022', (string) $dateString);
Expand Down
80 changes: 33 additions & 47 deletions packages/framework/tests/Unit/FrontMatterModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,114 +5,100 @@
namespace Hyde\Framework\Testing\Unit;

use Hyde\Markdown\Models\FrontMatter;
use PHPUnit\Framework\TestCase;
use Hyde\Testing\UnitTestCase;

/**
* @covers \Hyde\Markdown\Models\FrontMatter
*/
class FrontMatterModelTest extends TestCase
class FrontMatterModelTest extends UnitTestCase
{
public function test_constructor_creates_new_front_matter_model()
public function testConstructorCreatesNewFrontMatterModel()
{
$matter = new FrontMatter([]);
$this->assertInstanceOf(FrontMatter::class, $matter);
$this->assertInstanceOf(FrontMatter::class, new FrontMatter([]));
}

public function test_constructor_arguments_are_optional()
public function testConstructorArgumentsAreOptional()
{
$matter = new FrontMatter();
$this->assertInstanceOf(FrontMatter::class, $matter);
$this->assertInstanceOf(FrontMatter::class, new FrontMatter());
}

public function test_constructor_arguments_are_assigned()
public function testConstructorArgumentsAreAssigned()
{
$matter = new FrontMatter(['foo' => 'bar']);
$this->assertEquals(['foo' => 'bar'], $matter->toArray());
$this->assertEquals(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->toArray());
}

public function test_static_from_array_method_creates_new_front_matter_model()
public function testStaticFromArrayMethodCreatesNewFrontMatterModel()
{
$matter = FrontMatter::fromArray(['foo' => 'bar']);
$this->assertInstanceOf(FrontMatter::class, $matter);
$this->assertEquals(['foo' => 'bar'], $matter->toArray());
}

public function test_to_string_magic_method_converts_model_array_into_yaml_front_matter()
public function testToStringMagicMethodConvertsModelArrayIntoYamlFrontMatter()
{
$matter = new FrontMatter(['foo' => 'bar']);
$this->assertEquals("---\nfoo: bar\n---\n", (string) $matter);
$this->assertEquals("---\nfoo: bar\n---\n", (string) (new FrontMatter(['foo' => 'bar'])));
}

public function test_magic_get_method_returns_front_matter_property()
public function testMagicGetMethodReturnsFrontMatterProperty()
{
$matter = new FrontMatter(['foo' => 'bar']);
$this->assertEquals('bar', $matter->foo);
$this->assertEquals('bar', (new FrontMatter(['foo' => 'bar']))->foo);
}

public function test_magic_get_method_returns_null_if_property_does_not_exist()
public function testMagicGetMethodReturnsNullIfPropertyDoesNotExist()
{
$matter = new FrontMatter();
$this->assertNull($matter->foo);
$this->assertNull((new FrontMatter())->foo);
}

public function test_get_method_returns_data_when_no_argument_is_specified()
public function testGetMethodReturnsDataWhenNoArgumentIsSpecified()
{
$matter = new FrontMatter();
$this->assertSame([], $matter->get());
$this->assertSame([], (new FrontMatter())->get());
}

public function test_get_method_returns_data_when_no_argument_is_specified_with_data()
public function testGetMethodReturnsDataWhenNoArgumentIsSpecifiedWithData()
{
$matter = new FrontMatter(['foo' => 'bar']);
$this->assertSame(['foo' => 'bar'], $matter->get());
$this->assertSame(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->get());
}

public function test_get_method_returns_null_if_specified_front_matter_key_does_not_exist()
public function testGetMethodReturnsNullIfSpecifiedFrontMatterKeyDoesNotExist()
{
$matter = new FrontMatter();
$this->assertNull($matter->get('bar'));
$this->assertNull((new FrontMatter())->get('bar'));
}

public function test_get_method_returns_specified_default_value_if_property_does_not_exist()
public function testGetMethodReturnsSpecifiedDefaultValueIfPropertyDoesNotExist()
{
$matter = new FrontMatter();
$this->assertEquals('default', $matter->get('bar', 'default'));
}

public function test_get_method_returns_specified_front_matter_value_if_key_is_specified()
public function testGetMethodReturnsSpecifiedFrontMatterValueIfKeyIsSpecified()
{
$matter = new FrontMatter(['foo' => 'bar']);
$this->assertEquals('bar', $matter->get('foo'));
$this->assertEquals('bar', (new FrontMatter(['foo' => 'bar']))->get('foo'));
}

public function test_set_method_sets_front_matter_property()
public function testSetMethodSetsFrontMatterProperty()
{
$matter = new FrontMatter();
$matter->set('foo', 'bar');
$this->assertEquals('bar', $matter->get('foo'));
$this->assertEquals('bar', (new FrontMatter())->set('foo', 'bar')->get('foo'));
}

public function test_set_method_returns_self()
public function testSetMethodReturnsSelf()
{
$matter = new FrontMatter();
$this->assertSame($matter, $matter->set('foo', 'bar'));
}

public function test_has_method_returns_true_if_property_exists()
public function testHasMethodReturnsTrueIfPropertyExists()
{
$matter = new FrontMatter(['foo' => 'bar']);
$this->assertTrue($matter->has('foo'));
$this->assertTrue((new FrontMatter(['foo' => 'bar']))->has('foo'));
}

public function test_has_method_returns_false_if_property_does_not_exist()
public function testHasMethodReturnsFalseIfPropertyDoesNotExist()
{
$matter = new FrontMatter();
$this->assertFalse($matter->has('foo'));
$this->assertFalse((new FrontMatter())->has('foo'));
}

public function test_to_array_returns_front_matter_array()
public function testToArrayReturnsFrontMatterArray()
{
$matter = new FrontMatter(['foo' => 'bar']);
$this->assertEquals(['foo' => 'bar'], $matter->toArray());
$this->assertEquals(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->toArray());
}
}
34 changes: 18 additions & 16 deletions packages/framework/tests/Unit/HydeHelperFacadeMakeTitleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,45 @@
namespace Hyde\Framework\Testing\Unit;

use Hyde\Hyde;
use Hyde\Testing\TestCase;
use Hyde\Testing\UnitTestCase;

class HydeHelperFacadeMakeTitleTest extends TestCase
class HydeHelperFacadeMakeTitleTest extends UnitTestCase
{
public function test_make_title_helper_parses_kebab_case_into_title()
protected static bool $needsKernel = true;

public function testMakeTitleHelperParsesKebabCaseIntoTitle()
{
$this->assertEquals('Hello World', Hyde::makeTitle('hello-world'));
$this->assertSame('Hello World', Hyde::makeTitle('hello-world'));
}

public function test_make_title_helper_parses_snake_case_into_title()
public function testMakeTitleHelperParsesSnakeCaseIntoTitle()
{
$this->assertEquals('Hello World', Hyde::makeTitle('hello_world'));
$this->assertSame('Hello World', Hyde::makeTitle('hello_world'));
}

public function test_make_title_helper_parses_camel_case_into_title()
public function testMakeTitleHelperParsesCamelCaseIntoTitle()
{
$this->assertEquals('Hello World', Hyde::makeTitle('helloWorld'));
$this->assertSame('Hello World', Hyde::makeTitle('helloWorld'));
}

public function test_make_title_helper_parses_pascal_case_into_title()
public function testMakeTitleHelperParsesPascalCaseIntoTitle()
{
$this->assertEquals('Hello World', Hyde::makeTitle('HelloWorld'));
$this->assertSame('Hello World', Hyde::makeTitle('HelloWorld'));
}

public function test_make_title_helper_parses_title_case_into_title()
public function testMakeTitleHelperParsesTitleCaseIntoTitle()
{
$this->assertEquals('Hello World', Hyde::makeTitle('Hello World'));
$this->assertSame('Hello World', Hyde::makeTitle('Hello World'));
}

public function test_make_title_helper_parses_title_case_with_spaces_into_title()
public function testMakeTitleHelperParsesTitleCaseWithSpacesIntoTitle()
{
$this->assertEquals('Hello World', Hyde::makeTitle('Hello World'));
$this->assertSame('Hello World', Hyde::makeTitle('Hello World'));
}

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

0 comments on commit c4006ef

Please sign in to comment.