diff --git a/monorepo/HydeStan/HydeStan.php b/monorepo/HydeStan/HydeStan.php index 4dd8c0731e5..26c8f4218d6 100644 --- a/monorepo/HydeStan/HydeStan.php +++ b/monorepo/HydeStan/HydeStan.php @@ -12,6 +12,7 @@ final class HydeStan const VERSION = '0.0.0-dev'; private array $files; + private array $testFiles; private array $errors = []; private int $scannedLines = 0; private int $aggregateLines = 0; @@ -37,10 +38,13 @@ public function __construct(private readonly bool $debug = false) public function __destruct() { $this->console->newline(); - $this->console->info(sprintf('HydeStan has exited after scanning %s total (and %s aggregate) lines in %s files. Total expressions analysed: %s', + $this->console->info(sprintf('HydeStan has exited after scanning %s total (and %s aggregate) lines in %s files.', number_format($this->scannedLines), number_format($this->aggregateLines), - number_format(count($this->files)), + number_format(count($this->files) + count($this->testFiles)), + )); + + $this->console->info(sprintf('Total expressions analysed: %s', number_format(AnalysisStatisticsContainer::getExpressionsAnalysed()), )); @@ -64,6 +68,8 @@ public function run(): void $this->analyseFile($file, $this->getFileContents($file)); } + $this->runTestStan(); + $endTime = microtime(true) - $time; $this->console->info(sprintf('HydeStan has finished in %s seconds (%sms) using %s KB RAM', number_format($endTime, 2), @@ -112,6 +118,21 @@ private function getFiles(): array return $files; } + private function getTestFiles(): array + { + $files = []; + + $directory = new RecursiveDirectoryIterator(BASE_PATH.'/tests'); + $iterator = new RecursiveIteratorIterator($directory); + $regex = new RegexIterator($iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH); + + foreach ($regex as $file) { + $files[] = substr($file[0], strlen(BASE_PATH) + 1); + } + + return $files; + } + private function analyseFile(string $file, string $contents): void { $fileAnalysers = [ @@ -160,6 +181,51 @@ public static function addActionsMessage(string $level, string $file, int $lineN // $template = '::warning file={name},line={line},endLine={endLine},title={title}::{message}'; self::$warnings[] = sprintf("::$level file=%s,line=%s,endLine=%s,title=%s::%s", 'packages/framework/'.str_replace('\\', '/', $file), $lineNumber, $lineNumber, $title, $message); } + + protected function runTestStan(): void + { + $this->console->info('TestStan: Analyzing test files...'); + + $this->testFiles = $this->getTestFiles(); + + foreach ($this->testFiles as $file) { + $this->analyseTestFile($file, $this->getFileContents($file)); + } + + $this->console->info('TestStan: Finished analyzing test files!'); + } + + private function analyseTestFile(string $file, string $contents): void + { + $fileAnalysers = [ + new NoFixMeAnalyser($file, $contents), + new NoUsingAssertEqualsForScalarTypesTestAnalyser($file, $contents), + ]; + + foreach ($fileAnalysers as $analyser) { + if ($this->debug) { + $this->console->debugComment('Running '.$analyser::class); + } + + $analyser->run($file, $contents); + AnalysisStatisticsContainer::countedLines(substr_count($contents, "\n")); + + foreach (explode("\n", $contents) as $lineNumber => $line) { + $lineAnalysers = [ + // + ]; + + foreach ($lineAnalysers as $analyser) { + AnalysisStatisticsContainer::countedLine(); + $analyser->run($file, $lineNumber, $line); + $this->aggregateLines++; + } + } + } + + $this->scannedLines += substr_count($contents, "\n"); + $this->aggregateLines += (substr_count($contents, "\n") * count($fileAnalysers)); + } } abstract class Analyser @@ -215,6 +281,39 @@ public function run(string $file, string $contents): void } } +class NoUsingAssertEqualsForScalarTypesTestAnalyser extends FileAnalyser // Todo: Extend line analyser instead? Would allow for checking for more errors after the first error +{ + public function run(string $file, string $contents): void + { + $searches = [ + "assertEquals('", + ]; + + foreach ($searches as $search) { + AnalysisStatisticsContainer::analysedExpression(); + + if (str_contains($contents, $search)) { + // Get line number of marker by counting new \n tags before it + $stringBeforeMarker = substr($contents, 0, strpos($contents, $search)); + $lineNumber = substr_count($stringBeforeMarker, "\n") + 1; + + // Get the line contents + $line = explode("\n", $contents)[$lineNumber - 1]; + + // Check for false positives + $commonlyStringCastables = ['$article', '$document', 'getXmlElement()', '$url->loc', '$page->markdown', '$post->data(\'author\')']; + + if (check_str_contains_any($commonlyStringCastables, $line)) { + continue; + } + + // Todo: Does not work when using objects to string cast, false positive, maybe use warning instead of fail + $this->fail(sprintf('Found %s instead assertSame for scalar type in %s on line %s', trim($search, "()'"), $file, $lineNumber)); + } + } + } +} + class UnImportedFunctionAnalyser extends FileAnalyser { public function run(string $file, string $contents): void @@ -319,3 +418,16 @@ public function __construct(string $file, int $lineNumber, string $line); public function run(string $file, int $lineNumber, string $line): void; } + +function check_str_contains_any(array $searches, string $line): bool +{ + $strContainsAny = false; + foreach ($searches as $search) { + AnalysisStatisticsContainer::analysedExpression(); + if (str_contains($line, $search)) { + $strContainsAny = true; + } + } + + return $strContainsAny; +} diff --git a/packages/framework/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php b/packages/framework/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php index 195da02b12a..12660727644 100644 --- a/packages/framework/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php +++ b/packages/framework/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php @@ -25,21 +25,22 @@ public function testDiscoveredShortcodesAreUsedToProcessInput() { $processor = new ShortcodeProcessor('>info foo'); - $this->assertEquals('
', - $processor->run()); + $this->assertSame('foo
', $processor->run()); } public function testStringWithoutShortcodeIsNotModified() { $processor = new ShortcodeProcessor('foo'); - $this->assertEquals('foo', $processor->run()); + $this->assertSame('foo', $processor->run()); } public function testProcessStaticShorthand() { - $this->assertEquals('foo
', - ShortcodeProcessor::preprocess('>info foo')); + $this->assertSame( + 'foo
', + ShortcodeProcessor::preprocess('>info foo') + ); } public function testShortcodesCanBeAddedToProcessor() @@ -60,7 +61,7 @@ public static function resolve(string $input): string }); $this->assertArrayHasKey('foo', $processor->getShortcodes()); - $this->assertEquals('bar', $processor->run()); + $this->assertSame('bar', $processor->run()); } public function testShortcodesCanBeAddedToProcessorUsingArray() @@ -81,6 +82,6 @@ public static function resolve(string $input): string }]); $this->assertArrayHasKey('foo', $processor->getShortcodes()); - $this->assertEquals('bar', $processor->run()); + $this->assertSame('bar', $processor->run()); } } diff --git a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php index 79ab3e124a2..e8ca9f8d518 100644 --- a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php +++ b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php @@ -28,7 +28,7 @@ public function testServiceInstantiatesXmlElement() public function testXmlRootElementIsSetToRss20() { $service = new RssFeedGenerator(); - $this->assertEquals('rss', $service->getXmlElement()->getName()); + $this->assertSame('rss', $service->getXmlElement()->getName()); $this->assertEquals('2.0', $service->getXmlElement()->attributes()->version); } diff --git a/packages/framework/tests/Feature/Support/ProjectFileTest.php b/packages/framework/tests/Feature/Support/ProjectFileTest.php index a33c0b73bc4..892ae7ff4f6 100644 --- a/packages/framework/tests/Feature/Support/ProjectFileTest.php +++ b/packages/framework/tests/Feature/Support/ProjectFileTest.php @@ -21,19 +21,19 @@ public function testCanConstruct() $this->assertSame('foo', $file->path); } - public function can_make() + public function testCanMake() { $this->assertEquals(new ProjectFileTestClass('foo'), ProjectFileTestClass::make('foo')); } public function testCanConstructWithNestedPaths() { - $this->assertEquals('path/to/file.txt', ProjectFileTestClass::make('path/to/file.txt')->path); + $this->assertSame('path/to/file.txt', ProjectFileTestClass::make('path/to/file.txt')->path); } public function testAbsolutePathIsNormalizedToRelative() { - $this->assertEquals('foo', ProjectFileTestClass::make(Hyde::path('foo'))->path); + $this->assertSame('foo', ProjectFileTestClass::make(Hyde::path('foo'))->path); } public function testGetNameReturnsNameOfFile() diff --git a/packages/framework/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php b/packages/framework/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php index 7eabdeeb79d..5d684061b4e 100644 --- a/packages/framework/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php +++ b/packages/framework/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php @@ -31,126 +31,126 @@ protected function setUp(): void public function testHelperReturnsStringAsIsIfCurrentIsNotSet() { - $this->assertEquals('foo/bar.html', Hyde::relativeLink('foo/bar.html')); + $this->assertSame('foo/bar.html', Hyde::relativeLink('foo/bar.html')); } public function testHelperInjectsProperNumberOfDoublesSlash() { $this->mockCurrentPage('foo/bar.html'); - $this->assertEquals('../foo.html', Hyde::relativeLink('foo.html')); + $this->assertSame('../foo.html', Hyde::relativeLink('foo.html')); } public function testHelperInjectsProperNumberOfDoublesSlashForDeeplyNestedPaths() { $this->mockCurrentPage('foo/bar/baz/qux.html'); - $this->assertEquals('../../../foo.html', Hyde::relativeLink('foo.html')); + $this->assertSame('../../../foo.html', Hyde::relativeLink('foo.html')); } public function testHelperHandlesDestinationWithoutFileExtension() { $this->mockCurrentPage('foo/bar.html'); - $this->assertEquals('../foo', Hyde::relativeLink('foo')); + $this->assertSame('../foo', Hyde::relativeLink('foo')); } public function testHelperHandlesCurrentWithoutFileExtension() { $this->mockCurrentPage('foo/bar'); - $this->assertEquals('../foo.html', Hyde::relativeLink('foo.html')); + $this->assertSame('../foo.html', Hyde::relativeLink('foo.html')); } public function testHelperHandlesCaseWithoutAnyFileExtensions() { $this->mockCurrentPage('foo/bar'); - $this->assertEquals('../foo', Hyde::relativeLink('foo')); + $this->assertSame('../foo', Hyde::relativeLink('foo')); } public function testHelperHandlesCaseWithMixedFileExtensions() { $this->mockCurrentPage('foo/bar.md'); - $this->assertEquals('../foo.md', Hyde::relativeLink('foo.md')); + $this->assertSame('../foo.md', Hyde::relativeLink('foo.md')); $this->mockCurrentPage('foo/bar.txt'); - $this->assertEquals('../foo.txt', Hyde::relativeLink('foo.txt')); + $this->assertSame('../foo.txt', Hyde::relativeLink('foo.txt')); } public function testHelperHandlesDifferentFileExtensions() { $this->mockCurrentPage('foo/bar'); - $this->assertEquals('../foo.png', Hyde::relativeLink('foo.png')); - $this->assertEquals('../foo.css', Hyde::relativeLink('foo.css')); - $this->assertEquals('../foo.js', Hyde::relativeLink('foo.js')); + $this->assertSame('../foo.png', Hyde::relativeLink('foo.png')); + $this->assertSame('../foo.css', Hyde::relativeLink('foo.css')); + $this->assertSame('../foo.js', Hyde::relativeLink('foo.js')); } public function testHelperReturnsPrettyUrlIfEnabledAndDestinationIsAHtmlFile() { self::mockConfig(['hyde.pretty_urls' => true]); $this->mockCurrentPage('foo/bar.html'); - $this->assertEquals('../foo', Hyde::relativeLink('foo.html')); + $this->assertSame('../foo', Hyde::relativeLink('foo.html')); } public function testHelperMethodDoesNotRequireCurrentPathToBeHtmlToUsePrettyUrls() { self::mockConfig(['hyde.pretty_urls' => true]); $this->mockCurrentPage('foo/bar'); - $this->assertEquals('../foo', Hyde::relativeLink('foo.html')); + $this->assertSame('../foo', Hyde::relativeLink('foo.html')); } public function testHelperReturnsDoesNotReturnPrettyUrlIfWhenEnabledButAndDestinationIsNotAHtmlFile() { self::mockConfig(['hyde.pretty_urls' => true]); $this->mockCurrentPage('foo/bar.html'); - $this->assertEquals('../foo.png', Hyde::relativeLink('foo.png')); + $this->assertSame('../foo.png', Hyde::relativeLink('foo.png')); } public function testHelperRewritesIndexWhenUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => true]); $this->mockCurrentPage('foo.html'); - $this->assertEquals('./', Hyde::relativeLink('index.html')); + $this->assertSame('./', Hyde::relativeLink('index.html')); $this->mockCurrentPage('foo/bar.html'); - $this->assertEquals('../', Hyde::relativeLink('index.html')); + $this->assertSame('../', Hyde::relativeLink('index.html')); $this->mockCurrentPage('foo/bar/baz.html'); - $this->assertEquals('../../', Hyde::relativeLink('index.html')); + $this->assertSame('../../', Hyde::relativeLink('index.html')); } public function testHelperDoesNotRewriteIndexWhenNotUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => false]); $this->mockCurrentPage('foo.html'); - $this->assertEquals('index.html', Hyde::relativeLink('index.html')); + $this->assertSame('index.html', Hyde::relativeLink('index.html')); $this->mockCurrentPage('foo/bar.html'); - $this->assertEquals('../index.html', Hyde::relativeLink('index.html')); + $this->assertSame('../index.html', Hyde::relativeLink('index.html')); $this->mockCurrentPage('foo/bar/baz.html'); - $this->assertEquals('../../index.html', Hyde::relativeLink('index.html')); + $this->assertSame('../../index.html', Hyde::relativeLink('index.html')); } public function testHelperRewritesDocumentationPageIndexWhenUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => true]); $this->mockCurrentPage('foo.html'); - $this->assertEquals('docs/', Hyde::relativeLink('docs/index.html')); + $this->assertSame('docs/', Hyde::relativeLink('docs/index.html')); $this->mockCurrentPage('docs.html'); - $this->assertEquals('docs/', Hyde::relativeLink('docs/index.html')); + $this->assertSame('docs/', Hyde::relativeLink('docs/index.html')); $this->mockCurrentPage('foo/bar.html'); - $this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html')); + $this->assertSame('../docs/', Hyde::relativeLink('docs/index.html')); $this->mockCurrentPage('docs/foo.html'); - $this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html')); + $this->assertSame('../docs/', Hyde::relativeLink('docs/index.html')); } public function testHelperDoesNotRewriteDocumentationPageIndexWhenNotUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => false]); $this->mockCurrentPage('foo.html'); - $this->assertEquals('docs/index.html', Hyde::relativeLink('docs/index.html')); + $this->assertSame('docs/index.html', Hyde::relativeLink('docs/index.html')); $this->mockCurrentPage('docs.html'); - $this->assertEquals('docs/index.html', Hyde::relativeLink('docs/index.html')); + $this->assertSame('docs/index.html', Hyde::relativeLink('docs/index.html')); $this->mockCurrentPage('foo/bar.html'); - $this->assertEquals('../docs/index.html', Hyde::relativeLink('docs/index.html')); + $this->assertSame('../docs/index.html', Hyde::relativeLink('docs/index.html')); $this->mockCurrentPage('docs/foo.html'); - $this->assertEquals('../docs/index.html', Hyde::relativeLink('docs/index.html')); + $this->assertSame('../docs/index.html', Hyde::relativeLink('docs/index.html')); } public function testHelperDoesNotRewriteAlreadyProcessedLinks() { - $this->assertEquals('../foo', Hyde::relativeLink('../foo')); + $this->assertSame('../foo', Hyde::relativeLink('../foo')); } } diff --git a/packages/framework/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php b/packages/framework/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php index b92c4b133fe..3151a9772bb 100644 --- a/packages/framework/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php +++ b/packages/framework/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php @@ -19,85 +19,85 @@ public function testHelperReturnsStringAsIsIfPrettyUrlsIsNotTrue() { self::mockConfig(['hyde.pretty_urls' => false]); - $this->assertEquals('foo/bar.html', Hyde::formatLink('foo/bar.html')); + $this->assertSame('foo/bar.html', Hyde::formatLink('foo/bar.html')); } public function testHelperReturnsPrettyUrlIfPrettyUrlsIsTrue() { self::mockConfig(['hyde.pretty_urls' => true]); - $this->assertEquals('foo/bar', Hyde::formatLink('foo/bar.html')); + $this->assertSame('foo/bar', Hyde::formatLink('foo/bar.html')); } public function testHelperRespectsAbsoluteUrls() { self::mockConfig(['hyde.pretty_urls' => false]); - $this->assertEquals('/foo/bar.html', Hyde::formatLink('/foo/bar.html')); + $this->assertSame('/foo/bar.html', Hyde::formatLink('/foo/bar.html')); } public function testHelperRespectsPrettyAbsoluteUrls() { self::mockConfig(['hyde.pretty_urls' => true]); - $this->assertEquals('/foo/bar', Hyde::formatLink('/foo/bar.html')); + $this->assertSame('/foo/bar', Hyde::formatLink('/foo/bar.html')); } public function testHelperRespectsRelativeUrls() { self::mockConfig(['hyde.pretty_urls' => false]); - $this->assertEquals('../foo/bar.html', Hyde::formatLink('../foo/bar.html')); + $this->assertSame('../foo/bar.html', Hyde::formatLink('../foo/bar.html')); } public function testHelperRespectsPrettyRelativeUrls() { self::mockConfig(['hyde.pretty_urls' => true]); - $this->assertEquals('../foo/bar', Hyde::formatLink('../foo/bar.html')); + $this->assertSame('../foo/bar', Hyde::formatLink('../foo/bar.html')); } public function testNonHtmlLinksAreNotModified() { self::mockConfig(['hyde.pretty_urls' => true]); - $this->assertEquals('/foo/bar.jpg', Hyde::formatLink('/foo/bar.jpg')); + $this->assertSame('/foo/bar.jpg', Hyde::formatLink('/foo/bar.jpg')); } public function testHelperRespectsAbsoluteUrlsWithPrettyUrlsEnabled() { self::mockConfig(['hyde.pretty_urls' => true]); - $this->assertEquals('/foo/bar.jpg', Hyde::formatLink('/foo/bar.jpg')); + $this->assertSame('/foo/bar.jpg', Hyde::formatLink('/foo/bar.jpg')); } public function testHelperRewritesIndexWhenUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => true]); - $this->assertEquals('/', Hyde::formatLink('index.html')); + $this->assertSame('/', Hyde::formatLink('index.html')); } public function testHelperDoesNotRewriteIndexWhenNotUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => false]); - $this->assertEquals('index.html', Hyde::formatLink('index.html')); + $this->assertSame('index.html', Hyde::formatLink('index.html')); } public function testHelperRewritesDocumentationPageIndexWhenUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => true]); - $this->assertEquals('docs/', Hyde::formatLink('docs/index.html')); + $this->assertSame('docs/', Hyde::formatLink('docs/index.html')); } public function testHelperDoesNotRewriteDocumentationPageIndexWhenNotUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => false]); - $this->assertEquals('docs/index.html', Hyde::formatLink('docs/index.html')); + $this->assertSame('docs/index.html', Hyde::formatLink('docs/index.html')); } public function testHelpersRewritesArbitraryNestedIndexPagesWhenUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => true]); - $this->assertEquals('foo/bar/', Hyde::formatLink('foo/bar/index.html')); + $this->assertSame('foo/bar/', Hyde::formatLink('foo/bar/index.html')); } public function testHelpersDoesNotRewriteArbitraryNestedIndexPagesWhenNotUsingPrettyUrls() { self::mockConfig(['hyde.pretty_urls' => false]); - $this->assertEquals('foo/bar/index.html', Hyde::formatLink('foo/bar/index.html')); + $this->assertSame('foo/bar/index.html', Hyde::formatLink('foo/bar/index.html')); } } diff --git a/packages/framework/tests/Unit/Pages/HtmlPageTest.php b/packages/framework/tests/Unit/Pages/HtmlPageTest.php index 1551b7d23ad..f976cb444aa 100644 --- a/packages/framework/tests/Unit/Pages/HtmlPageTest.php +++ b/packages/framework/tests/Unit/Pages/HtmlPageTest.php @@ -18,7 +18,7 @@ public function testHtmlPageCanBeCompiled() $page = new HtmlPage('foo'); - $this->assertEquals('bar', $page->compile()); + $this->assertSame('bar', $page->compile()); } public function testCompileMethodUsesContents() diff --git a/packages/framework/tests/Unit/Pages/MarkdownPageTest.php b/packages/framework/tests/Unit/Pages/MarkdownPageTest.php index 712ccdb84e7..ba28e199462 100644 --- a/packages/framework/tests/Unit/Pages/MarkdownPageTest.php +++ b/packages/framework/tests/Unit/Pages/MarkdownPageTest.php @@ -27,9 +27,10 @@ public function testCreatedModelContainsExpectedData() $this->file('_pages/test-page.md', "# Test Page \n Hello World!"); $page = MarkdownPage::parse('test-page'); - $this->assertEquals('Test Page', $page->title); + $this->assertSame('Test Page', $page->title); + $this->assertSame('test-page', $page->identifier); + $this->assertSame("# Test Page \n Hello World!", $page->markdown->body()); $this->assertEquals("# Test Page \n Hello World!", $page->markdown); - $this->assertEquals('test-page', $page->identifier); } public function testCanRenderMarkdownPage() diff --git a/packages/framework/tests/Unit/Pages/MarkdownPostParserTest.php b/packages/framework/tests/Unit/Pages/MarkdownPostParserTest.php index c6b0d4f7eb8..8c933156651 100644 --- a/packages/framework/tests/Unit/Pages/MarkdownPostParserTest.php +++ b/packages/framework/tests/Unit/Pages/MarkdownPostParserTest.php @@ -4,12 +4,11 @@ namespace Hyde\Framework\Testing\Unit\Pages; -use Hyde\Facades\Filesystem; -use Hyde\Hyde; use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; use Hyde\Pages\MarkdownPost; use Hyde\Testing\TestCase; +use Hyde\Framework\Features\Blogging\Models\PostAuthor; /** * @see \Hyde\Framework\Testing\Feature\StaticSiteBuilderPostModuleTest for the compiler test. @@ -20,28 +19,25 @@ protected function setUp(): void { parent::setUp(); - file_put_contents(Hyde::path('_posts/test-post.md'), '--- -title: My New Post -category: blog -author: Mr. Hyde ---- + $this->file('_posts/test-post.md', <<<'MD' + --- + title: My New Post + category: blog + author: Mr. Hyde + --- -# My New Post + # My New Post -This is a post stub used in the automated tests -'); - } - - protected function tearDown(): void - { - Filesystem::unlink('_posts/test-post.md'); + This is a post stub used in the automated tests - parent::tearDown(); + MD + ); } public function testCanParseMarkdownFile() { $post = MarkdownPost::parse('test-post'); + $this->assertInstanceOf(MarkdownPost::class, $post); $this->assertCount(3, $post->matter->toArray()); $this->assertInstanceOf(FrontMatter::class, $post->matter); @@ -55,8 +51,10 @@ public function testCanParseMarkdownFile() public function testParsedMarkdownPostContainsValidFrontMatter() { $post = MarkdownPost::parse('test-post'); - $this->assertEquals('My New Post', $post->data('title')); + + $this->assertSame('My New Post', $post->data('title')); + $this->assertSame('blog', $post->data('category')); $this->assertEquals('Mr. Hyde', $post->data('author')); - $this->assertEquals('blog', $post->data('category')); + $this->assertInstanceOf(PostAuthor::class, $post->data('author')); } } diff --git a/packages/framework/tests/Unit/PostAuthorTest.php b/packages/framework/tests/Unit/PostAuthorTest.php index 503c59f57d5..4544ff6ce57 100644 --- a/packages/framework/tests/Unit/PostAuthorTest.php +++ b/packages/framework/tests/Unit/PostAuthorTest.php @@ -29,9 +29,9 @@ public function testCreateMethodAcceptsAllParameters() { $author = Author::create('foo', 'bar', 'https://example.com'); - $this->assertEquals('foo', $author->username); - $this->assertEquals('bar', $author->name); - $this->assertEquals('https://example.com', $author->website); + $this->assertSame('foo', $author->username); + $this->assertSame('bar', $author->name); + $this->assertSame('https://example.com', $author->website); } public function testGetOrCreateMethodCreatesNewAuthorModelFromString() @@ -107,8 +107,8 @@ public function testGetMethodReturnsConfigDefinedAuthorByUsername() $author = PostAuthor::get('foo'); $this->assertInstanceOf(PostAuthor::class, $author); - $this->assertEquals('foo', $author->username); - $this->assertEquals('bar', $author->name); + $this->assertSame('foo', $author->username); + $this->assertSame('bar', $author->name); } public function testGetMethodReturnsNewAuthorIfUsernameNotFoundInConfig() @@ -117,34 +117,34 @@ public function testGetMethodReturnsNewAuthorIfUsernameNotFoundInConfig() $author = PostAuthor::get('foo'); $this->assertInstanceOf(PostAuthor::class, $author); - $this->assertEquals('foo', $author->username); + $this->assertSame('foo', $author->username); } public function testGetNameHelperReturnsNameIfSet() { $author = new PostAuthor('username', 'John Doe'); - $this->assertEquals('John Doe', $author->getName()); + $this->assertSame('John Doe', $author->getName()); } public function testGetNameHelperReturnsUsernameIfNameIsNotSet() { $author = new PostAuthor('username'); - $this->assertEquals('username', $author->getName()); + $this->assertSame('username', $author->getName()); } public function testNameIsSetToUsernameIfNameIsNotSet() { $author = new PostAuthor('username'); - $this->assertEquals('username', $author->name); + $this->assertSame('username', $author->name); } public function testToStringHelperReturnsTheName() { $author = new PostAuthor('username', 'John Doe'); - $this->assertEquals('John Doe', (string) $author); + $this->assertSame('John Doe', (string) $author); } } diff --git a/packages/framework/tests/Unit/Views/LinkComponentTest.php b/packages/framework/tests/Unit/Views/LinkComponentTest.php index edcb4c150fc..30b2b016dee 100644 --- a/packages/framework/tests/Unit/Views/LinkComponentTest.php +++ b/packages/framework/tests/Unit/Views/LinkComponentTest.php @@ -16,21 +16,30 @@ class LinkComponentTest extends TestCase { public function testLinkComponentCanBeRendered() { - $this->assertEquals('bar', rtrim(Blade::render('foo