diff --git a/tests/Feature/BladeMatterParserTest.php b/tests/Feature/BladeMatterParserTest.php index c7c07ca8..eac6d4a7 100644 --- a/tests/Feature/BladeMatterParserTest.php +++ b/tests/Feature/BladeMatterParserTest.php @@ -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() diff --git a/tests/Feature/NavigationDataTest.php b/tests/Feature/NavigationDataTest.php index 1eaf47f6..de433810 100644 --- a/tests/Feature/NavigationDataTest.php +++ b/tests/Feature/NavigationDataTest.php @@ -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() diff --git a/tests/Feature/TypedConfigFacadeTest.php b/tests/Feature/TypedConfigFacadeTest.php index b313dc2d..dd5af604 100644 --- a/tests/Feature/TypedConfigFacadeTest.php +++ b/tests/Feature/TypedConfigFacadeTest.php @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/tests/Feature/YamlConfigurationFeatureTest.php b/tests/Feature/YamlConfigurationFeatureTest.php index 41362764..872c8ffb 100644 --- a/tests/Feature/YamlConfigurationFeatureTest.php +++ b/tests/Feature/YamlConfigurationFeatureTest.php @@ -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() diff --git a/tests/Unit/ServeCommandOptionsUnitTest.php b/tests/Unit/ServeCommandOptionsUnitTest.php index 073734e9..23061551 100644 --- a/tests/Unit/ServeCommandOptionsUnitTest.php +++ b/tests/Unit/ServeCommandOptionsUnitTest.php @@ -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; } diff --git a/tests/Unit/TestingSupportHelpersMetaTest.php b/tests/Unit/TestingSupportHelpersMetaTest.php index b27bff28..83c69454 100644 --- a/tests/Unit/TestingSupportHelpersMetaTest.php +++ b/tests/Unit/TestingSupportHelpersMetaTest.php @@ -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. @@ -19,6 +20,7 @@ class TestingSupportHelpersMetaTest extends UnitTestCase { use MocksKernelFeatures; + use FluentTestingHelpers; protected static bool $needsKernel = true; protected static bool $needsConfig = true; @@ -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();