- 21 test files covering controllers, services, entities, enums, messages - CI: add test job with Xdebug coverage (clover + text) - SonarQube: configure coverage report path and test sources Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
91 lines
2.7 KiB
PHP
91 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Twig;
|
|
|
|
use App\Twig\ViteAssetExtension;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Cache\CacheItemInterface;
|
|
use Psr\Cache\CacheItemPoolInterface;
|
|
|
|
class ViteAssetExtensionTest extends TestCase
|
|
{
|
|
private CacheItemPoolInterface $cache;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->cache = $this->createMock(CacheItemPoolInterface::class);
|
|
$_ENV['VITE_LOAD'] = '1';
|
|
}
|
|
|
|
private function createExtension(string $manifestPath = '/tmp/nonexistent'): ViteAssetExtension
|
|
{
|
|
return new ViteAssetExtension($manifestPath, $this->cache);
|
|
}
|
|
|
|
public function testGetFunctionsReturnsExpectedNames(): void
|
|
{
|
|
$extension = $this->createExtension();
|
|
$functions = $extension->getFunctions();
|
|
|
|
$names = array_map(fn ($f) => $f->getName(), $functions);
|
|
|
|
self::assertContains('vite_asset', $names);
|
|
self::assertContains('isMobile', $names);
|
|
self::assertContains('vite_favicons', $names);
|
|
}
|
|
|
|
public function testAssetDevReturnsScriptTags(): void
|
|
{
|
|
$_ENV['VITE_LOAD'] = '0';
|
|
$extension = $this->createExtension();
|
|
|
|
$html = $extension->asset('app.js', []);
|
|
|
|
self::assertStringContainsString('localhost:5173', $html);
|
|
self::assertStringContainsString('app.js', $html);
|
|
}
|
|
|
|
public function testAssetProdUsesManifest(): void
|
|
{
|
|
$manifest = [
|
|
'app.js' => [
|
|
'file' => 'assets/app.abc123.js',
|
|
'css' => ['assets/app.def456.css'],
|
|
],
|
|
];
|
|
|
|
$item = $this->createMock(CacheItemInterface::class);
|
|
$item->method('isHit')->willReturn(true);
|
|
$item->method('get')->willReturn($manifest);
|
|
$this->cache->method('getItem')->willReturn($item);
|
|
|
|
$extension = $this->createExtension();
|
|
$html = $extension->assetProd('app.js');
|
|
|
|
self::assertStringContainsString('assets/app.abc123.js', $html);
|
|
self::assertStringContainsString('assets/app.def456.css', $html);
|
|
}
|
|
|
|
public function testAssetProdHandlesMissingManifest(): void
|
|
{
|
|
$item = $this->createMock(CacheItemInterface::class);
|
|
$item->method('isHit')->willReturn(false);
|
|
$this->cache->method('getItem')->willReturn($item);
|
|
|
|
$extension = $this->createExtension('/tmp/nonexistent_manifest.json');
|
|
$html = $extension->assetProd('missing.js');
|
|
|
|
self::assertStringContainsString('script', $html);
|
|
}
|
|
|
|
public function testFaviconsDevReturnsFaviconLink(): void
|
|
{
|
|
$_ENV['VITE_LOAD'] = '0';
|
|
$extension = $this->createExtension();
|
|
|
|
$html = $extension->favicons();
|
|
|
|
self::assertStringContainsString('favicon.ico', $html);
|
|
}
|
|
}
|