Skip to content

Commit

Permalink
Merge pull request #1796 from hydephp/improve-static-analysis
Browse files Browse the repository at this point in the history
Internal: Improve test static analysis and improve tests hydephp/develop@254bbe7
  • Loading branch information
github-actions committed Jul 7, 2024
1 parent 1af0bd8 commit ebb6022
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 90 deletions.
15 changes: 8 additions & 7 deletions tests/Feature/Services/Markdown/ShortcodeProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ public function testDiscoveredShortcodesAreUsedToProcessInput()
{
$processor = new ShortcodeProcessor('>info foo');

$this->assertEquals('<blockquote class="info"><p>foo</p></blockquote>',
$processor->run());
$this->assertSame('<blockquote class="info"><p>foo</p></blockquote>', $processor->run());
}

public function testStringWithoutShortcodeIsNotModified()
{
$processor = new ShortcodeProcessor('foo');

$this->assertEquals('foo', $processor->run());
$this->assertSame('foo', $processor->run());
}

public function testProcessStaticShorthand()
{
$this->assertEquals('<blockquote class="info"><p>foo</p></blockquote>',
ShortcodeProcessor::preprocess('>info foo'));
$this->assertSame(
'<blockquote class="info"><p>foo</p></blockquote>',
ShortcodeProcessor::preprocess('>info foo')
);
}

public function testShortcodesCanBeAddedToProcessor()
Expand All @@ -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()
Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Feature/Services/RssFeedServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Support/ProjectFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
58 changes: 29 additions & 29 deletions tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
28 changes: 14 additions & 14 deletions tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Pages/HtmlPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testHtmlPageCanBeCompiled()

$page = new HtmlPage('foo');

$this->assertEquals('bar', $page->compile());
$this->assertSame('bar', $page->compile());
}

public function testCompileMethodUsesContents()
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Pages/MarkdownPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit ebb6022

Please sign in to comment.