EntityTemplateLoader example



    public function testSubscribedEvents(): void
    {
        $subscribedEvents = EntityTemplateLoader::getSubscribedEvents();

        static::assertEquals(['app_template.written' => 'reset']$subscribedEvents);
    }

    public function testDevMode(): void
    {
        $entityTemplateLoader = new EntityTemplateLoader($this->connectionMock, 'dev');

        $this->connectionMock->expects(static::never())->method('fetchAllAssociative');

        $result = $entityTemplateLoader->exists('@test/test');

        static::assertFalse($result);

        $result = $entityTemplateLoader->isFresh('@test/test', \time());

        static::assertFalse($result);

        
$this->templateLoader->exists('@StorefrontTheme/storefront/base.html.twig')
        );
    }

    public function testTemplateLoadingIsCachedWithoutDatabaseTemplates(): void
    {
        $connection = $this->createMock(Connection::class);
        $connection->expects(static::once())
            ->method('fetchAllAssociative')
            ->willReturn([]);

        $templateLoader = new EntityTemplateLoader($connection, 'prod');

        static::assertFalse($templateLoader->exists('@Storefront/storefront/base.html.twig'));
        static::assertFalse($templateLoader->exists('@Storefront/storefront/test.html.twig'));
    }

    private function importTemplates(): void
    {
        $this->templateRepository->upsert([
            [
                'id' => $this->template1Id,
                'path' => 'storefront/base.html.twig',
                
Home | Imprint | This part of the site doesn't use cookies.