Skip to content

Commit

Permalink
Merge pull request #1808 from hydephp/update-testing-helpers
Browse files Browse the repository at this point in the history
Internal: Improve testing helpers hydephp/develop@faeaf9f
  • Loading branch information
github-actions authored and caendesilva committed Jul 8, 2024
1 parent 17e10bb commit 0bce45c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
8 changes: 5 additions & 3 deletions tests/Feature/BladeMatterParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,17 @@ public function testGetValueWithType()
{
$this->assertSame('string', ParserTestClass::getValueWithType('string'));
$this->assertSame('string', ParserTestClass::getValueWithType('string'));
$this->assertSame(true, ParserTestClass::getValueWithType('true'));
$this->assertSame(false, ParserTestClass::getValueWithType('false'));

$this->assertSame(1, ParserTestClass::getValueWithType('1'));
$this->assertSame(0, ParserTestClass::getValueWithType('0'));
$this->assertSame(1.0, ParserTestClass::getValueWithType('1.0'));
$this->assertSame(0.0, ParserTestClass::getValueWithType('0.0'));
$this->assertSame(null, ParserTestClass::getValueWithType('null'));
$this->assertSame(['foo' => 'bar'], ParserTestClass::getValueWithType('["foo" => "bar"]'));
$this->assertSame(['foo' => 'bar'], ParserTestClass::getValueWithType("['foo' => 'bar']"));

$this->assertTrue(ParserTestClass::getValueWithType('true'));
$this->assertFalse(ParserTestClass::getValueWithType('false'));
$this->assertNull(ParserTestClass::getValueWithType('null'));
}

public function testParseArrayString()
Expand Down
12 changes: 11 additions & 1 deletion tests/Feature/NavigationDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ public function testConstruct()

$this->assertSame('label', $navigationData->label);
$this->assertSame('group', $navigationData->group);
$this->assertSame(true, $navigationData->hidden);
$this->assertSame(1, $navigationData->priority);
$this->assertTrue($navigationData->hidden);
}

public function testConstructWithDifferentData()
{
$navigationData = new NavigationData('label', 2, false);

$this->assertSame('label', $navigationData->label);
$this->assertSame(2, $navigationData->priority);
$this->assertFalse($navigationData->hidden);
$this->assertNull($navigationData->group);
}

public function testMake()
Expand Down
8 changes: 7 additions & 1 deletion tests/Feature/TypedConfigFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function testGetBool()
{
config(['foo' => true]);
$this->assertIsBool(Config::getBool('foo'));

config(['foo' => false]);
$this->assertIsBool(Config::getBool('foo'));
}

public function testGetInt()
Expand All @@ -56,7 +59,8 @@ public function testGetStringWithDefaultValue()

public function testGetBoolWithDefaultValue()
{
$this->assertSame(true, Config::getBool('foo', true));
$this->assertTrue(Config::getBool('foo', true));
$this->assertFalse(Config::getBool('foo', false));
}

public function testGetIntWithDefaultValue()
Expand All @@ -82,6 +86,7 @@ public function testGetStringWithStrictMode()
public function testGetBoolWithStrictMode()
{
$this->runUnitTest(true, true, Config::getBool(...));
$this->runUnitTest(false, false, Config::getBool(...));
}

public function testGetIntWithStrictMode()
Expand Down Expand Up @@ -137,6 +142,7 @@ public function testGetStringWithString()
public function testGetBoolWithBool()
{
$this->runUnitTest(true, true, Config::getBool(...));
$this->runUnitTest(false, false, Config::getBool(...));
}

public function testGetIntWithInt()
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/YamlConfigurationFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public function testCanDefineHydeConfigSettingsInHydeYmlFile()

$this->assertSame('Test', config('hyde.name'));
$this->assertSame('http://localhost', config('hyde.url'));
$this->assertSame(false, config('hyde.pretty_urls'));
$this->assertSame(true, config('hyde.generate_sitemap'));
$this->assertSame(true, config('hyde.rss.enabled'));
$this->assertSame('feed.xml', config('hyde.rss.filename'));
$this->assertSame('Test RSS Feed', config('hyde.rss.description'));
$this->assertSame('en', config('hyde.language'));
$this->assertSame('_site', config('hyde.output_directory'));
$this->assertTrue(config('hyde.generate_sitemap'));
$this->assertTrue(config('hyde.rss.enabled'));
$this->assertFalse(config('hyde.pretty_urls'));
}

public function testCanDefineMultipleConfigSettingsInHydeYmlFile()
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ServeCommandOptionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function testCheckArgvForOption()
$command = $this->getMock();

$this->assertSame('true', $command->checkArgvForOption('pretty-urls'));
$this->assertSame(null, $command->checkArgvForOption('dashboard'));
$this->assertNull($command->checkArgvForOption('dashboard'));

$_SERVER = $serverBackup;
}
Expand Down
40 changes: 40 additions & 0 deletions tests/Unit/TestingSupportHelpersMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Hyde\Pages\InMemoryPage;
use Hyde\Testing\UnitTestCase;
use Hyde\Testing\MocksKernelFeatures;
use Hyde\Testing\FluentTestingHelpers;

/**
* Meta test for internal testing helpers.
Expand All @@ -19,6 +20,7 @@
class TestingSupportHelpersMetaTest extends UnitTestCase
{
use MocksKernelFeatures;
use FluentTestingHelpers;

protected static bool $needsKernel = true;
protected static bool $needsConfig = true;
Expand Down Expand Up @@ -61,6 +63,44 @@ public function testWithPagesWhenSupplyingStrings()
$this->assertContainsOnlyInstancesOf(InMemoryPage::class, $this->kernel->pages());
}

public function testAssertAllSameAssertsAllValuesAreTheSame()
{
$string = 'foo';
$array = ['foo'];
$object = (object) ['foo' => 'bar'];

$this->assertAllSame($string, 'foo', 'foo');
$this->assertAllSame($array, $array, $array);
$this->assertAllSame($object, $object, $object);
}

public function testAssertAllSameFailsWhenValuesAreNotEqual()
{
$tests = [
['foo', 'bar'],
[['foo'], ['bar']],
[(object) ['foo' => 'bar'], (object) ['foo' => 'baz']],
];

foreach ($tests as $expected) {
try {
$this->assertAllSame(...$expected);
} catch (\PHPUnit\Framework\AssertionFailedError $exception) {
$this->assertStringContainsString('Failed asserting that two', $exception->getMessage());
$this->assertStringContainsString('are equal.', $exception->getMessage());
}
}
}

public function testAssertAllSameFailsWhenValuesAreNotIdentical()
{
try {
$this->assertAllSame((object) ['foo' => 'bar'], (object) ['foo' => 'bar']);
} catch (\PHPUnit\Framework\AssertionFailedError $exception) {
$this->assertSame('Failed asserting that two variables reference the same object.', $exception->getMessage());
}
}

protected function getPageIdentifiers()
{
return $this->kernel->pages()->keys()->all();
Expand Down

0 comments on commit 0bce45c

Please sign in to comment.