. */ declare(strict_types=1); namespace SP\Tests\Mvc\View; use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use SP\Domain\Core\Exceptions\FileNotFoundException; use SP\Domain\Core\UI\ThemeInterface; use SP\Mvc\View\TemplateResolver; /** * Class TemplateResolverTest */ #[Group('unitary')] class TemplateResolverTest extends TestCase { private ThemeInterface|MockObject $theme; private TemplateResolver $templateResolver; /** * @throws FileNotFoundException */ public function testGetTemplateFor() { $vfsStreamDirectory = vfsStream::setup( 'template_dir', 755, ['base_dir' => ['test_template.inc' => 'a_content']] ); $this->theme ->expects($this->once()) ->method('getViewsPath') ->willReturn($vfsStreamDirectory->url()); $out = $this->templateResolver->getTemplateFor('base_dir', 'test_template'); $this->assertEquals($vfsStreamDirectory->url() . '/base_dir/test_template.inc', $out); } /** * @throws Exception */ protected function setUp(): void { parent::setUp(); $this->theme = $this->createMock(ThemeInterface::class); $this->templateResolver = new TemplateResolver($this->theme); } /** * @throws FileNotFoundException */ public function testGetTemplateForWithNoPermissions() { $vfsStreamDirectory = vfsStream::setup( 'root_dir', 755, ['base_dir' => []] ); $this->theme ->expects($this->once()) ->method('getViewsPath') ->willReturn($vfsStreamDirectory->url()); $this->expectException(FileNotFoundException::class); $this->templateResolver->getTemplateFor('base_dir', 'test_template'); } }