Files
archived-doctrine-website/tests/DataSources/BlogPostsTest.php
Christophe Coevoet 495b4ac8f4 Inline the static website generator in the website repo
Maintaining a standalone static website generator project that is not
reused outside our website adds maintenance overhead. For instance,
support for using `phpdocumentor/guides` was implemented in the website
repo rather than the standalone generator package, which was still using
the `doctrine/rst-parser` package that we want to abandon.
2025-10-09 21:46:37 +02:00

65 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Doctrine\Website\Tests\DataSources;
use DateTimeImmutable;
use Doctrine\Website\DataSources\BlogPosts;
use Doctrine\Website\StaticGenerator\SourceFile\SourceFile;
use Doctrine\Website\StaticGenerator\SourceFile\SourceFileFilesystemReader;
use Doctrine\Website\StaticGenerator\SourceFile\SourceFileParameters;
use Doctrine\Website\StaticGenerator\SourceFile\SourceFiles;
use Doctrine\Website\Tests\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class BlogPostsTest extends TestCase
{
private SourceFileFilesystemReader&MockObject $sourceFileFilesystemReader;
private BlogPosts $blogPosts;
public function testGetSourceRows(): void
{
$parameters = new SourceFileParameters([
'url' => 'blog/2161/01/01/new-doctrine.rst',
'slug' => 'new-doctrine.rst',
'title' => 'New Doctrine',
'authorName' => 'John Doe',
'authorEmail' => 'john.doe@doctrine-website.org',
]);
$sourceFile = new SourceFile(__DIR__ . '/blog/', 'Content, the final frontier', $parameters);
$sourceFiles = new SourceFiles([$sourceFile]);
$this->sourceFileFilesystemReader->expects(self::once())
->method('getSourceFiles')
->with('')
->willReturn($sourceFiles);
$blogPostRows = $this->blogPosts->getSourceRows();
$expected = [
[
'url' => 'blog/2161/01/01/new-doctrine.rst',
'slug' => 'new-doctrine.rst',
'title' => 'New Doctrine',
'authorName' => 'John Doe',
'authorEmail' => 'john.doe@doctrine-website.org',
'contents' => 'Content, the final frontier',
'date' => new DateTimeImmutable('2161-01-01'),
],
];
self::assertEquals($expected, $blogPostRows);
}
protected function setUp(): void
{
$this->sourceFileFilesystemReader = $this->createMock(SourceFileFilesystemReader::class);
$this->blogPosts = new BlogPosts(
$this->sourceFileFilesystemReader,
);
}
}