Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/App/src/Factory/GetIndexViewHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Psr\Container\NotFoundExceptionInterface;

use function assert;
use function getcwd;

class GetIndexViewHandlerFactory
{
Expand All @@ -27,6 +26,8 @@ public function __invoke(ContainerInterface $container, string $requestedName):
$template = $container->get(TemplateRendererInterface::class);
assert($template instanceof TemplateRendererInterface);

return new GetIndexViewHandler($template, $postRepository, getcwd() . '/public/md-pages');
$config = $container->get('config');

return new GetIndexViewHandler($template, $postRepository, $config['llms']['pagesDir']);
}
}
5 changes: 3 additions & 2 deletions src/App/src/Factory/GetMarkdownArticleHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Psr\Container\NotFoundExceptionInterface;

use function assert;
use function getcwd;

class GetMarkdownArticleHandlerFactory
{
Expand All @@ -28,6 +27,8 @@ public function __invoke(ContainerInterface $container, string $requestedName):
$categoryRepository = $container->get(CategoryRepository::class);
assert($categoryRepository instanceof CategoryRepository);

return new GetMarkdownArticleHandler($template, $categoryRepository, getcwd() . '/public/md-articles');
$config = $container->get('config');

return new GetMarkdownArticleHandler($template, $categoryRepository, $config['llms']['sourceDir']);
}
}
5 changes: 3 additions & 2 deletions src/Blog/src/Factory/BlogServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Psr\Container\NotFoundExceptionInterface;

use function assert;
use function getcwd;

class BlogServiceFactory
{
Expand All @@ -25,6 +24,8 @@ public function __invoke(ContainerInterface $container, string $requestedName):
$template = $container->get(TemplateRendererInterface::class);
assert($template instanceof TemplateRendererInterface);

return new BlogService($template, getcwd() . '/public/md-articles');
$config = $container->get('config');

return new BlogService($template, $config['llms']['sourceDir']);
}
}
6 changes: 3 additions & 3 deletions src/Page/src/Factory/PageServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
use Light\Page\Service\PageServiceInterface;
use Psr\Container\ContainerInterface;

use function getcwd;

class PageServiceFactory
{
/**
* @param class-string $requestedName
*/
public function __invoke(ContainerInterface $container, string $requestedName): PageServiceInterface
{
return new PageService(getcwd() . '/public/md-pages');
$config = $container->get('config');

return new PageService($config['llms']['pagesDir']);
}
}
12 changes: 8 additions & 4 deletions test/Unit/Blog/Factory/BlogServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use Psr\Container\ContainerInterface;
use ReflectionProperty;

use function getcwd;

class BlogServiceFactoryTest extends UnitTest
{
/**
Expand All @@ -23,14 +21,20 @@ public function testInvokeInjectsTheRendererAndTheArticlesPath(): void
{
$template = $this->createStub(TemplateRendererInterface::class);
$container = $this->createStub(ContainerInterface::class);
$container->method('get')->willReturn($template);
$container
->method('get')
->willReturnCallback(fn (string $id): mixed => match ($id) {
TemplateRendererInterface::class => $template,
'config' => ['llms' => ['sourceDir' => '/some/path/md-articles']],
default => null,
});

$service = (new BlogServiceFactory())($container, BlogService::class);

$this->assertInstanceOf(BlogService::class, $service);
$this->assertSame($template, (new ReflectionProperty(BlogService::class, 'template'))->getValue($service));
$this->assertSame(
getcwd() . '/public/md-articles',
'/some/path/md-articles',
(new ReflectionProperty(BlogService::class, 'articlesPath'))->getValue($service)
);
}
Expand Down
21 changes: 16 additions & 5 deletions test/Unit/Page/Factory/PageServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Psr\Container\ContainerInterface;
use ReflectionProperty;

use function getcwd;

class PageServiceFactoryTest extends UnitTest
{
/**
Expand All @@ -21,14 +19,14 @@ class PageServiceFactoryTest extends UnitTest
public function testInvokeReturnsThePageService(): void
{
$service = (new PageServiceFactory())(
$this->createStub(ContainerInterface::class),
$this->createContainer('/some/path/md-pages'),
PageService::class
);

// The declared return type is the interface; what matters is which implementation it builds.
$this->assertInstanceOf(PageService::class, $service);
$this->assertSame(
getcwd() . '/public/md-pages',
'/some/path/md-pages',
(new ReflectionProperty(PageService::class, 'mdPagesPath'))->getValue($service)
);
}
Expand All @@ -39,11 +37,24 @@ public function testInvokeReturnsThePageService(): void
public function testInvokeBuildsAFreshServiceEachTime(): void
{
$factory = new PageServiceFactory();
$container = $this->createStub(ContainerInterface::class);
$container = $this->createContainer('/some/path/md-pages');

$this->assertNotSame(
$factory($container, PageService::class),
$factory($container, PageService::class)
);
}

/**
* @throws Exception
*/
private function createContainer(string $pagesDir): ContainerInterface
{
$container = $this->createStub(ContainerInterface::class);
$container->method('get')->willReturn([
'llms' => ['pagesDir' => $pagesDir],
]);

return $container;
}
}